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 |
63 | * unsigned * : the relative id |
64 | ****************************************************************************/ |
65 | |
66 | unsigned *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 | |
80 | unsigned *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 |
96 | LttType *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 | |
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 | |
963b5f2d |
242 | LttType *ltt_type_member_type(LttType *t, unsigned i) |
6cd62ccf |
243 | { |
244 | if(t->type_class != LTT_STRUCT) return NULL; |
89d4760c |
245 | if(i >= t->element_number || i < 0 ) return NULL; |
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 | { |
315 | return f->field_type; |
316 | } |
317 | |