git-svn-id: http://ltt.polymtl.ca/svn@461 04897980-b3bd-0310-b5e0-8ef037075253
[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
25/* Extensible array container */
26
27typedef struct _sequence {
28 int size;
29 int position;
30 void **array;
31} sequence;
32
33void sequence_init(sequence *t);
34void sequence_dispose(sequence *t);
35void sequence_push(sequence *t, void *elem);
36void *sequence_pop(sequence *t);
37
38
39/* Hash table */
40
41typedef struct _table {
42 sequence keys;
43 sequence values;
44} table;
45
46void table_init(table *t);
47void table_dispose(table *t);
48void table_insert(table *t, char *key, void *value);
49void *table_find(table *t, char *key);
50void table_insert_int(table *t, int *key, void *value);
51void *table_find_int(table *t, int *key);
52
53
54/* Token types */
55
56typedef enum _token_type {
57 ENDFILE,
963b5f2d 58 FORWARDSLASH,
59 LANGLEBRACKET,
60 RANGLEBRACKET,
6cd62ccf 61 EQUAL,
62 QUOTEDSTRING,
63 NUMBER,
64 NAME
65} token_type;
66
67
68/* State associated with a file being parsed */
69typedef struct _parse_file {
70 char *name;
71 FILE * fp;
72 int lineno;
73 char *buffer;
74 token_type type;
75 int unget;
76 void (*error) (struct _parse_file *, char *);
77} parse_file;
78
79void ungetToken(parse_file * in);
80char *getToken(parse_file *in);
963b5f2d 81char *getForwardslash(parse_file *in);
82char *getLAnglebracket(parse_file *in);
83char *getRAnglebracket(parse_file *in);
6cd62ccf 84char *getQuotedString(parse_file *in);
85char *getName(parse_file *in);
963b5f2d 86int getNumber(parse_file *in);
87char *getEqual(parse_file *in);
88char seekNextChar(parse_file *in);
6cd62ccf 89
90void skipComment(parse_file * in);
91void skipEOL(parse_file * in);
92int isalpha(char car);
93int isalnum(char car);
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
131typedef struct _field{
132 char *name;
133 char *description;
134 type_descriptor *type;
135} field;
136
137
138/* Events definitions */
139
140typedef struct _event {
141 char *name;
142 char *description;
143 type_descriptor *type;
6cd62ccf 144} event;
145
963b5f2d 146typedef struct _facility {
147 char * name;
148 char * description;
149 sequence events;
150 sequence unnamed_types;
151 table named_types;
152} facility;
153
6cd62ccf 154int getSize(parse_file *in);
963b5f2d 155unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type);
6cd62ccf 156
963b5f2d 157void parseFacility(parse_file *in, facility * fac);
6cd62ccf 158void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types);
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);
162void checkNamedTypesImplemented(table * namedTypes);
163type_descriptor * find_named_type(char *name, table * named_types);
164void generateChecksum(char * facName, unsigned long * checksum, sequence * events);
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.03461 seconds and 4 git commands to generate.