genevent with align support
[lttv.git] / genevent / parser.h
CommitLineData
3888436c 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;
11
12void sequence_init(sequence *t);
13void sequence_dispose(sequence *t);
14void sequence_push(sequence *t, void *elem);
15void *sequence_pop(sequence *t);
16
17
18/* Hash table */
19
20typedef struct _table {
21 sequence keys;
22 sequence values;
23} table;
24
25void table_init(table *t);
26void table_dispose(table *t);
27void table_insert(table *t, char *key, void *value);
28void *table_find(table *t, char *key);
29void table_insert_int(table *t, int *key, void *value);
30void *table_find_int(table *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;
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 type;
54 int unget;
55 void (*error) (struct _parse_file *, char *);
56} parse_file;
57
58void ungetToken(parse_file * in);
59char *getToken(parse_file *in);
60char *getForwardslash(parse_file *in);
61char *getLAnglebracket(parse_file *in);
62char *getRAnglebracket(parse_file *in);
63char *getQuotedString(parse_file *in);
64char *getName(parse_file *in);
65int getNumber(parse_file *in);
66char *getEqual(parse_file *in);
67char seekNextChar(parse_file *in);
68
69void skipComment(parse_file * in);
70void skipEOL(parse_file * in);
3888436c 71
72/* Some constants */
73
74static const int BUFFER_SIZE = 1024;
75
76
77/* Events data types */
78
79typedef enum _data_type {
80 INT,
81 UINT,
31cbc5d3 82 POINTER,
83 LONG,
84 ULONG,
85 SIZE_T,
86 SSIZE_T,
87 OFF_T,
3888436c 88 FLOAT,
89 STRING,
90 ENUM,
91 ARRAY,
92 SEQUENCE,
93 STRUCT,
94 UNION,
95 NONE
96} data_type;
97
3888436c 98/* Event type descriptors */
99
100typedef struct _type_descriptor {
101 char * type_name; //used for named type
102 data_type type;
103 char *fmt;
104 int size;
105 sequence labels; // for enumeration
8c6ca411 106 sequence labels_description;
44cac8a9 107 int already_printed;
3888436c 108 sequence fields; // for structure
109 struct _type_descriptor *nested_type; // for array and sequence
9774b764 110 int alignment;
3888436c 111} type_descriptor;
112
113
114/* Fields within types */
115
116typedef struct _field{
117 char *name;
118 char *description;
119 type_descriptor *type;
120} field;
121
122
123/* Events definitions */
124
125typedef struct _event {
126 char *name;
127 char *description;
128 type_descriptor *type;
129} event;
130
131typedef struct _facility {
132 char * name;
31cbc5d3 133 char * capname;
3888436c 134 char * description;
135 sequence events;
136 sequence unnamed_types;
137 table named_types;
138} facility;
139
140int getSize(parse_file *in);
141unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
142
143void parseFacility(parse_file *in, facility * fac);
144void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
145void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
146type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
147void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
148void checkNamedTypesImplemented(table * namedTypes);
149type_descriptor * find_named_type(char *name, table * named_types);
150void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
151
152
153/* get attributes */
154char * getNameAttribute(parse_file *in);
155char * getFormatAttribute(parse_file *in);
156int getSizeAttribute(parse_file *in);
157int getValueAttribute(parse_file *in);
158char * getValueStrAttribute(parse_file *in);
159
160char * getDescription(parse_file *in);
161
162
163static char *intOutputTypes[] = {
164 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
165
166static char *uintOutputTypes[] = {
167 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
168 "unsigned int", "unsigned long int" };
169
170static char *floatOutputTypes[] = {
171 "undef", "undef", "float", "double", "undef", "float", "double" };
172
173
174/* Dynamic memory allocation and freeing */
175
176void * memAlloc(int size);
177char *allocAndCopy(char * str);
178char *appendString(char *s, char *suffix);
179void freeTypes(sequence *t);
180void freeType(type_descriptor * td);
181void freeEvents(sequence *t);
182void freeNamedType(table * t);
183void error_callback(parse_file *in, char *msg);
184
185
186//checksum part
187static const unsigned int crctab32[] =
188{
189#include "crc32.tab"
190};
191
192static inline unsigned long
193partial_crc32_one(unsigned char c, unsigned long crc)
194{
195 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
196}
197
198static inline unsigned long
199partial_crc32(const char *s, unsigned long crc)
200{
201 while (*s)
202 crc = partial_crc32_one(*s++, crc);
203 return crc;
204}
205
206static inline unsigned long
207crc32(const char *s)
208{
209 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
210}
211
212
213#endif // PARSER_H
This page took 0.031285 seconds and 4 git commands to generate.