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