network byte order + state multitraces fix
[lttv.git] / ltt / branches / poly / ltt / parser.h
CommitLineData
90395b4b 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;
90699b2b 10} sequence_t;
90395b4b 11
90699b2b 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);
90395b4b 16
17
18/* Hash table */
19
20typedef struct _table {
90699b2b 21 sequence_t keys;
22 sequence_t values;
23} table_t;
90395b4b 24
90699b2b 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);
90395b4b 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
90699b2b 44} token_type_t;
90395b4b 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;
90699b2b 53 token_type_t type;
90395b4b 54 int unget;
55 void (*error) (struct _parse_file *, char *);
90699b2b 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);
90395b4b 71
72/* Some constants */
73
74static const int BUFFER_SIZE = 1024;
75
76
77/* Events data types */
78
79typedef 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
90395b4b 104typedef struct _type_descriptor {
105 char * type_name; //used for named type
90699b2b 106 data_type_t type;
90395b4b 107 char *fmt;
f104d082 108 size_t size;
90699b2b 109 sequence_t labels; // for enumeration
f104d082 110 sequence_t labels_values; // for enumeration
90699b2b 111 sequence_t labels_description;
90395b4b 112 int already_printed;
f104d082 113 sequence_t fields; // for structure, array and sequence (field_t type)
f0b795e0 114 int custom_write; /* Should we use a custom write function ? */
115 int network; /* Is the type a in network byte order ? */
90699b2b 116} type_descriptor_t;
90395b4b 117
118
90395b4b 119
f104d082 120/* Fields within types or events */
90395b4b 121typedef struct _field{
122 char *name;
123 char *description;
90699b2b 124 type_descriptor_t *type;
125} field_t;
90395b4b 126
127
128/* Events definitions */
129
130typedef struct _event {
131 char *name;
132 char *description;
f104d082 133 //type_descriptor_t *type;
134 sequence_t fields; /* event fields */
90395b4b 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 ? */
90699b2b 137} event_t;
90395b4b 138
139typedef struct _facility {
140 char * name;
141 char * capname;
f5d7967f 142 char * arch;
90395b4b 143 char * description;
90699b2b 144 sequence_t events;
f104d082 145 sequence_t unnamed_types; //FIXME : remove
90699b2b 146 table_t named_types;
f104d082 147 unsigned int checksum;
90699b2b 148} facility_t;
149
f104d082 150int getSizeindex(unsigned int value);
151unsigned long long int getSize(parse_file_t *in);
90699b2b 152unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
153
154void parseFacility(parse_file_t *in, facility_t * fac);
155void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
156 table_t * named_types);
157void parseTypeDefinition(parse_file_t *in,
158 sequence_t * unnamed_types, table_t * named_types);
159type_descriptor_t *parseType(parse_file_t *in,
160 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
f104d082 161void parseFields(parse_file_t *in, field_t *f,
162 sequence_t * unnamed_types,
163 table_t * named_types,
164 int tag);
90699b2b 165void checkNamedTypesImplemented(table_t * namedTypes);
166type_descriptor_t * find_named_type(char *name, table_t * named_types);
167void generateChecksum(char * facName,
f104d082 168 unsigned int * checksum, sequence_t * events);
90395b4b 169
170
171/* get attributes */
90699b2b 172char * getNameAttribute(parse_file_t *in);
173char * getFormatAttribute(parse_file_t *in);
174int getSizeAttribute(parse_file_t *in);
175int getValueAttribute(parse_file_t *in);
176char * getValueStrAttribute(parse_file_t *in);
90395b4b 177
90699b2b 178char * getDescription(parse_file_t *in);
90395b4b 179
180
90395b4b 181/* Dynamic memory allocation and freeing */
182
183void * memAlloc(int size);
184char *allocAndCopy(char * str);
185char *appendString(char *s, char *suffix);
90699b2b 186void freeTypes(sequence_t *t);
187void freeType(type_descriptor_t * td);
188void freeEvents(sequence_t *t);
189void freeNamedType(table_t * t);
190void error_callback(parse_file_t *in, char *msg);
90395b4b 191
192
193//checksum part
194static const unsigned int crctab32[] =
195{
196#include "crc32.tab"
197};
198
199static inline unsigned long
200partial_crc32_one(unsigned char c, unsigned long crc)
201{
202 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
203}
204
205static inline unsigned long
206partial_crc32(const char *s, unsigned long crc)
207{
208 while (*s)
209 crc = partial_crc32_one(*s++, crc);
210 return crc;
211}
212
213static inline unsigned long
214crc32(const char *s)
215{
216 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
217}
218
219
f104d082 220extern char *intOutputTypes[];
221
222extern char *uintOutputTypes[];
223
224extern char *floatOutputTypes[];
225
226
227
228
90395b4b 229#endif // PARSER_H
This page took 0.035752 seconds and 4 git commands to generate.