90395b4b |
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; |
90699b2b |
10 | } sequence_t; |
90395b4b |
11 | |
90699b2b |
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); |
90395b4b |
16 | |
17 | |
18 | /* Hash table */ |
19 | |
20 | typedef struct _table { |
90699b2b |
21 | sequence_t keys; |
22 | sequence_t values; |
23 | } table_t; |
90395b4b |
24 | |
90699b2b |
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); |
90395b4b |
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 |
90699b2b |
44 | } token_type_t; |
90395b4b |
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; |
90699b2b |
53 | token_type_t type; |
90395b4b |
54 | int unget; |
55 | void (*error) (struct _parse_file *, char *); |
90699b2b |
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); |
83e160f2 |
67 | int seekNextChar(parse_file_t *in); |
90699b2b |
68 | |
69 | void skipComment(parse_file_t * in); |
70 | void skipEOL(parse_file_t * in); |
90395b4b |
71 | |
72 | /* Some constants */ |
73 | |
74 | static const int BUFFER_SIZE = 1024; |
75 | |
76 | |
77 | /* Events data types */ |
78 | |
79 | typedef enum _data_type { |
f104d082 |
80 | INT_FIXED, |
81 | UINT_FIXED, |
82 | POINTER, |
83 | CHAR, |
84 | UCHAR, |
85 | SHORT, |
86 | USHORT, |
90395b4b |
87 | INT, |
88 | UINT, |
90395b4b |
89 | LONG, |
90 | ULONG, |
91 | SIZE_T, |
92 | SSIZE_T, |
93 | OFF_T, |
94 | FLOAT, |
95 | STRING, |
96 | ENUM, |
97 | ARRAY, |
98 | SEQUENCE, |
99 | STRUCT, |
100 | UNION, |
101 | NONE |
90699b2b |
102 | } data_type_t; |
90395b4b |
103 | |
dd3a6d39 |
104 | typedef struct _facility facility_t; |
105 | typedef struct _event event_t; |
106 | |
90395b4b |
107 | typedef struct _type_descriptor { |
dd3a6d39 |
108 | facility_t *fac; |
90395b4b |
109 | char * type_name; //used for named type |
90699b2b |
110 | data_type_t type; |
90395b4b |
111 | char *fmt; |
f104d082 |
112 | size_t size; |
90699b2b |
113 | sequence_t labels; // for enumeration |
f104d082 |
114 | sequence_t labels_values; // for enumeration |
90699b2b |
115 | sequence_t labels_description; |
90395b4b |
116 | int already_printed; |
f104d082 |
117 | sequence_t fields; // for structure, array and sequence (field_t type) |
f0b795e0 |
118 | int custom_write; /* Should we use a custom write function ? */ |
119 | int network; /* Is the type a in network byte order ? */ |
90699b2b |
120 | } type_descriptor_t; |
90395b4b |
121 | |
122 | |
f104d082 |
123 | /* Fields within types or events */ |
90395b4b |
124 | typedef struct _field{ |
dd3a6d39 |
125 | facility_t *fac; |
90395b4b |
126 | char *name; |
127 | char *description; |
90699b2b |
128 | type_descriptor_t *type; |
129 | } field_t; |
90395b4b |
130 | |
131 | |
132 | /* Events definitions */ |
133 | |
dd3a6d39 |
134 | struct _event { |
135 | facility_t *fac; |
90395b4b |
136 | char *name; |
137 | char *description; |
f104d082 |
138 | //type_descriptor_t *type; |
dd3a6d39 |
139 | sequence_t fields; /* event fields */ |
90395b4b |
140 | int per_trace; /* Is the event able to be logged to a specific trace ? */ |
141 | int per_tracefile; /* Must we log this event in a specific tracefile ? */ |
dd3a6d39 |
142 | int param_buffer; /* For userspace tracing : takes a buffer as parameter? */ |
143 | int no_instrument_function; |
144 | int high_priority; |
145 | int force; |
146 | int compact_data; |
147 | }; |
148 | |
149 | struct _facility { |
90395b4b |
150 | char * name; |
dd3a6d39 |
151 | char * capname; |
152 | char * arch; |
153 | int align; /* Alignment : default 1, 0 no alignment. */ |
90395b4b |
154 | char * description; |
90699b2b |
155 | sequence_t events; |
f104d082 |
156 | sequence_t unnamed_types; //FIXME : remove |
90699b2b |
157 | table_t named_types; |
dd3a6d39 |
158 | unsigned int checksum; |
159 | int user; /* Is this a userspace facility ? */ |
160 | }; |
90699b2b |
161 | |
f104d082 |
162 | int getSizeindex(unsigned int value); |
163 | unsigned long long int getSize(parse_file_t *in); |
90699b2b |
164 | unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type); |
165 | |
166 | void parseFacility(parse_file_t *in, facility_t * fac); |
dd3a6d39 |
167 | void parseEvent(facility_t *fac, parse_file_t *in, event_t *ev, sequence_t * unnamed_types, |
90699b2b |
168 | table_t * named_types); |
dd3a6d39 |
169 | void parseTypeDefinition(facility_t *fac, parse_file_t *in, |
90699b2b |
170 | sequence_t * unnamed_types, table_t * named_types); |
dd3a6d39 |
171 | type_descriptor_t *parseType(facility_t *fac, parse_file_t *in, |
90699b2b |
172 | type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types); |
dd3a6d39 |
173 | void parseFields(facility_t *fac, parse_file_t *in, field_t *f, |
f104d082 |
174 | sequence_t * unnamed_types, |
175 | table_t * named_types, |
176 | int tag); |
90699b2b |
177 | void checkNamedTypesImplemented(table_t * namedTypes); |
178 | type_descriptor_t * find_named_type(char *name, table_t * named_types); |
179 | void generateChecksum(char * facName, |
f104d082 |
180 | unsigned int * checksum, sequence_t * events); |
90395b4b |
181 | |
182 | |
183 | /* get attributes */ |
90699b2b |
184 | char * getNameAttribute(parse_file_t *in); |
185 | char * getFormatAttribute(parse_file_t *in); |
186 | int getSizeAttribute(parse_file_t *in); |
9f2d599d |
187 | int getValueAttribute(parse_file_t *in, long long *value); |
90395b4b |
188 | |
90699b2b |
189 | char * getDescription(parse_file_t *in); |
90395b4b |
190 | |
191 | |
90395b4b |
192 | /* Dynamic memory allocation and freeing */ |
193 | |
194 | void * memAlloc(int size); |
195 | char *allocAndCopy(char * str); |
196 | char *appendString(char *s, char *suffix); |
90699b2b |
197 | void freeTypes(sequence_t *t); |
198 | void freeType(type_descriptor_t * td); |
199 | void freeEvents(sequence_t *t); |
200 | void freeNamedType(table_t * t); |
201 | void error_callback(parse_file_t *in, char *msg); |
90395b4b |
202 | |
203 | |
204 | //checksum part |
205 | static const unsigned int crctab32[] = |
206 | { |
207 | #include "crc32.tab" |
208 | }; |
209 | |
210 | static inline unsigned long |
211 | partial_crc32_one(unsigned char c, unsigned long crc) |
212 | { |
213 | return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); |
214 | } |
215 | |
216 | static inline unsigned long |
217 | partial_crc32(const char *s, unsigned long crc) |
218 | { |
219 | while (*s) |
220 | crc = partial_crc32_one(*s++, crc); |
221 | return crc; |
222 | } |
223 | |
224 | static inline unsigned long |
225 | crc32(const char *s) |
226 | { |
227 | return partial_crc32(s, 0xffffffff) ^ 0xffffffff; |
228 | } |
229 | |
230 | |
f104d082 |
231 | extern char *intOutputTypes[]; |
232 | |
233 | extern char *uintOutputTypes[]; |
234 | |
235 | extern char *floatOutputTypes[]; |
236 | |
237 | |
238 | |
239 | |
90395b4b |
240 | #endif // PARSER_H |