test xml
[lttv.git] / genevent-new / parser.h
CommitLineData
3583026d 1#ifndef PARSER_H
2#define PARSER_H
3
4/* Extensible array container */
5
6typedef struct _sequence {
7 int size;
8 int position;
9 void **array;
10} sequence_t;
11
12void sequence_init(sequence_t *t);
13void sequence_dispose(sequence_t *t);
14void sequence_push(sequence_t *t, void *elem);
15void *sequence_pop(sequence_t *t);
16
17
18/* Hash table */
19
20typedef struct _table {
21 sequence_t keys;
22 sequence_t values;
23} table_t;
24
25void table_init(table_t *t);
26void table_dispose(table_t *t);
27void table_insert(table_t *t, char *key, void *value);
28void *table_find(table_t *t, char *key);
29void table_insert_int(table_t *t, int *key, void *value);
30void *table_find_int(table_t *t, int *key);
31
32
33/* Token types */
34
35typedef 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 */
48typedef 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
58void ungetToken(parse_file_t * in);
59char *getToken(parse_file_t *in);
60char *getForwardslash(parse_file_t *in);
61char *getLAnglebracket(parse_file_t *in);
62char *getRAnglebracket(parse_file_t *in);
63char *getQuotedString(parse_file_t *in);
64char *getName(parse_file_t *in);
65int getNumber(parse_file_t *in);
66char *getEqual(parse_file_t *in);
67char seekNextChar(parse_file_t *in);
68
69void skipComment(parse_file_t * in);
70void skipEOL(parse_file_t * in);
71
72/* Some constants */
73
74static const int BUFFER_SIZE = 1024;
75
76
77/* Events data types */
78
79typedef enum _data_type {
2d2d14a7 80 INT_FIXED,
81 UINT_FIXED,
82 POINTER,
83 CHAR,
84 UCHAR,
85 SHORT,
86 USHORT,
3583026d 87 INT,
88 UINT,
3583026d 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
102} data_type_t;
103
104/* Event type descriptors */
105
106typedef struct _type_descriptor {
107 char * type_name; //used for named type
108 data_type_t type;
109 char *fmt;
2d2d14a7 110 unsigned long long size;
3583026d 111 sequence_t labels; // for enumeration
112 sequence_t labels_description;
113 int already_printed;
114 sequence_t fields; // for structure
115 struct _type_descriptor *nested_type; // for array and sequence
116 int alignment;
117} type_descriptor_t;
118
119
120/* Fields within types */
121
122typedef struct _field{
123 char *name;
124 char *description;
125 type_descriptor_t *type;
126} field_t;
127
128
129/* Events definitions */
130
131typedef struct _event {
132 char *name;
133 char *description;
134 type_descriptor_t *type;
135 int per_trace; /* Is the event able to be logged to a specific trace ? */
136 int per_tracefile; /* Must we log this event in a specific tracefile ? */
137} event_t;
138
139typedef struct _facility {
140 char * name;
141 char * capname;
142 char * description;
143 sequence_t events;
144 sequence_t unnamed_types;
145 table_t named_types;
146} facility_t;
147
2d2d14a7 148int getSizeindex(unsigned int value);
149unsigned long long int getSize(parse_file_t *in);
3583026d 150unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
151
152void parseFacility(parse_file_t *in, facility_t * fac);
153void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
154 table_t * named_types);
155void parseTypeDefinition(parse_file_t *in,
156 sequence_t * unnamed_types, table_t * named_types);
157type_descriptor_t *parseType(parse_file_t *in,
158 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
159void parseFields(parse_file_t *in, type_descriptor_t *t,
160 sequence_t * unnamed_types, table_t * named_types);
161void checkNamedTypesImplemented(table_t * namedTypes);
162type_descriptor_t * find_named_type(char *name, table_t * named_types);
163void generateChecksum(char * facName,
164 unsigned long * checksum, sequence_t * events);
165
166
167/* get attributes */
168char * getNameAttribute(parse_file_t *in);
169char * getFormatAttribute(parse_file_t *in);
170int getSizeAttribute(parse_file_t *in);
171int getValueAttribute(parse_file_t *in);
172char * getValueStrAttribute(parse_file_t *in);
173
174char * getDescription(parse_file_t *in);
175
176
177/* Dynamic memory allocation and freeing */
178
179void * memAlloc(int size);
180char *allocAndCopy(char * str);
181char *appendString(char *s, char *suffix);
182void freeTypes(sequence_t *t);
183void freeType(type_descriptor_t * td);
184void freeEvents(sequence_t *t);
185void freeNamedType(table_t * t);
186void error_callback(parse_file_t *in, char *msg);
187
188
189//checksum part
190static const unsigned int crctab32[] =
191{
192#include "crc32.tab"
193};
194
195static inline unsigned long
196partial_crc32_one(unsigned char c, unsigned long crc)
197{
198 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
199}
200
201static inline unsigned long
202partial_crc32(const char *s, unsigned long crc)
203{
204 while (*s)
205 crc = partial_crc32_one(*s++, crc);
206 return crc;
207}
208
209static inline unsigned long
210crc32(const char *s)
211{
212 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
213}
214
215
2d2d14a7 216extern char *intOutputTypes[];
217
218extern char *uintOutputTypes[];
219
220extern char *floatOutputTypes[];
221
222
223
224
3583026d 225#endif // PARSER_H
This page took 0.031691 seconds and 4 git commands to generate.