| 1 | #include <stdio.h> |
| 2 | |
| 3 | #include <ltt/LTTTypes.h> |
| 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 | |
| 24 | char *ltt_eventtype_name(ltt_eventtype *et) |
| 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 | |
| 38 | char *ltt_eventtype_description(ltt_eventtype *et) |
| 39 | { |
| 40 | return et->description; |
| 41 | } |
| 42 | |
| 43 | /***************************************************************************** |
| 44 | *Function name |
| 45 | * ltt_eventtype_type : get the type of the event type |
| 46 | *Input params |
| 47 | * et : an event type |
| 48 | *Return value |
| 49 | * ltt_type * : the type of the event type |
| 50 | ****************************************************************************/ |
| 51 | |
| 52 | ltt_type *ltt_eventtype_type(ltt_eventtype *et) |
| 53 | { |
| 54 | return et->root_field->field_type; |
| 55 | } |
| 56 | |
| 57 | /***************************************************************************** |
| 58 | *Function name |
| 59 | * ltt_type_name : get the name of the type |
| 60 | *Input params |
| 61 | * t : a type |
| 62 | *Return value |
| 63 | * char * : the name of the type |
| 64 | ****************************************************************************/ |
| 65 | |
| 66 | char *ltt_type_name(ltt_type *t) |
| 67 | { |
| 68 | return t->element_name; |
| 69 | } |
| 70 | |
| 71 | /***************************************************************************** |
| 72 | *Function name |
| 73 | * ltt_type_class : get the type class of the type |
| 74 | *Input params |
| 75 | * t : a type |
| 76 | *Return value |
| 77 | * ltt_type_enum : the type class of the type |
| 78 | ****************************************************************************/ |
| 79 | |
| 80 | ltt_type_enum ltt_type_class(ltt_type *t) |
| 81 | { |
| 82 | return t->type_class; |
| 83 | } |
| 84 | |
| 85 | /***************************************************************************** |
| 86 | *Function name |
| 87 | * ltt_type_size : obtain the type size. The size is the number of bytes |
| 88 | * for primitive types (INT, UINT, FLOAT, ENUM), or the |
| 89 | * size for the unsigned integer length count for sequences |
| 90 | *Input params |
| 91 | * tf : trace file |
| 92 | * t : a type |
| 93 | *Return value |
| 94 | * unsigned : the type size |
| 95 | ****************************************************************************/ |
| 96 | |
| 97 | unsigned ltt_type_size(ltt_tracefile * tf, ltt_type *t) |
| 98 | { |
| 99 | if(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY || |
| 100 | t->type_class==LTT_STRING) return 0; |
| 101 | |
| 102 | if(t->type_class == LTT_FLOAT){ |
| 103 | return floatSizes[t->size]; |
| 104 | }else{ |
| 105 | if(t->size < sizeof(intSizes)/sizeof(unsigned)) |
| 106 | return intSizes[t->size]; |
| 107 | else{ |
| 108 | ltt_arch_size size = tf->trace_header->arch_size; |
| 109 | if(size == LTT_LP32) |
| 110 | return sizeof(int16_t); |
| 111 | else if(size == LTT_ILP32 || size == LTT_LP64) |
| 112 | return sizeof(int32_t); |
| 113 | else if(size == LTT_ILP64) |
| 114 | return sizeof(int64_t); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /***************************************************************************** |
| 120 | *Function name |
| 121 | * ltt_type_element_type : obtain the type of nested elements for arrays |
| 122 | * and sequences |
| 123 | *Input params |
| 124 | * t : a type |
| 125 | *Return value |
| 126 | * ltt_type : the type of nested element of array or sequence |
| 127 | ****************************************************************************/ |
| 128 | |
| 129 | ltt_type *ltt_type_element_type(ltt_type *t) |
| 130 | { |
| 131 | if(t->type_class != LTT_ARRAY || t->type_class != LTT_SEQUENCE) |
| 132 | return NULL; |
| 133 | return t->element_type[0]; |
| 134 | } |
| 135 | |
| 136 | /***************************************************************************** |
| 137 | *Function name |
| 138 | * ltt_type_element_number : obtain the number of elements for arrays |
| 139 | *Input params |
| 140 | * t : a type |
| 141 | *Return value |
| 142 | * unsigned : the number of elements for arrays |
| 143 | ****************************************************************************/ |
| 144 | |
| 145 | unsigned ltt_type_element_number(ltt_type *t) |
| 146 | { |
| 147 | if(t->type_class != LTT_ARRAY) |
| 148 | return 0; |
| 149 | return t->element_number; |
| 150 | } |
| 151 | |
| 152 | /***************************************************************************** |
| 153 | *Function name |
| 154 | * ltt_type_member_number : obtain the number of data members for structure |
| 155 | *Input params |
| 156 | * t : a type |
| 157 | *Return value |
| 158 | * unsigned : the number of members for structure |
| 159 | ****************************************************************************/ |
| 160 | |
| 161 | unsigned ltt_type_member_number(ltt_type *t) |
| 162 | { |
| 163 | if(t->type_class != LTT_STRUCT) |
| 164 | return 0; |
| 165 | return t->element_number; |
| 166 | } |
| 167 | |
| 168 | /***************************************************************************** |
| 169 | *Function name |
| 170 | * ltt_type_member_type : obtain the type of a data members in a structure |
| 171 | *Input params |
| 172 | * t : a type |
| 173 | * i : index of the member |
| 174 | *Return value |
| 175 | * ltt_type * : the type of structure member |
| 176 | ****************************************************************************/ |
| 177 | |
| 178 | ltt_type *ltt_type_member_type(ltt_type *t, unsigned i) |
| 179 | { |
| 180 | if(t->type_class != LTT_STRUCT) return NULL; |
| 181 | if(i > t->element_number || i == 0 ) return NULL; |
| 182 | return t->element_type[i-1]; |
| 183 | } |
| 184 | |
| 185 | /***************************************************************************** |
| 186 | *Function name |
| 187 | * ltt_enum_string_get : for enumerations, obtain the symbolic string |
| 188 | * associated with a value (0 to n - 1 for an |
| 189 | * enumeration of n elements) |
| 190 | *Input params |
| 191 | * t : a type |
| 192 | * i : index of the member |
| 193 | *Return value |
| 194 | * char * : symbolic string associated with a value |
| 195 | ****************************************************************************/ |
| 196 | |
| 197 | char *ltt_enum_string_get(ltt_type *t, unsigned i) |
| 198 | { |
| 199 | if(t->type_class != LTT_ENUM) return NULL; |
| 200 | if(i > t->element_number || i == 0 ) return NULL; |
| 201 | return t->enum_strings[i-1]; |
| 202 | } |
| 203 | |
| 204 | /***************************************************************************** |
| 205 | *Function name |
| 206 | * ltt_field_element : obtain the field of nested elements for arrays and |
| 207 | * sequence |
| 208 | *Input params |
| 209 | * f : a field |
| 210 | *Return value |
| 211 | * ltt_field * : the field of the nested element |
| 212 | ****************************************************************************/ |
| 213 | |
| 214 | ltt_field *ltt_field_element(ltt_field *f) |
| 215 | { |
| 216 | if(f->field_type->type_class != LTT_ARRAY || |
| 217 | f->field_type->type_class != LTT_SEQUENCE) |
| 218 | return NULL; |
| 219 | |
| 220 | return f->child[0]; |
| 221 | } |
| 222 | |
| 223 | /***************************************************************************** |
| 224 | *Function name |
| 225 | * ltt_field_member : obtain the filed of data members for structure |
| 226 | *Input params |
| 227 | * f : a field |
| 228 | * i : index of member field |
| 229 | *Return value |
| 230 | * ltt_field * : the field of the nested element |
| 231 | ****************************************************************************/ |
| 232 | |
| 233 | ltt_field *ltt_field_member(ltt_field *f, unsigned i) |
| 234 | { |
| 235 | if(f->field_type->type_class != LTT_STRUCT) return NULL; |
| 236 | if(i==0 || i>f->field_type->element_number) return NULL; |
| 237 | return f->child[i-1]; |
| 238 | } |
| 239 | |
| 240 | /***************************************************************************** |
| 241 | *Function name |
| 242 | * ltt_field_type : obtain the type of the field |
| 243 | *Input params |
| 244 | * f : a field |
| 245 | *Return value |
| 246 | * ltt_tyoe * : the type of field |
| 247 | ****************************************************************************/ |
| 248 | |
| 249 | ltt_type *ltt_field_type(ltt_field *f) |
| 250 | { |
| 251 | return f->field_type; |
| 252 | } |
| 253 | |