add func instrumentation
[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 ? */
f5c61f8d 137 int param_buffer; /* For userspace tracing : takes a buffer as parameter? */
90699b2b 138} event_t;
90395b4b 139
140typedef struct _facility {
141 char * name;
142 char * capname;
f5d7967f 143 char * arch;
90395b4b 144 char * description;
90699b2b 145 sequence_t events;
f104d082 146 sequence_t unnamed_types; //FIXME : remove
90699b2b 147 table_t named_types;
f104d082 148 unsigned int checksum;
383d64da 149 int user; /* Is this a userspace facility ? */
90699b2b 150} facility_t;
151
f104d082 152int getSizeindex(unsigned int value);
153unsigned long long int getSize(parse_file_t *in);
90699b2b 154unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
155
156void parseFacility(parse_file_t *in, facility_t * fac);
157void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
158 table_t * named_types);
159void parseTypeDefinition(parse_file_t *in,
160 sequence_t * unnamed_types, table_t * named_types);
161type_descriptor_t *parseType(parse_file_t *in,
162 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
f104d082 163void parseFields(parse_file_t *in, field_t *f,
164 sequence_t * unnamed_types,
165 table_t * named_types,
166 int tag);
90699b2b 167void checkNamedTypesImplemented(table_t * namedTypes);
168type_descriptor_t * find_named_type(char *name, table_t * named_types);
169void generateChecksum(char * facName,
f104d082 170 unsigned int * checksum, sequence_t * events);
90395b4b 171
172
173/* get attributes */
90699b2b 174char * getNameAttribute(parse_file_t *in);
175char * getFormatAttribute(parse_file_t *in);
176int getSizeAttribute(parse_file_t *in);
9f2d599d 177int getValueAttribute(parse_file_t *in, long long *value);
90395b4b 178
90699b2b 179char * getDescription(parse_file_t *in);
90395b4b 180
181
90395b4b 182/* Dynamic memory allocation and freeing */
183
184void * memAlloc(int size);
185char *allocAndCopy(char * str);
186char *appendString(char *s, char *suffix);
90699b2b 187void freeTypes(sequence_t *t);
188void freeType(type_descriptor_t * td);
189void freeEvents(sequence_t *t);
190void freeNamedType(table_t * t);
191void error_callback(parse_file_t *in, char *msg);
90395b4b 192
193
194//checksum part
195static const unsigned int crctab32[] =
196{
197#include "crc32.tab"
198};
199
200static inline unsigned long
201partial_crc32_one(unsigned char c, unsigned long crc)
202{
203 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
204}
205
206static inline unsigned long
207partial_crc32(const char *s, unsigned long crc)
208{
209 while (*s)
210 crc = partial_crc32_one(*s++, crc);
211 return crc;
212}
213
214static inline unsigned long
215crc32(const char *s)
216{
217 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
218}
219
220
f104d082 221extern char *intOutputTypes[];
222
223extern char *uintOutputTypes[];
224
225extern char *floatOutputTypes[];
226
227
228
229
90395b4b 230#endif // PARSER_H
This page took 0.037311 seconds and 4 git commands to generate.