Make sure libtraceread is completely licensed LGPL
[lttv.git] / ltt / branches / poly / ltt / parser.h
1 /*
2 * parser.h: Generate helper declarations and functions to trace events
3 * from an event description file.
4 *
5 * Copyright (C) 2005, Mathieu Desnoyers
6 * Copyright (C) 2002, Xianxiu Yang
7 * Copyright (C) 2002, Michel Dagenais
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License Version 2.1 as published by the Free Software Foundation.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24 #ifndef PARSER_H
25 #define PARSER_H
26
27 /* Extensible array container */
28
29 typedef struct _sequence {
30 int size;
31 int position;
32 void **array;
33 } sequence_t;
34
35 void sequence_init(sequence_t *t);
36 void sequence_dispose(sequence_t *t);
37 void sequence_push(sequence_t *t, void *elem);
38 void *sequence_pop(sequence_t *t);
39
40
41 /* Hash table */
42
43 typedef struct _table {
44 sequence_t keys;
45 sequence_t values;
46 } table_t;
47
48 void table_init(table_t *t);
49 void table_dispose(table_t *t);
50 void table_insert(table_t *t, char *key, void *value);
51 void *table_find(table_t *t, char *key);
52 void table_insert_int(table_t *t, int *key, void *value);
53 void *table_find_int(table_t *t, int *key);
54
55
56 /* Token types */
57
58 typedef enum _token_type {
59 ENDFILE,
60 FORWARDSLASH,
61 LANGLEBRACKET,
62 RANGLEBRACKET,
63 EQUAL,
64 QUOTEDSTRING,
65 NUMBER,
66 NAME
67 } token_type_t;
68
69
70 /* State associated with a file being parsed */
71 typedef struct _parse_file {
72 char *name;
73 FILE * fp;
74 int lineno;
75 char *buffer;
76 token_type_t type;
77 int unget;
78 void (*error) (struct _parse_file *, char *);
79 } parse_file_t;
80
81 void ungetToken(parse_file_t * in);
82 char *getToken(parse_file_t *in);
83 char *getForwardslash(parse_file_t *in);
84 char *getLAnglebracket(parse_file_t *in);
85 char *getRAnglebracket(parse_file_t *in);
86 char *getQuotedString(parse_file_t *in);
87 char *getName(parse_file_t *in);
88 int getNumber(parse_file_t *in);
89 char *getEqual(parse_file_t *in);
90 char seekNextChar(parse_file_t *in);
91
92 void skipComment(parse_file_t * in);
93 void skipEOL(parse_file_t * in);
94
95 /* Some constants */
96
97 static const int BUFFER_SIZE = 1024;
98
99
100 /* Events data types */
101
102 typedef enum _data_type {
103 INT_FIXED,
104 UINT_FIXED,
105 POINTER,
106 CHAR,
107 UCHAR,
108 SHORT,
109 USHORT,
110 INT,
111 UINT,
112 LONG,
113 ULONG,
114 SIZE_T,
115 SSIZE_T,
116 OFF_T,
117 FLOAT,
118 STRING,
119 ENUM,
120 ARRAY,
121 SEQUENCE,
122 STRUCT,
123 UNION,
124 NONE
125 } data_type_t;
126
127 typedef struct _type_descriptor {
128 char * type_name; //used for named type
129 data_type_t type;
130 char *fmt;
131 size_t size;
132 sequence_t labels; // for enumeration
133 sequence_t labels_values; // for enumeration
134 sequence_t labels_description;
135 int already_printed;
136 sequence_t fields; // for structure, array and sequence (field_t type)
137 int custom_write; /* Should we use a custom write function ? */
138 } type_descriptor_t;
139
140
141
142 /* Fields within types or events */
143 typedef struct _field{
144 char *name;
145 char *description;
146 type_descriptor_t *type;
147 } field_t;
148
149
150 /* Events definitions */
151
152 typedef struct _event {
153 char *name;
154 char *description;
155 //type_descriptor_t *type;
156 sequence_t fields; /* event fields */
157 int per_trace; /* Is the event able to be logged to a specific trace ? */
158 int per_tracefile; /* Must we log this event in a specific tracefile ? */
159 } event_t;
160
161 typedef struct _facility {
162 char * name;
163 char * capname;
164 char * arch;
165 char * description;
166 sequence_t events;
167 sequence_t unnamed_types; //FIXME : remove
168 table_t named_types;
169 unsigned int checksum;
170 } facility_t;
171
172 int getSizeindex(unsigned int value);
173 unsigned long long int getSize(parse_file_t *in);
174 unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
175
176 void parseFacility(parse_file_t *in, facility_t * fac);
177 void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
178 table_t * named_types);
179 void parseTypeDefinition(parse_file_t *in,
180 sequence_t * unnamed_types, table_t * named_types);
181 type_descriptor_t *parseType(parse_file_t *in,
182 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
183 void parseFields(parse_file_t *in, field_t *f,
184 sequence_t * unnamed_types,
185 table_t * named_types,
186 int tag);
187 void checkNamedTypesImplemented(table_t * namedTypes);
188 type_descriptor_t * find_named_type(char *name, table_t * named_types);
189 void generateChecksum(char * facName,
190 unsigned int * checksum, sequence_t * events);
191
192
193 /* get attributes */
194 char * getNameAttribute(parse_file_t *in);
195 char * getFormatAttribute(parse_file_t *in);
196 int getSizeAttribute(parse_file_t *in);
197 int getValueAttribute(parse_file_t *in);
198 char * getValueStrAttribute(parse_file_t *in);
199
200 char * getDescription(parse_file_t *in);
201
202
203 /* Dynamic memory allocation and freeing */
204
205 void * memAlloc(int size);
206 char *allocAndCopy(char * str);
207 char *appendString(char *s, char *suffix);
208 void freeTypes(sequence_t *t);
209 void freeType(type_descriptor_t * td);
210 void freeEvents(sequence_t *t);
211 void freeNamedType(table_t * t);
212 void error_callback(parse_file_t *in, char *msg);
213
214
215 //checksum part
216 static const unsigned int crctab32[] =
217 {
218 #include "crc32.tab"
219 };
220
221 static inline unsigned long
222 partial_crc32_one(unsigned char c, unsigned long crc)
223 {
224 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
225 }
226
227 static inline unsigned long
228 partial_crc32(const char *s, unsigned long crc)
229 {
230 while (*s)
231 crc = partial_crc32_one(*s++, crc);
232 return crc;
233 }
234
235 static inline unsigned long
236 crc32(const char *s)
237 {
238 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
239 }
240
241
242 extern char *intOutputTypes[];
243
244 extern char *uintOutputTypes[];
245
246 extern char *floatOutputTypes[];
247
248
249
250
251 #endif // PARSER_H
This page took 0.034962 seconds and 4 git commands to generate.