3 parser.c: Generate helper declarations and functions to trace events
4 from an event description file.
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.
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.
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
27 /* Extensible array container */
29 typedef struct _sequence
{
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
);
43 typedef struct _table
{
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
);
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
* 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
);
92 void skipComment(parse_file
* in
);
93 void skipEOL(parse_file
* in
);
97 static const int BUFFER_SIZE
= 1024;
100 /* Events data types */
102 typedef enum _data_type
{
116 /* Event type descriptors */
118 typedef struct _type_descriptor
{
119 char * type_name
; //used for named type
123 sequence labels
; // for enumeration
124 sequence fields
; // for structure
125 struct _type_descriptor
*nested_type
; // for array and sequence
129 /* Fields within types */
131 typedef struct _type_fields
{
134 type_descriptor
*type
;
138 /* Events definitions */
140 typedef struct _event_t
{
143 type_descriptor
*type
;
146 typedef struct _facility_t
{
150 sequence unnamed_types
;
154 int getSize(parse_file
*in
);
155 unsigned long getTypeChecksum(unsigned long aCrc
, type_descriptor
* type
);
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
);
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
);
174 char * getDescription(parse_file
*in
);
177 static char *intOutputTypes
[] = {
178 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
180 static char *uintOutputTypes
[] = {
181 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
182 "unsigned int", "unsigned long int" };
184 static char *floatOutputTypes
[] = {
185 "undef", "undef", "float", "double", "undef", "float", "double" };
188 /* Dynamic memory allocation and freeing */
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
);
201 static const unsigned int crctab32
[] =
206 static inline unsigned long
207 partial_crc32_one(unsigned char c
, unsigned long crc
)
209 return crctab32
[(crc
^ c
) & 0xff] ^ (crc
>> 8);
212 static inline unsigned long
213 partial_crc32(const char *s
, unsigned long crc
)
216 crc
= partial_crc32_one(*s
++, crc
);
220 static inline unsigned long
223 return partial_crc32(s
, 0xffffffff) ^ 0xffffffff;
This page took 0.040776 seconds and 4 git commands to generate.