update compat
[lttv.git] / tags / LinuxTraceToolkitViewer-0.10.0-pre-115102007 / ltt / parser.h
CommitLineData
3583026d 1#ifndef PARSER_H
2#define PARSER_H
3
4/* Extensible array container */
5
6typedef struct _sequence {
7 int size;
8 int position;
9 void **array;
10} sequence_t;
11
12void sequence_init(sequence_t *t);
13void sequence_dispose(sequence_t *t);
14void sequence_push(sequence_t *t, void *elem);
15void *sequence_pop(sequence_t *t);
16
17
18/* Hash table */
19
20typedef struct _table {
21 sequence_t keys;
22 sequence_t values;
23} table_t;
24
25void table_init(table_t *t);
26void table_dispose(table_t *t);
27void table_insert(table_t *t, char *key, void *value);
28void *table_find(table_t *t, char *key);
29void table_insert_int(table_t *t, int *key, void *value);
30void *table_find_int(table_t *t, int *key);
31
32
33/* Token types */
34
35typedef enum _token_type {
36 ENDFILE,
37 FORWARDSLASH,
38 LANGLEBRACKET,
39 RANGLEBRACKET,
40 EQUAL,
41 QUOTEDSTRING,
42 NUMBER,
43 NAME
44} token_type_t;
45
46
47/* State associated with a file being parsed */
48typedef struct _parse_file {
49 char *name;
50 FILE * fp;
51 int lineno;
52 char *buffer;
53 token_type_t type;
54 int unget;
55 void (*error) (struct _parse_file *, char *);
56} parse_file_t;
57
58void ungetToken(parse_file_t * in);
59char *getToken(parse_file_t *in);
60char *getForwardslash(parse_file_t *in);
61char *getLAnglebracket(parse_file_t *in);
62char *getRAnglebracket(parse_file_t *in);
63char *getQuotedString(parse_file_t *in);
64char *getName(parse_file_t *in);
65int getNumber(parse_file_t *in);
66char *getEqual(parse_file_t *in);
83e160f2 67int seekNextChar(parse_file_t *in);
3583026d 68
69void skipComment(parse_file_t * in);
70void skipEOL(parse_file_t * in);
71
72/* Some constants */
73
74static const int BUFFER_SIZE = 1024;
75
76
77/* Events data types */
78
79typedef enum _data_type {
2d2d14a7 80 INT_FIXED,
81 UINT_FIXED,
82 POINTER,
83 CHAR,
84 UCHAR,
85 SHORT,
86 USHORT,
3583026d 87 INT,
88 UINT,
3583026d 89 LONG,
90 ULONG,
91 SIZE_T,
92 SSIZE_T,
93 OFF_T,
94 FLOAT,
95 STRING,
96 ENUM,
97 ARRAY,
98 SEQUENCE,
99 STRUCT,
100 UNION,
101 NONE
102} data_type_t;
103
2fef3d3e 104typedef struct _facility facility_t;
105typedef struct _event event_t;
106
3583026d 107typedef struct _type_descriptor {
2fef3d3e 108 facility_t *fac;
3583026d 109 char * type_name; //used for named type
110 data_type_t type;
111 char *fmt;
a67cd958 112 size_t size;
3583026d 113 sequence_t labels; // for enumeration
70f46ac3 114 sequence_t labels_values; // for enumeration
3583026d 115 sequence_t labels_description;
116 int already_printed;
bf6349fa 117 sequence_t fields; // for structure, array and sequence (field_t type)
7479dd85 118 int custom_write; /* Should we use a custom write function ? */
119 int network; /* Is the type a in network byte order ? */
3583026d 120} type_descriptor_t;
121
122
a67cd958 123/* Fields within types or events */
3583026d 124typedef struct _field{
2fef3d3e 125 facility_t *fac;
3583026d 126 char *name;
127 char *description;
128 type_descriptor_t *type;
129} field_t;
130
131
132/* Events definitions */
133
2fef3d3e 134struct _event {
135 facility_t *fac;
3583026d 136 char *name;
137 char *description;
47299663 138 //type_descriptor_t *type;
2fef3d3e 139 sequence_t fields; /* event fields */
3583026d 140 int per_trace; /* Is the event able to be logged to a specific trace ? */
141 int per_tracefile; /* Must we log this event in a specific tracefile ? */
2fef3d3e 142 int param_buffer; /* For userspace tracing : takes a buffer as parameter? */
143 int no_instrument_function;
144 int high_priority;
145 int force;
146 int compact_data;
147};
148
149struct _facility {
3583026d 150 char * name;
2fef3d3e 151 char * capname;
152 char * arch;
153 int align; /* Alignment : default 1, 0 no alignment. */
3583026d 154 char * description;
155 sequence_t events;
70f46ac3 156 sequence_t unnamed_types; //FIXME : remove
3583026d 157 table_t named_types;
2fef3d3e 158 unsigned int checksum;
159 int user; /* Is this a userspace facility ? */
160};
3583026d 161
2d2d14a7 162int getSizeindex(unsigned int value);
163unsigned long long int getSize(parse_file_t *in);
3583026d 164unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
165
166void parseFacility(parse_file_t *in, facility_t * fac);
2fef3d3e 167void parseEvent(facility_t *fac, parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
3583026d 168 table_t * named_types);
2fef3d3e 169void parseTypeDefinition(facility_t *fac, parse_file_t *in,
3583026d 170 sequence_t * unnamed_types, table_t * named_types);
2fef3d3e 171type_descriptor_t *parseType(facility_t *fac, parse_file_t *in,
3583026d 172 type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
2fef3d3e 173void parseFields(facility_t *fac, parse_file_t *in, field_t *f,
2e415130 174 sequence_t * unnamed_types,
175 table_t * named_types,
176 int tag);
3583026d 177void checkNamedTypesImplemented(table_t * namedTypes);
178type_descriptor_t * find_named_type(char *name, table_t * named_types);
179void generateChecksum(char * facName,
30d72138 180 unsigned int * checksum, sequence_t * events);
3583026d 181
182
183/* get attributes */
184char * getNameAttribute(parse_file_t *in);
185char * getFormatAttribute(parse_file_t *in);
186int getSizeAttribute(parse_file_t *in);
bb9014e6 187int getValueAttribute(parse_file_t *in, long long *value);
3583026d 188
189char * getDescription(parse_file_t *in);
190
191
192/* Dynamic memory allocation and freeing */
193
194void * memAlloc(int size);
195char *allocAndCopy(char * str);
196char *appendString(char *s, char *suffix);
197void freeTypes(sequence_t *t);
198void freeType(type_descriptor_t * td);
199void freeEvents(sequence_t *t);
200void freeNamedType(table_t * t);
201void error_callback(parse_file_t *in, char *msg);
202
203
204//checksum part
205static const unsigned int crctab32[] =
206{
207#include "crc32.tab"
208};
209
210static inline unsigned long
211partial_crc32_one(unsigned char c, unsigned long crc)
212{
213 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
214}
215
216static inline unsigned long
217partial_crc32(const char *s, unsigned long crc)
218{
219 while (*s)
220 crc = partial_crc32_one(*s++, crc);
221 return crc;
222}
223
224static inline unsigned long
225crc32(const char *s)
226{
227 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
228}
229
230
2d2d14a7 231extern char *intOutputTypes[];
232
233extern char *uintOutputTypes[];
234
235extern char *floatOutputTypes[];
236
237
238
239
3583026d 240#endif // PARSER_H
This page took 0.054471 seconds and 4 git commands to generate.