many compile fix
[lttv.git] / ltt / branches / poly / ltt / parser.h
CommitLineData
449cb9d7 1/*
2
3parser.c: Generate helper declarations and functions to trace events
4 from an event description file.
5
6Copyright (C) 2002, Xianxiu Yang
7Copyright (C) 2002, Michel Dagenais
8This 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
10the Free Software Foundation; version 2 of the License.
11
12This 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
6cd62ccf 22#ifndef PARSER_H
23#define PARSER_H
24
0f7f40c1 25#include <glib.h>
26
6cd62ccf 27/* Extensible array container */
28
29typedef struct _sequence {
30 int size;
31 int position;
32 void **array;
33} sequence;
34
35void sequence_init(sequence *t);
36void sequence_dispose(sequence *t);
37void sequence_push(sequence *t, void *elem);
38void *sequence_pop(sequence *t);
39
40
41/* Hash table */
42
43typedef struct _table {
44 sequence keys;
45 sequence values;
46} table;
47
48void table_init(table *t);
49void table_dispose(table *t);
50void table_insert(table *t, char *key, void *value);
51void *table_find(table *t, char *key);
52void table_insert_int(table *t, int *key, void *value);
53void *table_find_int(table *t, int *key);
54
55
56/* Token types */
57
58typedef enum _token_type {
59 ENDFILE,
963b5f2d 60 FORWARDSLASH,
61 LANGLEBRACKET,
62 RANGLEBRACKET,
6cd62ccf 63 EQUAL,
64 QUOTEDSTRING,
65 NUMBER,
66 NAME
67} token_type;
68
69
70/* State associated with a file being parsed */
71typedef 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
81void ungetToken(parse_file * in);
82char *getToken(parse_file *in);
963b5f2d 83char *getForwardslash(parse_file *in);
84char *getLAnglebracket(parse_file *in);
85char *getRAnglebracket(parse_file *in);
6cd62ccf 86char *getQuotedString(parse_file *in);
87char *getName(parse_file *in);
963b5f2d 88int getNumber(parse_file *in);
89char *getEqual(parse_file *in);
90char seekNextChar(parse_file *in);
6cd62ccf 91
92void skipComment(parse_file * in);
93void skipEOL(parse_file * in);
6cd62ccf 94
95/* Some constants */
96
97static const int BUFFER_SIZE = 1024;
98
99
100/* Events data types */
101
102typedef enum _data_type {
103 INT,
104 UINT,
105 FLOAT,
106 STRING,
107 ENUM,
108 ARRAY,
109 SEQUENCE,
110 STRUCT,
963b5f2d 111 UNION,
6cd62ccf 112 NONE
113} data_type;
114
115
116/* Event type descriptors */
117
118typedef 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
8d1e6362 131typedef struct _type_fields{
6cd62ccf 132 char *name;
133 char *description;
134 type_descriptor *type;
8d1e6362 135} type_fields;
6cd62ccf 136
137
138/* Events definitions */
139
8d1e6362 140typedef struct _event_t {
6cd62ccf 141 char *name;
142 char *description;
143 type_descriptor *type;
8d1e6362 144} event_t;
6cd62ccf 145
8d1e6362 146typedef struct _facility_t {
963b5f2d 147 char * name;
148 char * description;
149 sequence events;
150 sequence unnamed_types;
151 table named_types;
8d1e6362 152} facility_t;
963b5f2d 153
6cd62ccf 154int getSize(parse_file *in);
963b5f2d 155unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
6cd62ccf 156
8d1e6362 157void parseFacility(parse_file *in, facility_t * fac);
158void parseEvent(parse_file *in, event_t *ev, sequence * unnamed_types, table * named_types);
6cd62ccf 159void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types);
160type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
161void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types);
fc063e40 162int checkNamedTypesImplemented(table * namedTypes);
6cd62ccf 163type_descriptor * find_named_type(char *name, table * named_types);
0f7f40c1 164int generateChecksum(char * facName, guint32 * checksum, sequence * events);
6cd62ccf 165
166
963b5f2d 167/* get attributes */
168char * getNameAttribute(parse_file *in);
169char * getFormatAttribute(parse_file *in);
170int getSizeAttribute(parse_file *in);
171int getValueAttribute(parse_file *in);
172char * getValueStrAttribute(parse_file *in);
173
174char * getDescription(parse_file *in);
175
6cd62ccf 176
177static char *intOutputTypes[] = {
178 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
179
180static char *uintOutputTypes[] = {
181 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
182 "unsigned int", "unsigned long int" };
183
184static char *floatOutputTypes[] = {
185 "undef", "undef", "float", "double", "undef", "float", "double" };
186
187
188/* Dynamic memory allocation and freeing */
189
190void * memAlloc(int size);
191char *allocAndCopy(char * str);
192char *appendString(char *s, char *suffix);
193void freeTypes(sequence *t);
194void freeType(type_descriptor * td);
195void freeEvents(sequence *t);
196void freeNamedType(table * t);
197void error_callback(parse_file *in, char *msg);
198
199
200//checksum part
201static const unsigned int crctab32[] =
202{
203#include "crc32.tab"
204};
205
206static inline unsigned long
207partial_crc32_one(unsigned char c, unsigned long crc)
208{
209 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
210}
211
212static inline unsigned long
213partial_crc32(const char *s, unsigned long crc)
214{
215 while (*s)
216 crc = partial_crc32_one(*s++, crc);
217 return crc;
218}
219
220static inline unsigned long
221crc32(const char *s)
222{
223 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
224}
225
226
227#endif // PARSER_H
This page took 0.038811 seconds and 4 git commands to generate.