Add config.h support : will fix the LARGEFILE problem
[lttv.git] / ltt / branches / poly / ltt / type.c
CommitLineData
449cb9d7 1/* This file is part of the Linux Trace Toolkit viewer
57df94dd 2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
449cb9d7 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
4e4d11b3 19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
6cd62ccf 23#include <stdio.h>
57df94dd 24#include <glib.h>
6cd62ccf 25
6cd62ccf 26#include "parser.h"
a5dcde2f 27#include <ltt/ltt.h>
28#include "ltt-private.h"
6cd62ccf 29#include <ltt/type.h>
30
31static unsigned intSizes[] = {
32 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
33 sizeof(short) };
34
57df94dd 35typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32,
36 SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER }
37 intSizesNames;
38
39
6cd62ccf 40static unsigned floatSizes[] = {
41 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
42
57df94dd 43#define FLOAT_SIZES_NUMBER 7
44
6cd62ccf 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
45e14832 55gchar *ltt_eventtype_name(LttEventType *et)
6cd62ccf 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
45e14832 69gchar *ltt_eventtype_description(LttEventType *et)
6cd62ccf 70{
71 return et->description;
72}
73
963b5f2d 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
83LttFacility *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
33690006 94 * unsigned : the relative id
963b5f2d 95 ****************************************************************************/
96
33690006 97unsigned ltt_eventtype_relative_id(LttEventType *et)
963b5f2d 98{
33690006 99 return et->index;
963b5f2d 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
33690006 108 * unsigned : the id
963b5f2d 109 ****************************************************************************/
110
33690006 111unsigned ltt_eventtype_id(LttEventType *et)
963b5f2d 112{
33690006 113 return et->facility->base_id + et->index;
963b5f2d 114}
115
6cd62ccf 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
963b5f2d 122 * LttType * : the type of the event type
6cd62ccf 123 ****************************************************************************/
124
963b5f2d 125LttType *ltt_eventtype_type(LttEventType *et)
6cd62ccf 126{
57df94dd 127 if(unlikely(!et->root_field)) return NULL;
128 else return et->root_field->field_type;
6cd62ccf 129}
130
963b5f2d 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
140LttField *ltt_eventtype_field(LttEventType *et)
141{
142 return et->root_field;
143}
144
6cd62ccf 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
45e14832 154gchar *ltt_type_name(LttType *t)
6cd62ccf 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
963b5f2d 165 * LttTypeEnum : the type class of the type
6cd62ccf 166 ****************************************************************************/
167
963b5f2d 168LttTypeEnum ltt_type_class(LttType *t)
6cd62ccf 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
8d1e6362 183 * returns 0 if erroneous, and show a critical warning message.
6cd62ccf 184 ****************************************************************************/
185
963b5f2d 186unsigned ltt_type_size(LttTrace * trace, LttType *t)
6cd62ccf 187{
57df94dd 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];
62c72abf 212 }
6cd62ccf 213 }
214 }
57df94dd 215
216 return size;
6cd62ccf 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
963b5f2d 226 * LttType : the type of nested element of array or sequence
6cd62ccf 227 ****************************************************************************/
228
963b5f2d 229LttType *ltt_type_element_type(LttType *t)
6cd62ccf 230{
57df94dd 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;
6cd62ccf 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
963b5f2d 250unsigned ltt_type_element_number(LttType *t)
6cd62ccf 251{
57df94dd 252 unsigned ret = 0;
253
254 if(likely(t->type_class == LTT_ARRAY))
255 ret = t->element_number;
256
257 return ret;
6cd62ccf 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
963b5f2d 269unsigned ltt_type_member_number(LttType *t)
6cd62ccf 270{
57df94dd 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;
6cd62ccf 277}
278
279/*****************************************************************************
280 *Function name
59d7bdf3 281 * ltt_type_member_type : obtain the type of a data member in a structure
282 * or union.
6cd62ccf 283 *Input params
284 * t : a type
285 * i : index of the member
286 *Return value
963b5f2d 287 * LttType * : the type of structure member
6cd62ccf 288 ****************************************************************************/
289
45e14832 290LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name)
6cd62ccf 291{
57df94dd 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;
6cd62ccf 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
963b5f2d 320char *ltt_enum_string_get(LttType *t, unsigned i)
57df94dd 321{
45e14832 322 gchar *string = NULL;
57df94dd 323
324 if(likely(t->type_class == LTT_ENUM && i < t->element_number))
325 string = t->enum_strings[i];
326
327 return string;
6cd62ccf 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
963b5f2d 337 * LttField * : the field of the nested element
6cd62ccf 338 ****************************************************************************/
339
963b5f2d 340LttField *ltt_field_element(LttField *f)
6cd62ccf 341{
57df94dd 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];
6cd62ccf 347
57df94dd 348 return nest;
6cd62ccf 349}
350
351/*****************************************************************************
352 *Function name
59d7bdf3 353 * ltt_field_member : obtain the field of data members for structure
6cd62ccf 354 *Input params
355 * f : a field
356 * i : index of member field
357 *Return value
963b5f2d 358 * LttField * : the field of the nested element
6cd62ccf 359 ****************************************************************************/
360
963b5f2d 361LttField *ltt_field_member(LttField *f, unsigned i)
6cd62ccf 362{
57df94dd 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;
6cd62ccf 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
963b5f2d 384LttType *ltt_field_type(LttField *f)
6cd62ccf 385{
57df94dd 386 if(unlikely(!f))return NULL;
6cd62ccf 387 return f->field_type;
388}
389
a5dcde2f 390int ltt_field_size(LttField * f)
391{
57df94dd 392 if(unlikely(!f))return 0;
a5dcde2f 393 return f->field_size;
394}
This page took 0.048643 seconds and 4 git commands to generate.