6cd62ccf |
1 | #include <stdio.h> |
2 | |
6cd62ccf |
3 | #include "parser.h" |
a5dcde2f |
4 | #include <ltt/ltt.h> |
5 | #include "ltt-private.h" |
6cd62ccf |
6 | #include <ltt/type.h> |
7 | |
8 | static unsigned intSizes[] = { |
9 | sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t), |
10 | sizeof(short) }; |
11 | |
12 | static unsigned floatSizes[] = { |
13 | 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) }; |
14 | |
15 | |
16 | /***************************************************************************** |
17 | *Function name |
18 | * ltt_eventtype_name : get the name of the event type |
19 | *Input params |
20 | * et : an event type |
21 | *Return value |
22 | * char * : the name of the event type |
23 | ****************************************************************************/ |
24 | |
963b5f2d |
25 | char *ltt_eventtype_name(LttEventType *et) |
6cd62ccf |
26 | { |
27 | return et->name; |
28 | } |
29 | |
30 | /***************************************************************************** |
31 | *Function name |
32 | * ltt_eventtype_description : get the description of the event type |
33 | *Input params |
34 | * et : an event type |
35 | *Return value |
36 | * char * : the description of the event type |
37 | ****************************************************************************/ |
38 | |
963b5f2d |
39 | char *ltt_eventtype_description(LttEventType *et) |
6cd62ccf |
40 | { |
41 | return et->description; |
42 | } |
43 | |
963b5f2d |
44 | /***************************************************************************** |
45 | *Function name |
46 | * ltt_eventtype_facility : get the facility which contains the event type |
47 | *Input params |
48 | * et : an event type |
49 | *Return value |
50 | * LttFacility * : the facility |
51 | ****************************************************************************/ |
52 | |
53 | LttFacility *ltt_eventtype_facility(LttEventType *et) |
54 | { |
55 | return et->facility; |
56 | } |
57 | |
58 | /***************************************************************************** |
59 | *Function name |
60 | * ltt_eventtype_relative_id : get the relative id of the event type |
61 | *Input params |
62 | * et : an event type |
63 | *Return value |
33690006 |
64 | * unsigned : the relative id |
963b5f2d |
65 | ****************************************************************************/ |
66 | |
33690006 |
67 | unsigned ltt_eventtype_relative_id(LttEventType *et) |
963b5f2d |
68 | { |
33690006 |
69 | return et->index; |
963b5f2d |
70 | } |
71 | |
72 | /***************************************************************************** |
73 | *Function name |
74 | * ltt_eventtype_id : get the id of the event type |
75 | *Input params |
76 | * et : an event type |
77 | *Return value |
33690006 |
78 | * unsigned : the id |
963b5f2d |
79 | ****************************************************************************/ |
80 | |
33690006 |
81 | unsigned ltt_eventtype_id(LttEventType *et) |
963b5f2d |
82 | { |
33690006 |
83 | return et->facility->base_id + et->index; |
963b5f2d |
84 | } |
85 | |
6cd62ccf |
86 | /***************************************************************************** |
87 | *Function name |
88 | * ltt_eventtype_type : get the type of the event type |
89 | *Input params |
90 | * et : an event type |
91 | *Return value |
963b5f2d |
92 | * LttType * : the type of the event type |
6cd62ccf |
93 | ****************************************************************************/ |
94 | |
963b5f2d |
95 | LttType *ltt_eventtype_type(LttEventType *et) |
6cd62ccf |
96 | { |
a2331fa0 |
97 | if(!et->root_field) return NULL; |
6cd62ccf |
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 | |
110 | LttField *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 |
124 | char *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 |
138 | LttTypeEnum 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 |
155 | unsigned 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; |
62c72abf |
167 | if(size == LTT_LP32){ |
168 | if(t->size == 5)return sizeof(int16_t); |
169 | else return sizeof(int32_t); |
170 | } |
171 | else if(size == LTT_ILP32 || size == LTT_LP64){ |
172 | if(t->size == 5)return sizeof(int32_t); |
173 | else{ |
174 | if(size == LTT_ILP32) return sizeof(int32_t); |
175 | else return sizeof(int64_t); |
176 | } |
177 | } |
178 | else if(size == LTT_ILP64)return sizeof(int64_t); |
6cd62ccf |
179 | } |
180 | } |
181 | } |
182 | |
183 | /***************************************************************************** |
184 | *Function name |
185 | * ltt_type_element_type : obtain the type of nested elements for arrays |
186 | * and sequences |
187 | *Input params |
188 | * t : a type |
189 | *Return value |
963b5f2d |
190 | * LttType : the type of nested element of array or sequence |
6cd62ccf |
191 | ****************************************************************************/ |
192 | |
963b5f2d |
193 | LttType *ltt_type_element_type(LttType *t) |
6cd62ccf |
194 | { |
c687f6c8 |
195 | if(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE) |
6cd62ccf |
196 | return NULL; |
197 | return t->element_type[0]; |
198 | } |
199 | |
200 | /***************************************************************************** |
201 | *Function name |
202 | * ltt_type_element_number : obtain the number of elements for arrays |
203 | *Input params |
204 | * t : a type |
205 | *Return value |
206 | * unsigned : the number of elements for arrays |
207 | ****************************************************************************/ |
208 | |
963b5f2d |
209 | unsigned ltt_type_element_number(LttType *t) |
6cd62ccf |
210 | { |
211 | if(t->type_class != LTT_ARRAY) |
212 | return 0; |
213 | return t->element_number; |
214 | } |
215 | |
216 | /***************************************************************************** |
217 | *Function name |
218 | * ltt_type_member_number : obtain the number of data members for structure |
219 | *Input params |
220 | * t : a type |
221 | *Return value |
222 | * unsigned : the number of members for structure |
223 | ****************************************************************************/ |
224 | |
963b5f2d |
225 | unsigned ltt_type_member_number(LttType *t) |
6cd62ccf |
226 | { |
c687f6c8 |
227 | if(t->type_class != LTT_STRUCT && t->type_class != LTT_UNION) |
6cd62ccf |
228 | return 0; |
229 | return t->element_number; |
230 | } |
231 | |
232 | /***************************************************************************** |
233 | *Function name |
234 | * ltt_type_member_type : obtain the type of a data members in a structure |
235 | *Input params |
236 | * t : a type |
237 | * i : index of the member |
238 | *Return value |
963b5f2d |
239 | * LttType * : the type of structure member |
6cd62ccf |
240 | ****************************************************************************/ |
241 | |
02007847 |
242 | LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) |
6cd62ccf |
243 | { |
02007847 |
244 | if(t->type_class != LTT_STRUCT){*name == NULL; return NULL;} |
245 | if(i >= t->element_number || i < 0 ){*name = NULL; return NULL;} |
fe974fde |
246 | *name = t->element_type[i]->element_name; |
89d4760c |
247 | return t->element_type[i]; |
6cd62ccf |
248 | } |
249 | |
250 | /***************************************************************************** |
251 | *Function name |
252 | * ltt_enum_string_get : for enumerations, obtain the symbolic string |
253 | * associated with a value (0 to n - 1 for an |
254 | * enumeration of n elements) |
255 | *Input params |
256 | * t : a type |
257 | * i : index of the member |
258 | *Return value |
259 | * char * : symbolic string associated with a value |
260 | ****************************************************************************/ |
261 | |
963b5f2d |
262 | char *ltt_enum_string_get(LttType *t, unsigned i) |
6cd62ccf |
263 | { |
264 | if(t->type_class != LTT_ENUM) return NULL; |
89d4760c |
265 | if(i >= t->element_number || i < 0 ) return NULL; |
266 | return t->enum_strings[i]; |
6cd62ccf |
267 | } |
268 | |
269 | /***************************************************************************** |
270 | *Function name |
271 | * ltt_field_element : obtain the field of nested elements for arrays and |
272 | * sequence |
273 | *Input params |
274 | * f : a field |
275 | *Return value |
963b5f2d |
276 | * LttField * : the field of the nested element |
6cd62ccf |
277 | ****************************************************************************/ |
278 | |
963b5f2d |
279 | LttField *ltt_field_element(LttField *f) |
6cd62ccf |
280 | { |
c687f6c8 |
281 | if(f->field_type->type_class != LTT_ARRAY && |
6cd62ccf |
282 | f->field_type->type_class != LTT_SEQUENCE) |
283 | return NULL; |
284 | |
285 | return f->child[0]; |
286 | } |
287 | |
288 | /***************************************************************************** |
289 | *Function name |
290 | * ltt_field_member : obtain the filed of data members for structure |
291 | *Input params |
292 | * f : a field |
293 | * i : index of member field |
294 | *Return value |
963b5f2d |
295 | * LttField * : the field of the nested element |
6cd62ccf |
296 | ****************************************************************************/ |
297 | |
963b5f2d |
298 | LttField *ltt_field_member(LttField *f, unsigned i) |
6cd62ccf |
299 | { |
300 | if(f->field_type->type_class != LTT_STRUCT) return NULL; |
89d4760c |
301 | if(i < 0 || i >= f->field_type->element_number) return NULL; |
302 | return f->child[i]; |
6cd62ccf |
303 | } |
304 | |
305 | /***************************************************************************** |
306 | *Function name |
307 | * ltt_field_type : obtain the type of the field |
308 | *Input params |
309 | * f : a field |
310 | *Return value |
311 | * ltt_tyoe * : the type of field |
312 | ****************************************************************************/ |
313 | |
963b5f2d |
314 | LttType *ltt_field_type(LttField *f) |
6cd62ccf |
315 | { |
a2331fa0 |
316 | if(!f)return NULL; |
6cd62ccf |
317 | return f->field_type; |
318 | } |
319 | |
a5dcde2f |
320 | int ltt_field_size(LttField * f) |
321 | { |
322 | if(!f)return 0; |
323 | return f->field_size; |
324 | } |