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
25 /* Extensible array container */
27 typedef struct _sequence
{
33 void sequence_init(sequence
*t
);
34 void sequence_dispose(sequence
*t
);
35 void sequence_push(sequence
*t
, void *elem
);
36 void *sequence_pop(sequence
*t
);
41 typedef struct _table
{
46 void table_init(table
*t
);
47 void table_dispose(table
*t
);
48 void table_insert(table
*t
, char *key
, void *value
);
49 void *table_find(table
*t
, char *key
);
50 void table_insert_int(table
*t
, int *key
, void *value
);
51 void *table_find_int(table
*t
, int *key
);
56 typedef enum _token_type
{
68 /* State associated with a file being parsed */
69 typedef struct _parse_file
{
76 void (*error
) (struct _parse_file
*, char *);
79 void ungetToken(parse_file
* in
);
80 char *getToken(parse_file
*in
);
81 char *getForwardslash(parse_file
*in
);
82 char *getLAnglebracket(parse_file
*in
);
83 char *getRAnglebracket(parse_file
*in
);
84 char *getQuotedString(parse_file
*in
);
85 char *getName(parse_file
*in
);
86 int getNumber(parse_file
*in
);
87 char *getEqual(parse_file
*in
);
88 char seekNextChar(parse_file
*in
);
90 void skipComment(parse_file
* in
);
91 void skipEOL(parse_file
* in
);
95 static const int BUFFER_SIZE
= 1024;
98 /* Events data types */
100 typedef enum _data_type
{
114 /* Event type descriptors */
116 typedef struct _type_descriptor
{
117 char * type_name
; //used for named type
121 sequence labels
; // for enumeration
122 sequence fields
; // for structure
123 struct _type_descriptor
*nested_type
; // for array and sequence
127 /* Fields within types */
129 typedef struct _type_fields
{
132 type_descriptor
*type
;
136 /* Events definitions */
138 typedef struct _event_t
{
141 type_descriptor
*type
;
144 typedef struct _facility_t
{
148 sequence unnamed_types
;
152 int getSize(parse_file
*in
);
153 unsigned long getTypeChecksum(unsigned long aCrc
, type_descriptor
* type
);
155 void parseFacility(parse_file
*in
, facility_t
* fac
);
156 void parseEvent(parse_file
*in
, event_t
*ev
, sequence
* unnamed_types
, table
* named_types
);
157 void parseTypeDefinition(parse_file
*in
, sequence
* unnamed_types
, table
* named_types
);
158 type_descriptor
*parseType(parse_file
*in
, type_descriptor
*t
, sequence
* unnamed_types
, table
* named_types
);
159 void parseFields(parse_file
*in
, type_descriptor
*t
, sequence
* unnamed_types
, table
* named_types
);
160 int checkNamedTypesImplemented(table
* namedTypes
);
161 type_descriptor
* find_named_type(char *name
, table
* named_types
);
162 int generateChecksum(char * facName
, unsigned long * checksum
, sequence
* events
);
166 char * getNameAttribute(parse_file
*in
);
167 char * getFormatAttribute(parse_file
*in
);
168 int getSizeAttribute(parse_file
*in
);
169 int getValueAttribute(parse_file
*in
);
170 char * getValueStrAttribute(parse_file
*in
);
172 char * getDescription(parse_file
*in
);
175 static char *intOutputTypes
[] = {
176 "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" };
178 static char *uintOutputTypes
[] = {
179 "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int",
180 "unsigned int", "unsigned long int" };
182 static char *floatOutputTypes
[] = {
183 "undef", "undef", "float", "double", "undef", "float", "double" };
186 /* Dynamic memory allocation and freeing */
188 void * memAlloc(int size
);
189 char *allocAndCopy(char * str
);
190 char *appendString(char *s
, char *suffix
);
191 void freeTypes(sequence
*t
);
192 void freeType(type_descriptor
* td
);
193 void freeEvents(sequence
*t
);
194 void freeNamedType(table
* t
);
195 void error_callback(parse_file
*in
, char *msg
);
199 static const unsigned int crctab32
[] =
204 static inline unsigned long
205 partial_crc32_one(unsigned char c
, unsigned long crc
)
207 return crctab32
[(crc
^ c
) & 0xff] ^ (crc
>> 8);
210 static inline unsigned long
211 partial_crc32(const char *s
, unsigned long crc
)
214 crc
= partial_crc32_one(*s
++, crc
);
218 static inline unsigned long
221 return partial_crc32(s
, 0xffffffff) ^ 0xffffffff;
This page took 0.032833 seconds and 4 git commands to generate.