many compile fix
[lttv.git] / ltt / branches / poly / ltt / parser.h
1 /*
2
3 parser.c: Generate helper declarations and functions to trace events
4 from an event description file.
5
6 Copyright (C) 2002, Xianxiu Yang
7 Copyright (C) 2002, Michel Dagenais
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #ifndef PARSER_H
23 #define PARSER_H
24
25 #include <glib.h>
26
27 /* Extensible array container */
28
29 typedef struct _sequence {
30 int size;
31 int position;
32 void **array;
33 } sequence;
34
35 void sequence_init(sequence *t);
36 void sequence_dispose(sequence *t);
37 void sequence_push(sequence *t, void *elem);
38 void *sequence_pop(sequence *t);
39
40
41 /* Hash table */
42
43 typedef struct _table {
44 sequence keys;
45 sequence values;
46 } table;
47
48 void table_init(table *t);
49 void table_dispose(table *t);
50 void table_insert(table *t, char *key, void *value);
51 void *table_find(table *t, char *key);
52 void table_insert_int(table *t, int *key, void *value);
53 void *table_find_int(table *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;
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 type;
77 int unget;
78 void (*error) (struct _parse_file *, char *);
79 } parse_file;
80
81 void ungetToken(parse_file * in);
82 char *getToken(parse_file *in);
83 char *getForwardslash(parse_file *in);
84 char *getLAnglebracket(parse_file *in);
85 char *getRAnglebracket(parse_file *in);
86 char *getQuotedString(parse_file *in);
87 char *getName(parse_file *in);
88 int getNumber(parse_file *in);
89 char *getEqual(parse_file *in);
90 char seekNextChar(parse_file *in);
91
92 void skipComment(parse_file * in);
93 void skipEOL(parse_file * 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,
104 UINT,
105 FLOAT,
106 STRING,
107 ENUM,
108 ARRAY,
109 SEQUENCE,
110 STRUCT,
111 UNION,
112 NONE
113 } data_type;
114
115
116 /* Event type descriptors */
117
118 typedef struct _type_descriptor {
119 char * type_name; //used for named type
120 data_type type;
121 char *fmt;
122 int size;
123 sequence labels; // for enumeration
124 sequence fields; // for structure
125 struct _type_descriptor *nested_type; // for array and sequence
126 } type_descriptor;
127
128
129 /* Fields within types */
130
131 typedef struct _type_fields{
132 char *name;
133 char *description;
134 type_descriptor *type;
135 } type_fields;
136
137
138 /* Events definitions */
139
140 typedef struct _event_t {
141 char *name;
142 char *description;
143 type_descriptor *type;
144 } event_t;
145
146 typedef struct _facility_t {
147 char * name;
148 char * description;
149 sequence events;
150 sequence unnamed_types;
151 table named_types;
152 } facility_t;
153
154 int getSize(parse_file *in);
155 unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
156
157 void parseFacility(parse_file *in, facility_t * fac);
158 void parseEvent(parse_file *in, event_t *ev, sequence * unnamed_types, table * named_types);
159 void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
160 type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
161 void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
162 int checkNamedTypesImplemented(table * namedTypes);
163 type_descriptor * find_named_type(char *name, table * named_types);
164 int generateChecksum(char * facName, guint32 * checksum, sequence * events);
165
166
167 /* get attributes */
168 char * getNameAttribute(parse_file *in);
169 char * getFormatAttribute(parse_file *in);
170 int getSizeAttribute(parse_file *in);
171 int getValueAttribute(parse_file *in);
172 char * getValueStrAttribute(parse_file *in);
173
174 char * getDescription(parse_file *in);
175
176
177 static char *intOutputTypes[] = {
178 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
179
180 static char *uintOutputTypes[] = {
181 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
182 "unsigned int", "unsigned long int" };
183
184 static char *floatOutputTypes[] = {
185 "undef", "undef", "float", "double", "undef", "float", "double" };
186
187
188 /* Dynamic memory allocation and freeing */
189
190 void * memAlloc(int size);
191 char *allocAndCopy(char * str);
192 char *appendString(char *s, char *suffix);
193 void freeTypes(sequence *t);
194 void freeType(type_descriptor * td);
195 void freeEvents(sequence *t);
196 void freeNamedType(table * t);
197 void error_callback(parse_file *in, char *msg);
198
199
200 //checksum part
201 static const unsigned int crctab32[] =
202 {
203 #include "crc32.tab"
204 };
205
206 static inline unsigned long
207 partial_crc32_one(unsigned char c, unsigned long crc)
208 {
209 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
210 }
211
212 static inline unsigned long
213 partial_crc32(const char *s, unsigned long crc)
214 {
215 while (*s)
216 crc = partial_crc32_one(*s++, crc);
217 return crc;
218 }
219
220 static inline unsigned long
221 crc32(const char *s)
222 {
223 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
224 }
225
226
227 #endif // PARSER_H
This page took 0.038366 seconds and 4 git commands to generate.