2 * parser.h: Generate helper declarations and functions to trace events
3 * from an event description file.
5 * Copyright (C) 2005, Mathieu Desnoyers
6 * Copyright (C) 2002, Xianxiu Yang
7 * Copyright (C) 2002, Michel Dagenais
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.
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.
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.
27 /* Extensible array container */
29 typedef struct _sequence
{
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
);
43 typedef struct _table
{
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
);
58 typedef enum _token_type
{
70 /* State associated with a file being parsed */
71 typedef struct _parse_file
{
78 void (*error
) (struct _parse_file
*, char *);
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
);
92 void skipComment(parse_file_t
* in
);
93 void skipEOL(parse_file_t
* in
);
97 static const int BUFFER_SIZE
= 1024;
100 /* Events data types */
102 typedef enum _data_type
{
127 typedef struct _type_descriptor
{
128 char * type_name
; //used for named type
132 sequence_t labels
; // for enumeration
133 sequence_t labels_values
; // for enumeration
134 sequence_t labels_description
;
136 sequence_t fields
; // for structure, array and sequence (field_t type)
137 int custom_write
; /* Should we use a custom write function ? */
142 /* Fields within types or events */
143 typedef struct _field
{
146 type_descriptor_t
*type
;
150 /* Events definitions */
152 typedef struct _event
{
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 ? */
161 typedef struct _facility
{
167 sequence_t unnamed_types
; //FIXME : remove
169 unsigned int checksum
;
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
);
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
,
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
);
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
);
200 char * getDescription(parse_file_t
*in
);
203 /* Dynamic memory allocation and freeing */
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
);
216 static const unsigned int crctab32
[] =
221 static inline unsigned long
222 partial_crc32_one(unsigned char c
, unsigned long crc
)
224 return crctab32
[(crc
^ c
) & 0xff] ^ (crc
>> 8);
227 static inline unsigned long
228 partial_crc32(const char *s
, unsigned long crc
)
231 crc
= partial_crc32_one(*s
++, crc
);
235 static inline unsigned long
238 return partial_crc32(s
, 0xffffffff) ^ 0xffffffff;
242 extern char *intOutputTypes
[];
244 extern char *uintOutputTypes
[];
246 extern char *floatOutputTypes
[];