| 1 | #include <stdio.h> |
| 2 | |
| 3 | #include "parser.h" |
| 4 | #include <ltt/ltt.h> |
| 5 | #include "ltt-private.h" |
| 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 | |
| 25 | char *ltt_eventtype_name(LttEventType *et) |
| 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 | |
| 39 | char *ltt_eventtype_description(LttEventType *et) |
| 40 | { |
| 41 | return et->description; |
| 42 | } |
| 43 | |
| 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 |
| 64 | * unsigned : the relative id |
| 65 | ****************************************************************************/ |
| 66 | |
| 67 | unsigned ltt_eventtype_relative_id(LttEventType *et) |
| 68 | { |
| 69 | return et->index; |
| 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 |
| 78 | * unsigned : the id |
| 79 | ****************************************************************************/ |
| 80 | |
| 81 | unsigned ltt_eventtype_id(LttEventType *et) |
| 82 | { |
| 83 | return et->facility->base_id + et->index; |
| 84 | } |
| 85 | |
| 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 |
| 92 | * LttType * : the type of the event type |
| 93 | ****************************************************************************/ |
| 94 | |
| 95 | LttType *ltt_eventtype_type(LttEventType *et) |
| 96 | { |
| 97 | if(!et->root_field) return NULL; |
| 98 | return et->root_field->field_type; |
| 99 | } |
| 100 | |
| 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 | |
| 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 | |
| 124 | char *ltt_type_name(LttType *t) |
| 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 |
| 135 | * LttTypeEnum : the type class of the type |
| 136 | ****************************************************************************/ |
| 137 | |
| 138 | LttTypeEnum ltt_type_class(LttType *t) |
| 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 | |
| 155 | unsigned ltt_type_size(LttTrace * trace, LttType *t) |
| 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{ |
| 166 | LttArchSize size = trace->system_description->size; |
| 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); |
| 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 |
| 190 | * LttType : the type of nested element of array or sequence |
| 191 | ****************************************************************************/ |
| 192 | |
| 193 | LttType *ltt_type_element_type(LttType *t) |
| 194 | { |
| 195 | if(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE) |
| 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 | |
| 209 | unsigned ltt_type_element_number(LttType *t) |
| 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 | |
| 225 | unsigned ltt_type_member_number(LttType *t) |
| 226 | { |
| 227 | if(t->type_class != LTT_STRUCT && t->type_class != LTT_UNION) |
| 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 |
| 239 | * LttType * : the type of structure member |
| 240 | ****************************************************************************/ |
| 241 | |
| 242 | LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) |
| 243 | { |
| 244 | if(t->type_class != LTT_STRUCT){*name == NULL; return NULL;} |
| 245 | if(i >= t->element_number || i < 0 ){*name = NULL; return NULL;} |
| 246 | *name = t->element_type[i]->element_name; |
| 247 | return t->element_type[i]; |
| 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 | |
| 262 | char *ltt_enum_string_get(LttType *t, unsigned i) |
| 263 | { |
| 264 | if(t->type_class != LTT_ENUM) return NULL; |
| 265 | if(i >= t->element_number || i < 0 ) return NULL; |
| 266 | return t->enum_strings[i]; |
| 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 |
| 276 | * LttField * : the field of the nested element |
| 277 | ****************************************************************************/ |
| 278 | |
| 279 | LttField *ltt_field_element(LttField *f) |
| 280 | { |
| 281 | if(f->field_type->type_class != LTT_ARRAY && |
| 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 |
| 295 | * LttField * : the field of the nested element |
| 296 | ****************************************************************************/ |
| 297 | |
| 298 | LttField *ltt_field_member(LttField *f, unsigned i) |
| 299 | { |
| 300 | if(f->field_type->type_class != LTT_STRUCT) return NULL; |
| 301 | if(i < 0 || i >= f->field_type->element_number) return NULL; |
| 302 | return f->child[i]; |
| 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 | |
| 314 | LttType *ltt_field_type(LttField *f) |
| 315 | { |
| 316 | if(!f)return NULL; |
| 317 | return f->field_type; |
| 318 | } |
| 319 | |
| 320 | int ltt_field_size(LttField * f) |
| 321 | { |
| 322 | if(!f)return 0; |
| 323 | return f->field_size; |
| 324 | } |