sync genevent and LTTV parsers
[lttv.git] / genevent / parser.h
1 #ifndef PARSER_H
2 #define PARSER_H
3
4 /* Extensible array container */
5
6 typedef struct _sequence {
7 int size;
8 int position;
9 void **array;
10 } sequence_t;
11
12 void sequence_init(sequence_t *t);
13 void sequence_dispose(sequence_t *t);
14 void sequence_push(sequence_t *t, void *elem);
15 void *sequence_pop(sequence_t *t);
16
17
18 /* Hash table */
19
20 typedef struct _table {
21 sequence_t keys;
22 sequence_t values;
23 } table_t;
24
25 void table_init(table_t *t);
26 void table_dispose(table_t *t);
27 void table_insert(table_t *t, char *key, void *value);
28 void *table_find(table_t *t, char *key);
29 void table_insert_int(table_t *t, int *key, void *value);
30 void *table_find_int(table_t *t, int *key);
31
32
33 /* Token types */
34
35 typedef enum _token_type {
36 ENDFILE,
37 FORWARDSLASH,
38 LANGLEBRACKET,
39 RANGLEBRACKET,
40 EQUAL,
41 QUOTEDSTRING,
42 NUMBER,
43 NAME
44 } token_type_t;
45
46
47 /* State associated with a file being parsed */
48 typedef struct _parse_file {
49 char *name;
50 FILE * fp;
51 int lineno;
52 char *buffer;
53 token_type_t type;
54 int unget;
55 void (*error) (struct _parse_file *, char *);
56 } parse_file_t;
57
58 void ungetToken(parse_file_t * in);
59 char *getToken(parse_file_t *in);
60 char *getForwardslash(parse_file_t *in);
61 char *getLAnglebracket(parse_file_t *in);
62 char *getRAnglebracket(parse_file_t *in);
63 char *getQuotedString(parse_file_t *in);
64 char *getName(parse_file_t *in);
65 int getNumber(parse_file_t *in);
66 char *getEqual(parse_file_t *in);
67 char seekNextChar(parse_file_t *in);
68
69 void skipComment(parse_file_t * in);
70 void skipEOL(parse_file_t * in);
71
72 /* Some constants */
73
74 static const int BUFFER_SIZE = 1024;
75
76
77 /* Events data types */
78
79 typedef enum _data_type {
80 INT,
81 UINT,
82 POINTER,
83 LONG,
84 ULONG,
85 SIZE_T,
86 SSIZE_T,
87 OFF_T,
88 FLOAT,
89 STRING,
90 ENUM,
91 ARRAY,
92 SEQUENCE,
93 STRUCT,
94 UNION,
95 NONE
96 } data_type_t;
97
98 /* Event type descriptors */
99
100 typedef struct _type_descriptor {
101 char * type_name; //used for named type
102 data_type_t type;
103 char *fmt;
104 int size;
105 sequence_t labels; // for enumeration
106 sequence_t labels_description;
107 int already_printed;
108 sequence_t fields; // for structure
109 struct _type_descriptor *nested_type; // for array and sequence
110 int alignment;
111 } type_descriptor_t;
112
113
114 /* Fields within types */
115
116 typedef struct _field{
117 char *name;
118 char *description;
119 type_descriptor_t *type;
120 } field_t;
121
122
123 /* Events definitions */
124
125 typedef struct _event {
126 char *name;
127 char *description;
128 type_descriptor_t *type;
129 int per_trace; /* Is the event able to be logged to a specific trace ? */
130 int per_tracefile; /* Must we log this event in a specific tracefile ? */
131 } event_t;
132
133 typedef struct _facility {
134 char * name;
135 char * capname;
136 char * description;
137 sequence_t events;
138 sequence_t unnamed_types;
139 table_t named_types;
140 } facility_t;
141
142 int getSize(parse_file_t *in);
143 unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
144
145 void parseFacility(parse_file_t *in, facility_t * fac);
146 void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
147 table_t * named_types);
148 void parseTypeDefinition(parse_file_t *in,
149 sequence_t * unnamed_types, table_t * named_types);
150 type_descriptor_t *parseType(parse_file_t *in,
151 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
152 void parseFields(parse_file_t *in, type_descriptor_t *t,
153 sequence_t * unnamed_types, table_t * named_types);
154 void checkNamedTypesImplemented(table_t * namedTypes);
155 type_descriptor_t * find_named_type(char *name, table_t * named_types);
156 void generateChecksum(char * facName,
157 unsigned long * checksum, sequence_t * events);
158
159
160 /* get attributes */
161 char * getNameAttribute(parse_file_t *in);
162 char * getFormatAttribute(parse_file_t *in);
163 int getSizeAttribute(parse_file_t *in);
164 int getValueAttribute(parse_file_t *in);
165 char * getValueStrAttribute(parse_file_t *in);
166
167 char * getDescription(parse_file_t *in);
168
169
170 static char *intOutputTypes[] = {
171 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
172
173 static char *uintOutputTypes[] = {
174 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
175 "unsigned int", "unsigned long int" };
176
177 static char *floatOutputTypes[] = {
178 "undef", "undef", "float", "double", "undef", "float", "double" };
179
180
181 /* Dynamic memory allocation and freeing */
182
183 void * memAlloc(int size);
184 char *allocAndCopy(char * str);
185 char *appendString(char *s, char *suffix);
186 void freeTypes(sequence_t *t);
187 void freeType(type_descriptor_t * td);
188 void freeEvents(sequence_t *t);
189 void freeNamedType(table_t * t);
190 void error_callback(parse_file_t *in, char *msg);
191
192
193 //checksum part
194 static const unsigned int crctab32[] =
195 {
196 #include "crc32.tab"
197 };
198
199 static inline unsigned long
200 partial_crc32_one(unsigned char c, unsigned long crc)
201 {
202 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
203 }
204
205 static inline unsigned long
206 partial_crc32(const char *s, unsigned long crc)
207 {
208 while (*s)
209 crc = partial_crc32_one(*s++, crc);
210 return crc;
211 }
212
213 static inline unsigned long
214 crc32(const char *s)
215 {
216 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
217 }
218
219
220 #endif // PARSER_H
This page took 0.034294 seconds and 5 git commands to generate.