Make sure libtraceread is completely licensed LGPL
[lttv.git] / ltt / branches / poly / ltt / parser.h
CommitLineData
1b44b0b5 1/*
2 * parser.h: Generate helper declarations and functions to trace events
3 * from an event description file.
4 *
5 * Copyright (C) 2005, Mathieu Desnoyers
6 * Copyright (C) 2002, Xianxiu Yang
7 * Copyright (C) 2002, Michel Dagenais
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License Version 2.1 as published by the Free Software Foundation.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
90395b4b 24#ifndef PARSER_H
25#define PARSER_H
26
27/* Extensible array container */
28
29typedef struct _sequence {
30 int size;
31 int position;
32 void **array;
90699b2b 33} sequence_t;
90395b4b 34
90699b2b 35void sequence_init(sequence_t *t);
36void sequence_dispose(sequence_t *t);
37void sequence_push(sequence_t *t, void *elem);
38void *sequence_pop(sequence_t *t);
90395b4b 39
40
41/* Hash table */
42
43typedef struct _table {
90699b2b 44 sequence_t keys;
45 sequence_t values;
46} table_t;
90395b4b 47
90699b2b 48void table_init(table_t *t);
49void table_dispose(table_t *t);
50void table_insert(table_t *t, char *key, void *value);
51void *table_find(table_t *t, char *key);
52void table_insert_int(table_t *t, int *key, void *value);
53void *table_find_int(table_t *t, int *key);
90395b4b 54
55
56/* Token types */
57
58typedef enum _token_type {
59 ENDFILE,
60 FORWARDSLASH,
61 LANGLEBRACKET,
62 RANGLEBRACKET,
63 EQUAL,
64 QUOTEDSTRING,
65 NUMBER,
66 NAME
90699b2b 67} token_type_t;
90395b4b 68
69
70/* State associated with a file being parsed */
71typedef struct _parse_file {
72 char *name;
73 FILE * fp;
74 int lineno;
75 char *buffer;
90699b2b 76 token_type_t type;
90395b4b 77 int unget;
78 void (*error) (struct _parse_file *, char *);
90699b2b 79} parse_file_t;
80
81void ungetToken(parse_file_t * in);
82char *getToken(parse_file_t *in);
83char *getForwardslash(parse_file_t *in);
84char *getLAnglebracket(parse_file_t *in);
85char *getRAnglebracket(parse_file_t *in);
86char *getQuotedString(parse_file_t *in);
87char *getName(parse_file_t *in);
88int getNumber(parse_file_t *in);
89char *getEqual(parse_file_t *in);
90char seekNextChar(parse_file_t *in);
91
92void skipComment(parse_file_t * in);
93void skipEOL(parse_file_t * in);
90395b4b 94
95/* Some constants */
96
97static const int BUFFER_SIZE = 1024;
98
99
100/* Events data types */
101
102typedef enum _data_type {
f104d082 103 INT_FIXED,
104 UINT_FIXED,
105 POINTER,
106 CHAR,
107 UCHAR,
108 SHORT,
109 USHORT,
90395b4b 110 INT,
111 UINT,
90395b4b 112 LONG,
113 ULONG,
114 SIZE_T,
115 SSIZE_T,
116 OFF_T,
117 FLOAT,
118 STRING,
119 ENUM,
120 ARRAY,
121 SEQUENCE,
122 STRUCT,
123 UNION,
124 NONE
90699b2b 125} data_type_t;
90395b4b 126
90395b4b 127typedef struct _type_descriptor {
128 char * type_name; //used for named type
90699b2b 129 data_type_t type;
90395b4b 130 char *fmt;
f104d082 131 size_t size;
90699b2b 132 sequence_t labels; // for enumeration
f104d082 133 sequence_t labels_values; // for enumeration
90699b2b 134 sequence_t labels_description;
90395b4b 135 int already_printed;
f104d082 136 sequence_t fields; // for structure, array and sequence (field_t type)
7df766d3 137 int custom_write; /* Should we use a custom write function ? */
90699b2b 138} type_descriptor_t;
90395b4b 139
140
90395b4b 141
f104d082 142/* Fields within types or events */
90395b4b 143typedef struct _field{
144 char *name;
145 char *description;
90699b2b 146 type_descriptor_t *type;
147} field_t;
90395b4b 148
149
150/* Events definitions */
151
152typedef struct _event {
153 char *name;
154 char *description;
f104d082 155 //type_descriptor_t *type;
156 sequence_t fields; /* event fields */
90395b4b 157 int per_trace; /* Is the event able to be logged to a specific trace ? */
158 int per_tracefile; /* Must we log this event in a specific tracefile ? */
90699b2b 159} event_t;
90395b4b 160
161typedef struct _facility {
162 char * name;
163 char * capname;
f5d7967f 164 char * arch;
90395b4b 165 char * description;
90699b2b 166 sequence_t events;
f104d082 167 sequence_t unnamed_types; //FIXME : remove
90699b2b 168 table_t named_types;
f104d082 169 unsigned int checksum;
90699b2b 170} facility_t;
171
f104d082 172int getSizeindex(unsigned int value);
173unsigned long long int getSize(parse_file_t *in);
90699b2b 174unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
175
176void parseFacility(parse_file_t *in, facility_t * fac);
177void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
178 table_t * named_types);
179void parseTypeDefinition(parse_file_t *in,
180 sequence_t * unnamed_types, table_t * named_types);
181type_descriptor_t *parseType(parse_file_t *in,
182 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
f104d082 183void parseFields(parse_file_t *in, field_t *f,
184 sequence_t * unnamed_types,
185 table_t * named_types,
186 int tag);
90699b2b 187void checkNamedTypesImplemented(table_t * namedTypes);
188type_descriptor_t * find_named_type(char *name, table_t * named_types);
189void generateChecksum(char * facName,
f104d082 190 unsigned int * checksum, sequence_t * events);
90395b4b 191
192
193/* get attributes */
90699b2b 194char * getNameAttribute(parse_file_t *in);
195char * getFormatAttribute(parse_file_t *in);
196int getSizeAttribute(parse_file_t *in);
197int getValueAttribute(parse_file_t *in);
198char * getValueStrAttribute(parse_file_t *in);
90395b4b 199
90699b2b 200char * getDescription(parse_file_t *in);
90395b4b 201
202
90395b4b 203/* Dynamic memory allocation and freeing */
204
205void * memAlloc(int size);
206char *allocAndCopy(char * str);
207char *appendString(char *s, char *suffix);
90699b2b 208void freeTypes(sequence_t *t);
209void freeType(type_descriptor_t * td);
210void freeEvents(sequence_t *t);
211void freeNamedType(table_t * t);
212void error_callback(parse_file_t *in, char *msg);
90395b4b 213
214
215//checksum part
216static const unsigned int crctab32[] =
217{
218#include "crc32.tab"
219};
220
221static inline unsigned long
222partial_crc32_one(unsigned char c, unsigned long crc)
223{
224 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
225}
226
227static inline unsigned long
228partial_crc32(const char *s, unsigned long crc)
229{
230 while (*s)
231 crc = partial_crc32_one(*s++, crc);
232 return crc;
233}
234
235static inline unsigned long
236crc32(const char *s)
237{
238 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
239}
240
241
f104d082 242extern char *intOutputTypes[];
243
244extern char *uintOutputTypes[];
245
246extern char *floatOutputTypes[];
247
248
249
250
90395b4b 251#endif // PARSER_H
This page took 0.035697 seconds and 4 git commands to generate.