new version of the reading API
[lttv.git] / ltt / branches / poly / ltt / type.c
CommitLineData
6cd62ccf 1#include <stdio.h>
2
fcdf0ec2 3#include <ltt/LTTTypes.h>
6cd62ccf 4#include "parser.h"
5#include <ltt/type.h>
6
7static unsigned intSizes[] = {
8 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
9 sizeof(short) };
10
11static unsigned floatSizes[] = {
12 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
13
14
15/*****************************************************************************
16 *Function name
17 * ltt_eventtype_name : get the name of the event type
18 *Input params
19 * et : an event type
20 *Return value
21 * char * : the name of the event type
22 ****************************************************************************/
23
963b5f2d 24char *ltt_eventtype_name(LttEventType *et)
6cd62ccf 25{
26 return et->name;
27}
28
29/*****************************************************************************
30 *Function name
31 * ltt_eventtype_description : get the description of the event type
32 *Input params
33 * et : an event type
34 *Return value
35 * char * : the description of the event type
36 ****************************************************************************/
37
963b5f2d 38char *ltt_eventtype_description(LttEventType *et)
6cd62ccf 39{
40 return et->description;
41}
42
963b5f2d 43/*****************************************************************************
44 *Function name
45 * ltt_eventtype_facility : get the facility which contains the event type
46 *Input params
47 * et : an event type
48 *Return value
49 * LttFacility * : the facility
50 ****************************************************************************/
51
52LttFacility *ltt_eventtype_facility(LttEventType *et)
53{
54 return et->facility;
55}
56
57/*****************************************************************************
58 *Function name
59 * ltt_eventtype_relative_id : get the relative id of the event type
60 *Input params
61 * et : an event type
62 *Return value
63 * unsigned * : the relative id
64 ****************************************************************************/
65
66unsigned *ltt_eventtype_relative_id(LttEventType *et)
67{
68 return (unsigned*)&et->index;
69}
70
71/*****************************************************************************
72 *Function name
73 * ltt_eventtype_id : get the id of the event type
74 *Input params
75 * et : an event type
76 *Return value
77 * unsigned * : the id
78 ****************************************************************************/
79
80unsigned *ltt_eventtype_id(LttEventType *et)
81{
82 unsigned *id = g_new(unsigned,1);
83 *id = et->facility->base_id + et->index;
84 return (unsigned*)id;
85}
86
6cd62ccf 87/*****************************************************************************
88 *Function name
89 * ltt_eventtype_type : get the type of the event type
90 *Input params
91 * et : an event type
92 *Return value
963b5f2d 93 * LttType * : the type of the event type
6cd62ccf 94 ****************************************************************************/
95
963b5f2d 96LttType *ltt_eventtype_type(LttEventType *et)
6cd62ccf 97{
98 return et->root_field->field_type;
99}
100
963b5f2d 101/*****************************************************************************
102 *Function name
103 * ltt_eventtype_field : get the root filed of the event type
104 *Input params
105 * et : an event type
106 *Return value
107 * LttField * : the root filed of the event type
108 ****************************************************************************/
109
110LttField *ltt_eventtype_field(LttEventType *et)
111{
112 return et->root_field;
113}
114
6cd62ccf 115/*****************************************************************************
116 *Function name
117 * ltt_type_name : get the name of the type
118 *Input params
119 * t : a type
120 *Return value
121 * char * : the name of the type
122 ****************************************************************************/
123
963b5f2d 124char *ltt_type_name(LttType *t)
6cd62ccf 125{
126 return t->element_name;
127}
128
129/*****************************************************************************
130 *Function name
131 * ltt_type_class : get the type class of the type
132 *Input params
133 * t : a type
134 *Return value
963b5f2d 135 * LttTypeEnum : the type class of the type
6cd62ccf 136 ****************************************************************************/
137
963b5f2d 138LttTypeEnum ltt_type_class(LttType *t)
6cd62ccf 139{
140 return t->type_class;
141}
142
143/*****************************************************************************
144 *Function name
145 * ltt_type_size : obtain the type size. The size is the number of bytes
146 * for primitive types (INT, UINT, FLOAT, ENUM), or the
147 * size for the unsigned integer length count for sequences
148 *Input params
149 * tf : trace file
150 * t : a type
151 *Return value
152 * unsigned : the type size
153 ****************************************************************************/
154
963b5f2d 155unsigned ltt_type_size(LttTrace * trace, LttType *t)
6cd62ccf 156{
157 if(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY ||
158 t->type_class==LTT_STRING) return 0;
159
160 if(t->type_class == LTT_FLOAT){
161 return floatSizes[t->size];
162 }else{
163 if(t->size < sizeof(intSizes)/sizeof(unsigned))
164 return intSizes[t->size];
165 else{
963b5f2d 166 LttArchSize size = trace->system_description->size;
6cd62ccf 167 if(size == LTT_LP32)
168 return sizeof(int16_t);
169 else if(size == LTT_ILP32 || size == LTT_LP64)
170 return sizeof(int32_t);
171 else if(size == LTT_ILP64)
172 return sizeof(int64_t);
173 }
174 }
175}
176
177/*****************************************************************************
178 *Function name
179 * ltt_type_element_type : obtain the type of nested elements for arrays
180 * and sequences
181 *Input params
182 * t : a type
183 *Return value
963b5f2d 184 * LttType : the type of nested element of array or sequence
6cd62ccf 185 ****************************************************************************/
186
963b5f2d 187LttType *ltt_type_element_type(LttType *t)
6cd62ccf 188{
189 if(t->type_class != LTT_ARRAY || t->type_class != LTT_SEQUENCE)
190 return NULL;
191 return t->element_type[0];
192}
193
194/*****************************************************************************
195 *Function name
196 * ltt_type_element_number : obtain the number of elements for arrays
197 *Input params
198 * t : a type
199 *Return value
200 * unsigned : the number of elements for arrays
201 ****************************************************************************/
202
963b5f2d 203unsigned ltt_type_element_number(LttType *t)
6cd62ccf 204{
205 if(t->type_class != LTT_ARRAY)
206 return 0;
207 return t->element_number;
208}
209
210/*****************************************************************************
211 *Function name
212 * ltt_type_member_number : obtain the number of data members for structure
213 *Input params
214 * t : a type
215 *Return value
216 * unsigned : the number of members for structure
217 ****************************************************************************/
218
963b5f2d 219unsigned ltt_type_member_number(LttType *t)
6cd62ccf 220{
963b5f2d 221 if(t->type_class != LTT_STRUCT || t->type_class != LTT_UNION)
6cd62ccf 222 return 0;
223 return t->element_number;
224}
225
226/*****************************************************************************
227 *Function name
228 * ltt_type_member_type : obtain the type of a data members in a structure
229 *Input params
230 * t : a type
231 * i : index of the member
232 *Return value
963b5f2d 233 * LttType * : the type of structure member
6cd62ccf 234 ****************************************************************************/
235
963b5f2d 236LttType *ltt_type_member_type(LttType *t, unsigned i)
6cd62ccf 237{
238 if(t->type_class != LTT_STRUCT) return NULL;
239 if(i > t->element_number || i == 0 ) return NULL;
240 return t->element_type[i-1];
241}
242
243/*****************************************************************************
244 *Function name
245 * ltt_enum_string_get : for enumerations, obtain the symbolic string
246 * associated with a value (0 to n - 1 for an
247 * enumeration of n elements)
248 *Input params
249 * t : a type
250 * i : index of the member
251 *Return value
252 * char * : symbolic string associated with a value
253 ****************************************************************************/
254
963b5f2d 255char *ltt_enum_string_get(LttType *t, unsigned i)
6cd62ccf 256{
257 if(t->type_class != LTT_ENUM) return NULL;
258 if(i > t->element_number || i == 0 ) return NULL;
259 return t->enum_strings[i-1];
260}
261
262/*****************************************************************************
263 *Function name
264 * ltt_field_element : obtain the field of nested elements for arrays and
265 * sequence
266 *Input params
267 * f : a field
268 *Return value
963b5f2d 269 * LttField * : the field of the nested element
6cd62ccf 270 ****************************************************************************/
271
963b5f2d 272LttField *ltt_field_element(LttField *f)
6cd62ccf 273{
274 if(f->field_type->type_class != LTT_ARRAY ||
275 f->field_type->type_class != LTT_SEQUENCE)
276 return NULL;
277
278 return f->child[0];
279}
280
281/*****************************************************************************
282 *Function name
283 * ltt_field_member : obtain the filed of data members for structure
284 *Input params
285 * f : a field
286 * i : index of member field
287 *Return value
963b5f2d 288 * LttField * : the field of the nested element
6cd62ccf 289 ****************************************************************************/
290
963b5f2d 291LttField *ltt_field_member(LttField *f, unsigned i)
6cd62ccf 292{
293 if(f->field_type->type_class != LTT_STRUCT) return NULL;
294 if(i==0 || i>f->field_type->element_number) return NULL;
295 return f->child[i-1];
296}
297
298/*****************************************************************************
299 *Function name
300 * ltt_field_type : obtain the type of the field
301 *Input params
302 * f : a field
303 *Return value
304 * ltt_tyoe * : the type of field
305 ****************************************************************************/
306
963b5f2d 307LttType *ltt_field_type(LttField *f)
6cd62ccf 308{
309 return f->field_type;
310}
311
This page took 0.034624 seconds and 4 git commands to generate.