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