update
[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
3583026d 104typedef struct _type_descriptor {
105 char * type_name; //used for named type
106 data_type_t type;
107 char *fmt;
a67cd958 108 size_t size;
3583026d 109 sequence_t labels; // for enumeration
110 sequence_t labels_description;
111 int already_printed;
a67cd958 112 sequence_t fields; // for structure, array and sequence
3583026d 113 int alignment;
114} type_descriptor_t;
115
116
3583026d 117
a67cd958 118/* Fields within types or events */
3583026d 119typedef struct _field{
120 char *name;
121 char *description;
122 type_descriptor_t *type;
123} field_t;
124
125
126/* Events definitions */
127
128typedef struct _event {
129 char *name;
130 char *description;
47299663 131 //type_descriptor_t *type;
132 sequence_t fields; /* event fields */
3583026d 133 int per_trace; /* Is the event able to be logged to a specific trace ? */
134 int per_tracefile; /* Must we log this event in a specific tracefile ? */
135} event_t;
136
137typedef struct _facility {
138 char * name;
139 char * capname;
140 char * description;
141 sequence_t events;
142 sequence_t unnamed_types;
143 table_t named_types;
30d72138 144 unsigned int checksum;
3583026d 145} facility_t;
146
2d2d14a7 147int getSizeindex(unsigned int value);
148unsigned long long int getSize(parse_file_t *in);
3583026d 149unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
150
151void parseFacility(parse_file_t *in, facility_t * fac);
152void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
153 table_t * named_types);
154void parseTypeDefinition(parse_file_t *in,
155 sequence_t * unnamed_types, table_t * named_types);
156type_descriptor_t *parseType(parse_file_t *in,
157 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
47299663 158void parseFields(parse_file_t *in, field_t *f,
2e415130 159 sequence_t * unnamed_types,
160 table_t * named_types,
161 int tag);
3583026d 162void checkNamedTypesImplemented(table_t * namedTypes);
163type_descriptor_t * find_named_type(char *name, table_t * named_types);
164void generateChecksum(char * facName,
30d72138 165 unsigned int * checksum, sequence_t * events);
3583026d 166
167
168/* get attributes */
169char * getNameAttribute(parse_file_t *in);
170char * getFormatAttribute(parse_file_t *in);
171int getSizeAttribute(parse_file_t *in);
172int getValueAttribute(parse_file_t *in);
173char * getValueStrAttribute(parse_file_t *in);
174
175char * getDescription(parse_file_t *in);
176
177
178/* Dynamic memory allocation and freeing */
179
180void * memAlloc(int size);
181char *allocAndCopy(char * str);
182char *appendString(char *s, char *suffix);
183void freeTypes(sequence_t *t);
184void freeType(type_descriptor_t * td);
185void freeEvents(sequence_t *t);
186void freeNamedType(table_t * t);
187void error_callback(parse_file_t *in, char *msg);
188
189
190//checksum part
191static const unsigned int crctab32[] =
192{
193#include "crc32.tab"
194};
195
196static inline unsigned long
197partial_crc32_one(unsigned char c, unsigned long crc)
198{
199 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
200}
201
202static inline unsigned long
203partial_crc32(const char *s, unsigned long crc)
204{
205 while (*s)
206 crc = partial_crc32_one(*s++, crc);
207 return crc;
208}
209
210static inline unsigned long
211crc32(const char *s)
212{
213 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
214}
215
216
2d2d14a7 217extern char *intOutputTypes[];
218
219extern char *uintOutputTypes[];
220
221extern char *floatOutputTypes[];
222
223
224
225
3583026d 226#endif // PARSER_H
This page took 0.038766 seconds and 4 git commands to generate.