Add config.h support : will fix the LARGEFILE problem
[lttv.git] / ltt / branches / poly / ltt / type.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <stdio.h>
24 #include <glib.h>
25
26 #include "parser.h"
27 #include <ltt/ltt.h>
28 #include "ltt-private.h"
29 #include <ltt/type.h>
30
31 static unsigned intSizes[] = {
32 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
33 sizeof(short) };
34
35 typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32,
36 SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER }
37 intSizesNames;
38
39
40 static unsigned floatSizes[] = {
41 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
42
43 #define FLOAT_SIZES_NUMBER 7
44
45
46 /*****************************************************************************
47 *Function name
48 * ltt_eventtype_name : get the name of the event type
49 *Input params
50 * et : an event type
51 *Return value
52 * char * : the name of the event type
53 ****************************************************************************/
54
55 gchar *ltt_eventtype_name(LttEventType *et)
56 {
57 return et->name;
58 }
59
60 /*****************************************************************************
61 *Function name
62 * ltt_eventtype_description : get the description of the event type
63 *Input params
64 * et : an event type
65 *Return value
66 * char * : the description of the event type
67 ****************************************************************************/
68
69 gchar *ltt_eventtype_description(LttEventType *et)
70 {
71 return et->description;
72 }
73
74 /*****************************************************************************
75 *Function name
76 * ltt_eventtype_facility : get the facility which contains the event type
77 *Input params
78 * et : an event type
79 *Return value
80 * LttFacility * : the facility
81 ****************************************************************************/
82
83 LttFacility *ltt_eventtype_facility(LttEventType *et)
84 {
85 return et->facility;
86 }
87
88 /*****************************************************************************
89 *Function name
90 * ltt_eventtype_relative_id : get the relative id of the event type
91 *Input params
92 * et : an event type
93 *Return value
94 * unsigned : the relative id
95 ****************************************************************************/
96
97 unsigned ltt_eventtype_relative_id(LttEventType *et)
98 {
99 return et->index;
100 }
101
102 /*****************************************************************************
103 *Function name
104 * ltt_eventtype_id : get the id of the event type
105 *Input params
106 * et : an event type
107 *Return value
108 * unsigned : the id
109 ****************************************************************************/
110
111 unsigned ltt_eventtype_id(LttEventType *et)
112 {
113 return et->facility->base_id + et->index;
114 }
115
116 /*****************************************************************************
117 *Function name
118 * ltt_eventtype_type : get the type of the event type
119 *Input params
120 * et : an event type
121 *Return value
122 * LttType * : the type of the event type
123 ****************************************************************************/
124
125 LttType *ltt_eventtype_type(LttEventType *et)
126 {
127 if(unlikely(!et->root_field)) return NULL;
128 else return et->root_field->field_type;
129 }
130
131 /*****************************************************************************
132 *Function name
133 * ltt_eventtype_field : get the root filed of the event type
134 *Input params
135 * et : an event type
136 *Return value
137 * LttField * : the root filed of the event type
138 ****************************************************************************/
139
140 LttField *ltt_eventtype_field(LttEventType *et)
141 {
142 return et->root_field;
143 }
144
145 /*****************************************************************************
146 *Function name
147 * ltt_type_name : get the name of the type
148 *Input params
149 * t : a type
150 *Return value
151 * char * : the name of the type
152 ****************************************************************************/
153
154 gchar *ltt_type_name(LttType *t)
155 {
156 return t->element_name;
157 }
158
159 /*****************************************************************************
160 *Function name
161 * ltt_type_class : get the type class of the type
162 *Input params
163 * t : a type
164 *Return value
165 * LttTypeEnum : the type class of the type
166 ****************************************************************************/
167
168 LttTypeEnum ltt_type_class(LttType *t)
169 {
170 return t->type_class;
171 }
172
173 /*****************************************************************************
174 *Function name
175 * ltt_type_size : obtain the type size. The size is the number of bytes
176 * for primitive types (INT, UINT, FLOAT, ENUM), or the
177 * size for the unsigned integer length count for sequences
178 *Input params
179 * tf : trace file
180 * t : a type
181 *Return value
182 * unsigned : the type size
183 * returns 0 if erroneous, and show a critical warning message.
184 ****************************************************************************/
185
186 unsigned ltt_type_size(LttTrace * trace, LttType *t)
187 {
188 unsigned size;
189 if(unlikely(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY ||
190 t->type_class==LTT_STRING || t->type_class==LTT_UNION)) {
191 size = 0;
192 } else {
193 if(t->type_class == LTT_FLOAT){
194 size = floatSizes[t->size];
195 }else{
196 if(likely(t->size < INT_SIZES_NUMBER))
197 size = intSizes[t->size];
198 else{
199 LttArchSize archsize = trace->system_description->size;
200 if(archsize == LTT_LP32){
201 if(t->size == 5) size = intSizes[SIZE_INT16];
202 else size = intSizes[SIZE_INT32];
203 }
204 else if(archsize == LTT_ILP32 || archsize == LTT_LP64){
205 if(t->size == 5) size = intSizes[SIZE_INT32];
206 else{
207 if(archsize == LTT_ILP32) size = intSizes[SIZE_INT32];
208 else size = intSizes[SIZE_INT64];
209 }
210 }
211 else if(archsize == LTT_ILP64) size = intSizes[SIZE_INT64];
212 }
213 }
214 }
215
216 return size;
217 }
218
219 /*****************************************************************************
220 *Function name
221 * ltt_type_element_type : obtain the type of nested elements for arrays
222 * and sequences
223 *Input params
224 * t : a type
225 *Return value
226 * LttType : the type of nested element of array or sequence
227 ****************************************************************************/
228
229 LttType *ltt_type_element_type(LttType *t)
230 {
231 LttType *element_type;
232
233 if(unlikely(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE))
234 element_type = NULL;
235 else
236 element_type = t->element_type[0];
237
238 return element_type;
239 }
240
241 /*****************************************************************************
242 *Function name
243 * ltt_type_element_number : obtain the number of elements for arrays
244 *Input params
245 * t : a type
246 *Return value
247 * unsigned : the number of elements for arrays
248 ****************************************************************************/
249
250 unsigned ltt_type_element_number(LttType *t)
251 {
252 unsigned ret = 0;
253
254 if(likely(t->type_class == LTT_ARRAY))
255 ret = t->element_number;
256
257 return ret;
258 }
259
260 /*****************************************************************************
261 *Function name
262 * ltt_type_member_number : obtain the number of data members for structure
263 *Input params
264 * t : a type
265 *Return value
266 * unsigned : the number of members for structure
267 ****************************************************************************/
268
269 unsigned ltt_type_member_number(LttType *t)
270 {
271 unsigned ret = 0;
272
273 if(likely(t->type_class == LTT_STRUCT || t->type_class == LTT_UNION))
274 ret =t->element_number;
275
276 return ret;
277 }
278
279 /*****************************************************************************
280 *Function name
281 * ltt_type_member_type : obtain the type of a data member in a structure
282 * or union.
283 *Input params
284 * t : a type
285 * i : index of the member
286 *Return value
287 * LttType * : the type of structure member
288 ****************************************************************************/
289
290 LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name)
291 {
292 LttType *member_type = NULL;
293
294 if(unlikely( (t->type_class != LTT_STRUCT
295 && t->type_class != LTT_UNION)
296 ||
297 (i >= t->element_number)
298 )) {
299 *name = NULL;
300 } else {
301 *name = t->element_type[i]->element_name;
302 member_type = t->element_type[i];
303 }
304
305 return member_type;
306 }
307
308 /*****************************************************************************
309 *Function name
310 * ltt_enum_string_get : for enumerations, obtain the symbolic string
311 * associated with a value (0 to n - 1 for an
312 * enumeration of n elements)
313 *Input params
314 * t : a type
315 * i : index of the member
316 *Return value
317 * char * : symbolic string associated with a value
318 ****************************************************************************/
319
320 char *ltt_enum_string_get(LttType *t, unsigned i)
321 {
322 gchar *string = NULL;
323
324 if(likely(t->type_class == LTT_ENUM && i < t->element_number))
325 string = t->enum_strings[i];
326
327 return string;
328 }
329
330 /*****************************************************************************
331 *Function name
332 * ltt_field_element : obtain the field of nested elements for arrays and
333 * sequence
334 *Input params
335 * f : a field
336 *Return value
337 * LttField * : the field of the nested element
338 ****************************************************************************/
339
340 LttField *ltt_field_element(LttField *f)
341 {
342 LttField *nest = NULL;
343
344 if(likely(f->field_type->type_class == LTT_ARRAY ||
345 f->field_type->type_class == LTT_SEQUENCE))
346 nest = f->child[0];
347
348 return nest;
349 }
350
351 /*****************************************************************************
352 *Function name
353 * ltt_field_member : obtain the field of data members for structure
354 *Input params
355 * f : a field
356 * i : index of member field
357 *Return value
358 * LttField * : the field of the nested element
359 ****************************************************************************/
360
361 LttField *ltt_field_member(LttField *f, unsigned i)
362 {
363 LttField *field_member;
364
365 if(unlikely( f->field_type->type_class != LTT_STRUCT
366 && f->field_type->type_class != LTT_UNION)
367 || i >= f->field_type->element_number )
368 field_member = NULL;
369 else
370 field_member = f->child[i];
371
372 return field_member;
373 }
374
375 /*****************************************************************************
376 *Function name
377 * ltt_field_type : obtain the type of the field
378 *Input params
379 * f : a field
380 *Return value
381 * ltt_tyoe * : the type of field
382 ****************************************************************************/
383
384 LttType *ltt_field_type(LttField *f)
385 {
386 if(unlikely(!f))return NULL;
387 return f->field_type;
388 }
389
390 int ltt_field_size(LttField * f)
391 {
392 if(unlikely(!f))return 0;
393 return f->field_size;
394 }
This page took 0.038308 seconds and 4 git commands to generate.