Commit | Line | Data |
---|---|---|
7b33a0e0 PP |
1 | /* |
2 | * Copyright 2018 - Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | */ | |
14 | ||
71c5da58 | 15 | #include <babeltrace2/babeltrace.h> |
85e7137b | 16 | #include "common/macros.h" |
57952005 | 17 | #include "common/assert.h" |
7b33a0e0 | 18 | #include <glib.h> |
969c1d8a | 19 | #include <stdbool.h> |
7b33a0e0 PP |
20 | #include <stdint.h> |
21 | #include <string.h> | |
22 | #include <inttypes.h> | |
23 | ||
24 | #include "ctf-meta-visitors.h" | |
25 | ||
0476f6f7 | 26 | struct ctx { |
16699f85 | 27 | bt_self_component *self_comp; |
0476f6f7 PP |
28 | bt_trace_class *ir_tc; |
29 | bt_stream_class *ir_sc; | |
30 | struct ctf_trace_class *tc; | |
31 | struct ctf_stream_class *sc; | |
32 | struct ctf_event_class *ec; | |
33 | enum ctf_scope scope; | |
34 | }; | |
35 | ||
7b33a0e0 | 36 | static inline |
0476f6f7 PP |
37 | bt_field_class *ctf_field_class_to_ir(struct ctx *ctx, |
38 | struct ctf_field_class *fc); | |
7b33a0e0 PP |
39 | |
40 | static inline | |
939190b3 | 41 | void ctf_field_class_int_set_props(struct ctf_field_class_int *fc, |
8eee8ea2 | 42 | bt_field_class *ir_fc) |
7b33a0e0 | 43 | { |
78cf9df6 | 44 | bt_field_class_integer_set_field_value_range(ir_fc, |
9e550e5f | 45 | fc->base.size); |
78cf9df6 | 46 | bt_field_class_integer_set_preferred_display_base(ir_fc, |
939190b3 | 47 | fc->disp_base); |
7b33a0e0 PP |
48 | } |
49 | ||
50 | static inline | |
0476f6f7 | 51 | bt_field_class *ctf_field_class_int_to_ir(struct ctx *ctx, |
9e550e5f | 52 | struct ctf_field_class_int *fc) |
7b33a0e0 | 53 | { |
8eee8ea2 | 54 | bt_field_class *ir_fc; |
7b33a0e0 | 55 | |
939190b3 | 56 | if (fc->is_signed) { |
60bbfc7c | 57 | ir_fc = bt_field_class_integer_signed_create(ctx->ir_tc); |
7b33a0e0 | 58 | } else { |
60bbfc7c | 59 | ir_fc = bt_field_class_integer_unsigned_create(ctx->ir_tc); |
7b33a0e0 PP |
60 | } |
61 | ||
939190b3 PP |
62 | BT_ASSERT(ir_fc); |
63 | ctf_field_class_int_set_props(fc, ir_fc); | |
64 | return ir_fc; | |
7b33a0e0 PP |
65 | } |
66 | ||
67 | static inline | |
0476f6f7 | 68 | bt_field_class *ctf_field_class_enum_to_ir(struct ctx *ctx, |
9e550e5f | 69 | struct ctf_field_class_enum *fc) |
7b33a0e0 PP |
70 | { |
71 | int ret; | |
8eee8ea2 | 72 | bt_field_class *ir_fc; |
7b33a0e0 PP |
73 | uint64_t i; |
74 | ||
939190b3 | 75 | if (fc->base.is_signed) { |
60bbfc7c | 76 | ir_fc = bt_field_class_enumeration_signed_create(ctx->ir_tc); |
7b33a0e0 | 77 | } else { |
60bbfc7c | 78 | ir_fc = bt_field_class_enumeration_unsigned_create(ctx->ir_tc); |
7b33a0e0 PP |
79 | } |
80 | ||
939190b3 PP |
81 | BT_ASSERT(ir_fc); |
82 | ctf_field_class_int_set_props((void *) fc, ir_fc); | |
7b33a0e0 | 83 | |
939190b3 PP |
84 | for (i = 0; i < fc->mappings->len; i++) { |
85 | struct ctf_field_class_enum_mapping *mapping = | |
86 | ctf_field_class_enum_borrow_mapping_by_index(fc, i); | |
02b61fe0 PP |
87 | void *range_set; |
88 | uint64_t range_i; | |
7b33a0e0 | 89 | |
939190b3 | 90 | if (fc->base.is_signed) { |
02b61fe0 | 91 | range_set = bt_integer_range_set_signed_create(); |
7b33a0e0 | 92 | } else { |
02b61fe0 PP |
93 | range_set = bt_integer_range_set_unsigned_create(); |
94 | } | |
95 | ||
96 | BT_ASSERT(range_set); | |
97 | ||
98 | for (range_i = 0; range_i < mapping->ranges->len; range_i++) { | |
99 | struct ctf_range *range = | |
100 | ctf_field_class_enum_mapping_borrow_range_by_index( | |
101 | mapping, range_i); | |
102 | ||
103 | if (fc->base.is_signed) { | |
104 | ret = bt_integer_range_set_signed_add_range( | |
105 | range_set, range->lower.i, | |
106 | range->upper.i); | |
107 | } else { | |
108 | ret = bt_integer_range_set_unsigned_add_range( | |
109 | range_set, range->lower.u, | |
110 | range->upper.u); | |
111 | } | |
112 | ||
113 | BT_ASSERT(ret == 0); | |
114 | } | |
115 | ||
116 | if (fc->base.is_signed) { | |
60bbfc7c | 117 | ret = bt_field_class_enumeration_signed_add_mapping( |
02b61fe0 | 118 | ir_fc, mapping->label->str, range_set); |
dc667962 | 119 | BT_INTEGER_RANGE_SET_SIGNED_PUT_REF_AND_RESET(range_set); |
02b61fe0 | 120 | } else { |
60bbfc7c | 121 | ret = bt_field_class_enumeration_unsigned_add_mapping( |
02b61fe0 | 122 | ir_fc, mapping->label->str, range_set); |
dc667962 | 123 | BT_INTEGER_RANGE_SET_UNSIGNED_PUT_REF_AND_RESET(range_set); |
7b33a0e0 PP |
124 | } |
125 | ||
126 | BT_ASSERT(ret == 0); | |
127 | } | |
128 | ||
939190b3 | 129 | return ir_fc; |
7b33a0e0 PP |
130 | } |
131 | ||
132 | static inline | |
0476f6f7 | 133 | bt_field_class *ctf_field_class_float_to_ir(struct ctx *ctx, |
939190b3 | 134 | struct ctf_field_class_float *fc) |
7b33a0e0 | 135 | { |
8eee8ea2 | 136 | bt_field_class *ir_fc; |
7b33a0e0 | 137 | |
939190b3 | 138 | if (fc->base.size == 32) { |
76276a81 FD |
139 | ir_fc = bt_field_class_real_single_precision_create(ctx->ir_tc); |
140 | } else { | |
141 | ir_fc = bt_field_class_real_double_precision_create(ctx->ir_tc); | |
7b33a0e0 | 142 | } |
76276a81 | 143 | BT_ASSERT(ir_fc); |
7b33a0e0 | 144 | |
939190b3 | 145 | return ir_fc; |
7b33a0e0 PP |
146 | } |
147 | ||
148 | static inline | |
0476f6f7 | 149 | bt_field_class *ctf_field_class_string_to_ir(struct ctx *ctx, |
939190b3 | 150 | struct ctf_field_class_string *fc) |
7b33a0e0 | 151 | { |
0476f6f7 | 152 | bt_field_class *ir_fc = bt_field_class_string_create(ctx->ir_tc); |
7b33a0e0 | 153 | |
939190b3 PP |
154 | BT_ASSERT(ir_fc); |
155 | return ir_fc; | |
7b33a0e0 PP |
156 | } |
157 | ||
158 | static inline | |
0476f6f7 PP |
159 | void translate_struct_field_class_members(struct ctx *ctx, |
160 | struct ctf_field_class_struct *fc, bt_field_class *ir_fc, | |
161 | bool with_header_prefix, | |
162 | struct ctf_field_class_struct *context_fc) | |
7b33a0e0 | 163 | { |
7b33a0e0 | 164 | uint64_t i; |
0476f6f7 | 165 | int ret; |
7b33a0e0 | 166 | |
939190b3 PP |
167 | for (i = 0; i < fc->members->len; i++) { |
168 | struct ctf_named_field_class *named_fc = | |
169 | ctf_field_class_struct_borrow_member_by_index(fc, i); | |
8eee8ea2 | 170 | bt_field_class *member_ir_fc; |
0476f6f7 | 171 | const char *name = named_fc->name->str; |
7b33a0e0 | 172 | |
939190b3 | 173 | if (!named_fc->fc->in_ir) { |
7b33a0e0 PP |
174 | continue; |
175 | } | |
176 | ||
0476f6f7 | 177 | member_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc); |
939190b3 | 178 | BT_ASSERT(member_ir_fc); |
0476f6f7 PP |
179 | ret = bt_field_class_structure_append_member(ir_fc, name, |
180 | member_ir_fc); | |
7b33a0e0 | 181 | BT_ASSERT(ret == 0); |
8c6884d9 | 182 | bt_field_class_put_ref(member_ir_fc); |
7b33a0e0 | 183 | } |
0476f6f7 | 184 | } |
7b33a0e0 | 185 | |
0476f6f7 PP |
186 | static inline |
187 | bt_field_class *ctf_field_class_struct_to_ir(struct ctx *ctx, | |
188 | struct ctf_field_class_struct *fc) | |
189 | { | |
190 | bt_field_class *ir_fc = bt_field_class_structure_create(ctx->ir_tc); | |
191 | ||
192 | BT_ASSERT(ir_fc); | |
193 | translate_struct_field_class_members(ctx, fc, ir_fc, false, NULL); | |
939190b3 | 194 | return ir_fc; |
7b33a0e0 PP |
195 | } |
196 | ||
197 | static inline | |
0476f6f7 PP |
198 | bt_field_class *borrow_ir_fc_from_field_path(struct ctx *ctx, |
199 | struct ctf_field_path *field_path) | |
7b33a0e0 | 200 | { |
8eee8ea2 | 201 | bt_field_class *ir_fc = NULL; |
939190b3 | 202 | struct ctf_field_class *fc = ctf_field_path_borrow_field_class( |
0476f6f7 | 203 | field_path, ctx->tc, ctx->sc, ctx->ec); |
7b33a0e0 | 204 | |
939190b3 | 205 | BT_ASSERT(fc); |
7b33a0e0 | 206 | |
939190b3 PP |
207 | if (fc->in_ir) { |
208 | ir_fc = fc->ir_fc; | |
7b33a0e0 PP |
209 | } |
210 | ||
939190b3 | 211 | return ir_fc; |
7b33a0e0 PP |
212 | } |
213 | ||
02b61fe0 PP |
214 | static inline |
215 | const void *find_ir_enum_field_class_mapping_by_label(const bt_field_class *fc, | |
216 | const char *label, bool is_signed) | |
217 | { | |
218 | const void *mapping = NULL; | |
219 | uint64_t i; | |
220 | ||
221 | for (i = 0; i < bt_field_class_enumeration_get_mapping_count(fc); i++) { | |
222 | const bt_field_class_enumeration_mapping *this_mapping; | |
223 | const void *spec_this_mapping; | |
224 | ||
225 | if (is_signed) { | |
226 | spec_this_mapping = | |
60bbfc7c | 227 | bt_field_class_enumeration_signed_borrow_mapping_by_index_const( |
02b61fe0 PP |
228 | fc, i); |
229 | this_mapping = | |
60bbfc7c | 230 | bt_field_class_enumeration_signed_mapping_as_mapping_const( |
02b61fe0 PP |
231 | spec_this_mapping); |
232 | } else { | |
233 | spec_this_mapping = | |
60bbfc7c | 234 | bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( |
02b61fe0 PP |
235 | fc, i); |
236 | this_mapping = | |
60bbfc7c | 237 | bt_field_class_enumeration_unsigned_mapping_as_mapping_const( |
02b61fe0 PP |
238 | spec_this_mapping); |
239 | } | |
240 | ||
241 | BT_ASSERT(this_mapping); | |
242 | BT_ASSERT(spec_this_mapping); | |
243 | ||
244 | if (strcmp(bt_field_class_enumeration_mapping_get_label( | |
245 | this_mapping), label) == 0) { | |
246 | mapping = spec_this_mapping; | |
247 | goto end; | |
248 | } | |
249 | } | |
250 | ||
251 | end: | |
252 | return mapping; | |
253 | } | |
254 | ||
7b33a0e0 | 255 | static inline |
0476f6f7 PP |
256 | bt_field_class *ctf_field_class_variant_to_ir(struct ctx *ctx, |
257 | struct ctf_field_class_variant *fc) | |
7b33a0e0 PP |
258 | { |
259 | int ret; | |
02b61fe0 | 260 | bt_field_class *ir_fc; |
7b33a0e0 | 261 | uint64_t i; |
02b61fe0 | 262 | bt_field_class *ir_tag_fc = NULL; |
0476f6f7 PP |
263 | |
264 | if (fc->tag_path.root != CTF_SCOPE_PACKET_HEADER && | |
265 | fc->tag_path.root != CTF_SCOPE_EVENT_HEADER) { | |
02b61fe0 PP |
266 | ir_tag_fc = borrow_ir_fc_from_field_path(ctx, &fc->tag_path); |
267 | BT_ASSERT(ir_tag_fc); | |
0476f6f7 | 268 | } |
7b33a0e0 | 269 | |
02b61fe0 PP |
270 | ir_fc = bt_field_class_variant_create(ctx->ir_tc, ir_tag_fc); |
271 | BT_ASSERT(ir_fc); | |
272 | ||
939190b3 PP |
273 | for (i = 0; i < fc->options->len; i++) { |
274 | struct ctf_named_field_class *named_fc = | |
275 | ctf_field_class_variant_borrow_option_by_index(fc, i); | |
8eee8ea2 | 276 | bt_field_class *option_ir_fc; |
7b33a0e0 | 277 | |
939190b3 | 278 | BT_ASSERT(named_fc->fc->in_ir); |
0476f6f7 | 279 | option_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc); |
939190b3 | 280 | BT_ASSERT(option_ir_fc); |
02b61fe0 PP |
281 | |
282 | if (ir_tag_fc) { | |
283 | /* | |
284 | * At this point the trace IR selector | |
285 | * (enumeration) field class already exists if | |
286 | * the variant is tagged (`ir_tag_fc`). This one | |
287 | * already contains range sets for its mappings, | |
288 | * so we just reuse the same, finding them by | |
289 | * matching a variant field class's option's | |
290 | * _original_ name (with a leading underscore, | |
291 | * possibly) with a selector field class's | |
292 | * mapping name. | |
293 | */ | |
294 | if (fc->tag_fc->base.is_signed) { | |
60bbfc7c | 295 | const bt_field_class_enumeration_signed_mapping *mapping = |
02b61fe0 PP |
296 | find_ir_enum_field_class_mapping_by_label( |
297 | ir_tag_fc, | |
298 | named_fc->orig_name->str, true); | |
299 | const bt_integer_range_set_signed *range_set; | |
300 | ||
301 | BT_ASSERT(mapping); | |
302 | range_set = | |
60bbfc7c | 303 | bt_field_class_enumeration_signed_mapping_borrow_ranges_const( |
02b61fe0 PP |
304 | mapping); |
305 | BT_ASSERT(range_set); | |
8bc207af | 306 | ret = bt_field_class_variant_with_selector_field_integer_signed_append_option( |
02b61fe0 PP |
307 | ir_fc, named_fc->name->str, |
308 | option_ir_fc, range_set); | |
309 | } else { | |
60bbfc7c | 310 | const bt_field_class_enumeration_unsigned_mapping *mapping = |
02b61fe0 PP |
311 | find_ir_enum_field_class_mapping_by_label( |
312 | ir_tag_fc, | |
313 | named_fc->orig_name->str, | |
314 | false); | |
315 | const bt_integer_range_set_unsigned *range_set; | |
316 | ||
317 | BT_ASSERT(mapping); | |
318 | range_set = | |
60bbfc7c | 319 | bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( |
02b61fe0 PP |
320 | mapping); |
321 | BT_ASSERT(range_set); | |
8bc207af | 322 | ret = bt_field_class_variant_with_selector_field_integer_unsigned_append_option( |
02b61fe0 PP |
323 | ir_fc, named_fc->name->str, |
324 | option_ir_fc, range_set); | |
325 | } | |
326 | } else { | |
327 | ret = bt_field_class_variant_without_selector_append_option( | |
328 | ir_fc, named_fc->name->str, option_ir_fc); | |
329 | } | |
330 | ||
7b33a0e0 | 331 | BT_ASSERT(ret == 0); |
8c6884d9 | 332 | bt_field_class_put_ref(option_ir_fc); |
7b33a0e0 PP |
333 | } |
334 | ||
939190b3 | 335 | return ir_fc; |
7b33a0e0 PP |
336 | } |
337 | ||
338 | static inline | |
0476f6f7 PP |
339 | bt_field_class *ctf_field_class_array_to_ir(struct ctx *ctx, |
340 | struct ctf_field_class_array *fc) | |
7b33a0e0 | 341 | { |
8eee8ea2 PP |
342 | bt_field_class *ir_fc; |
343 | bt_field_class *elem_ir_fc; | |
7b33a0e0 | 344 | |
939190b3 | 345 | if (fc->base.is_text) { |
0476f6f7 | 346 | ir_fc = bt_field_class_string_create(ctx->ir_tc); |
939190b3 | 347 | BT_ASSERT(ir_fc); |
7b33a0e0 PP |
348 | goto end; |
349 | } | |
350 | ||
0476f6f7 | 351 | elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc); |
939190b3 | 352 | BT_ASSERT(elem_ir_fc); |
60bbfc7c | 353 | ir_fc = bt_field_class_array_static_create(ctx->ir_tc, elem_ir_fc, |
9e550e5f | 354 | fc->length); |
939190b3 | 355 | BT_ASSERT(ir_fc); |
8c6884d9 | 356 | bt_field_class_put_ref(elem_ir_fc); |
7b33a0e0 PP |
357 | |
358 | end: | |
939190b3 | 359 | return ir_fc; |
7b33a0e0 PP |
360 | } |
361 | ||
362 | static inline | |
0476f6f7 PP |
363 | bt_field_class *ctf_field_class_sequence_to_ir(struct ctx *ctx, |
364 | struct ctf_field_class_sequence *fc) | |
7b33a0e0 | 365 | { |
8eee8ea2 PP |
366 | bt_field_class *ir_fc; |
367 | bt_field_class *elem_ir_fc; | |
93d7d5d1 | 368 | bt_field_class *length_fc = NULL; |
7b33a0e0 | 369 | |
939190b3 | 370 | if (fc->base.is_text) { |
0476f6f7 | 371 | ir_fc = bt_field_class_string_create(ctx->ir_tc); |
939190b3 | 372 | BT_ASSERT(ir_fc); |
7b33a0e0 PP |
373 | goto end; |
374 | } | |
375 | ||
0476f6f7 | 376 | elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc); |
939190b3 | 377 | BT_ASSERT(elem_ir_fc); |
0476f6f7 PP |
378 | |
379 | if (fc->length_path.root != CTF_SCOPE_PACKET_HEADER && | |
380 | fc->length_path.root != CTF_SCOPE_EVENT_HEADER) { | |
93d7d5d1 PP |
381 | length_fc = borrow_ir_fc_from_field_path(ctx, &fc->length_path); |
382 | BT_ASSERT(length_fc); | |
0476f6f7 | 383 | } |
7b33a0e0 | 384 | |
60bbfc7c | 385 | ir_fc = bt_field_class_array_dynamic_create(ctx->ir_tc, elem_ir_fc, |
93d7d5d1 PP |
386 | length_fc); |
387 | BT_ASSERT(ir_fc); | |
388 | bt_field_class_put_ref(elem_ir_fc); | |
389 | BT_ASSERT(ir_fc); | |
390 | ||
7b33a0e0 | 391 | end: |
939190b3 | 392 | return ir_fc; |
7b33a0e0 PP |
393 | } |
394 | ||
395 | static inline | |
0476f6f7 PP |
396 | bt_field_class *ctf_field_class_to_ir(struct ctx *ctx, |
397 | struct ctf_field_class *fc) | |
7b33a0e0 | 398 | { |
8eee8ea2 | 399 | bt_field_class *ir_fc = NULL; |
7b33a0e0 | 400 | |
939190b3 PP |
401 | BT_ASSERT(fc); |
402 | BT_ASSERT(fc->in_ir); | |
7b33a0e0 | 403 | |
af0c18e3 PP |
404 | switch (fc->type) { |
405 | case CTF_FIELD_CLASS_TYPE_INT: | |
0476f6f7 | 406 | ir_fc = ctf_field_class_int_to_ir(ctx, (void *) fc); |
7b33a0e0 | 407 | break; |
af0c18e3 | 408 | case CTF_FIELD_CLASS_TYPE_ENUM: |
0476f6f7 | 409 | ir_fc = ctf_field_class_enum_to_ir(ctx, (void *) fc); |
7b33a0e0 | 410 | break; |
af0c18e3 | 411 | case CTF_FIELD_CLASS_TYPE_FLOAT: |
0476f6f7 | 412 | ir_fc = ctf_field_class_float_to_ir(ctx, (void *) fc); |
7b33a0e0 | 413 | break; |
af0c18e3 | 414 | case CTF_FIELD_CLASS_TYPE_STRING: |
0476f6f7 | 415 | ir_fc = ctf_field_class_string_to_ir(ctx, (void *) fc); |
7b33a0e0 | 416 | break; |
af0c18e3 | 417 | case CTF_FIELD_CLASS_TYPE_STRUCT: |
0476f6f7 | 418 | ir_fc = ctf_field_class_struct_to_ir(ctx, (void *) fc); |
7b33a0e0 | 419 | break; |
af0c18e3 | 420 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
0476f6f7 | 421 | ir_fc = ctf_field_class_array_to_ir(ctx, (void *) fc); |
7b33a0e0 | 422 | break; |
af0c18e3 | 423 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: |
0476f6f7 | 424 | ir_fc = ctf_field_class_sequence_to_ir(ctx, (void *) fc); |
7b33a0e0 | 425 | break; |
af0c18e3 | 426 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
0476f6f7 | 427 | ir_fc = ctf_field_class_variant_to_ir(ctx, (void *) fc); |
7b33a0e0 PP |
428 | break; |
429 | default: | |
430 | abort(); | |
431 | } | |
432 | ||
939190b3 PP |
433 | fc->ir_fc = ir_fc; |
434 | return ir_fc; | |
7b33a0e0 PP |
435 | } |
436 | ||
437 | static inline | |
939190b3 PP |
438 | bool ctf_field_class_struct_has_immediate_member_in_ir( |
439 | struct ctf_field_class_struct *fc) | |
7b33a0e0 PP |
440 | { |
441 | uint64_t i; | |
442 | bool has_immediate_member_in_ir = false; | |
443 | ||
496fac93 PP |
444 | /* |
445 | * If the structure field class has no members at all, then it | |
446 | * was an empty structure in the beginning, so leave it existing | |
447 | * and empty. | |
448 | */ | |
449 | if (fc->members->len == 0) { | |
450 | has_immediate_member_in_ir = true; | |
451 | goto end; | |
452 | } | |
453 | ||
939190b3 PP |
454 | for (i = 0; i < fc->members->len; i++) { |
455 | struct ctf_named_field_class *named_fc = | |
456 | ctf_field_class_struct_borrow_member_by_index(fc, i); | |
7b33a0e0 | 457 | |
939190b3 | 458 | if (named_fc->fc->in_ir) { |
7b33a0e0 PP |
459 | has_immediate_member_in_ir = true; |
460 | goto end; | |
461 | } | |
462 | } | |
463 | ||
464 | end: | |
465 | return has_immediate_member_in_ir; | |
466 | } | |
467 | ||
468 | static inline | |
0476f6f7 | 469 | bt_field_class *scope_ctf_field_class_to_ir(struct ctx *ctx) |
7b33a0e0 | 470 | { |
8eee8ea2 | 471 | bt_field_class *ir_fc = NULL; |
0476f6f7 | 472 | struct ctf_field_class *fc = NULL; |
7b33a0e0 | 473 | |
0476f6f7 PP |
474 | switch (ctx->scope) { |
475 | case CTF_SCOPE_PACKET_CONTEXT: | |
476 | fc = ctx->sc->packet_context_fc; | |
477 | break; | |
478 | case CTF_SCOPE_EVENT_COMMON_CONTEXT: | |
479 | fc = ctx->sc->event_common_context_fc; | |
480 | break; | |
481 | case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT: | |
482 | fc = ctx->ec->spec_context_fc; | |
483 | break; | |
484 | case CTF_SCOPE_EVENT_PAYLOAD: | |
485 | fc = ctx->ec->payload_fc; | |
486 | break; | |
487 | default: | |
488 | abort(); | |
7b33a0e0 PP |
489 | } |
490 | ||
0476f6f7 PP |
491 | if (fc && ctf_field_class_struct_has_immediate_member_in_ir( |
492 | (void *) fc)) { | |
493 | ir_fc = ctf_field_class_to_ir(ctx, fc); | |
7b33a0e0 PP |
494 | } |
495 | ||
939190b3 | 496 | return ir_fc; |
7b33a0e0 PP |
497 | } |
498 | ||
7b33a0e0 | 499 | static inline |
0476f6f7 | 500 | void ctf_event_class_to_ir(struct ctx *ctx) |
7b33a0e0 PP |
501 | { |
502 | int ret; | |
8eee8ea2 | 503 | bt_event_class *ir_ec = NULL; |
0476f6f7 | 504 | bt_field_class *ir_fc; |
7b33a0e0 | 505 | |
0476f6f7 PP |
506 | BT_ASSERT(ctx->ec); |
507 | ||
508 | if (ctx->ec->is_translated) { | |
78cf9df6 | 509 | ir_ec = bt_stream_class_borrow_event_class_by_id( |
0476f6f7 | 510 | ctx->ir_sc, ctx->ec->id); |
7b33a0e0 PP |
511 | BT_ASSERT(ir_ec); |
512 | goto end; | |
513 | } | |
514 | ||
0476f6f7 | 515 | ir_ec = bt_event_class_create_with_id(ctx->ir_sc, ctx->ec->id); |
7b33a0e0 | 516 | BT_ASSERT(ir_ec); |
8c6884d9 | 517 | bt_event_class_put_ref(ir_ec); |
0476f6f7 PP |
518 | ctx->scope = CTF_SCOPE_EVENT_SPECIFIC_CONTEXT; |
519 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
520 | if (ir_fc) { | |
521 | ret = bt_event_class_set_specific_context_field_class( | |
522 | ir_ec, ir_fc); | |
523 | BT_ASSERT(ret == 0); | |
524 | bt_field_class_put_ref(ir_fc); | |
7b33a0e0 PP |
525 | } |
526 | ||
0476f6f7 PP |
527 | ctx->scope = CTF_SCOPE_EVENT_PAYLOAD; |
528 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
529 | if (ir_fc) { | |
530 | ret = bt_event_class_set_payload_field_class(ir_ec, | |
531 | ir_fc); | |
532 | BT_ASSERT(ret == 0); | |
533 | bt_field_class_put_ref(ir_fc); | |
7b33a0e0 PP |
534 | } |
535 | ||
0476f6f7 PP |
536 | if (ctx->ec->name->len > 0) { |
537 | ret = bt_event_class_set_name(ir_ec, ctx->ec->name->str); | |
7b33a0e0 PP |
538 | BT_ASSERT(ret == 0); |
539 | } | |
540 | ||
0476f6f7 PP |
541 | if (ctx->ec->emf_uri->len > 0) { |
542 | ret = bt_event_class_set_emf_uri(ir_ec, ctx->ec->emf_uri->str); | |
7b33a0e0 PP |
543 | BT_ASSERT(ret == 0); |
544 | } | |
545 | ||
87f15877 | 546 | if (ctx->ec->is_log_level_set) { |
0476f6f7 | 547 | bt_event_class_set_log_level(ir_ec, ctx->ec->log_level); |
7b33a0e0 PP |
548 | } |
549 | ||
0476f6f7 PP |
550 | ctx->ec->is_translated = true; |
551 | ctx->ec->ir_ec = ir_ec; | |
7b33a0e0 PP |
552 | |
553 | end: | |
0476f6f7 | 554 | return; |
7b33a0e0 PP |
555 | } |
556 | ||
557 | ||
558 | static inline | |
0476f6f7 | 559 | void ctf_stream_class_to_ir(struct ctx *ctx) |
7b33a0e0 PP |
560 | { |
561 | int ret; | |
0476f6f7 | 562 | bt_field_class *ir_fc; |
7b33a0e0 | 563 | |
0476f6f7 | 564 | BT_ASSERT(ctx->sc); |
7b33a0e0 | 565 | |
0476f6f7 PP |
566 | if (ctx->sc->is_translated) { |
567 | ctx->ir_sc = bt_trace_class_borrow_stream_class_by_id( | |
568 | ctx->ir_tc, ctx->sc->id); | |
569 | BT_ASSERT(ctx->ir_sc); | |
570 | goto end; | |
7b33a0e0 PP |
571 | } |
572 | ||
0476f6f7 PP |
573 | ctx->ir_sc = bt_stream_class_create_with_id(ctx->ir_tc, ctx->sc->id); |
574 | BT_ASSERT(ctx->ir_sc); | |
575 | bt_stream_class_put_ref(ctx->ir_sc); | |
37a93d41 PP |
576 | |
577 | if (ctx->sc->default_clock_class) { | |
578 | BT_ASSERT(ctx->sc->default_clock_class->ir_cc); | |
579 | ret = bt_stream_class_set_default_clock_class(ctx->ir_sc, | |
580 | ctx->sc->default_clock_class->ir_cc); | |
581 | BT_ASSERT(ret == 0); | |
582 | } | |
583 | ||
584 | bt_stream_class_set_supports_packets(ctx->ir_sc, BT_TRUE, | |
585 | ctx->sc->packets_have_ts_begin, ctx->sc->packets_have_ts_end); | |
586 | bt_stream_class_set_supports_discarded_events(ctx->ir_sc, | |
587 | ctx->sc->has_discarded_events, | |
588 | ctx->sc->discarded_events_have_default_cs); | |
589 | bt_stream_class_set_supports_discarded_packets(ctx->ir_sc, | |
590 | ctx->sc->has_discarded_packets, | |
591 | ctx->sc->discarded_packets_have_default_cs); | |
0476f6f7 PP |
592 | ctx->scope = CTF_SCOPE_PACKET_CONTEXT; |
593 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
594 | if (ir_fc) { | |
595 | ret = bt_stream_class_set_packet_context_field_class( | |
596 | ctx->ir_sc, ir_fc); | |
597 | BT_ASSERT(ret == 0); | |
598 | bt_field_class_put_ref(ir_fc); | |
7b33a0e0 PP |
599 | } |
600 | ||
0476f6f7 PP |
601 | ctx->scope = CTF_SCOPE_EVENT_COMMON_CONTEXT; |
602 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
603 | if (ir_fc) { | |
604 | ret = bt_stream_class_set_event_common_context_field_class( | |
605 | ctx->ir_sc, ir_fc); | |
606 | BT_ASSERT(ret == 0); | |
607 | bt_field_class_put_ref(ir_fc); | |
7b33a0e0 PP |
608 | } |
609 | ||
0476f6f7 | 610 | bt_stream_class_set_assigns_automatic_event_class_id(ctx->ir_sc, |
7b33a0e0 | 611 | BT_FALSE); |
0476f6f7 | 612 | bt_stream_class_set_assigns_automatic_stream_id(ctx->ir_sc, BT_FALSE); |
7b33a0e0 | 613 | |
0476f6f7 PP |
614 | ctx->sc->is_translated = true; |
615 | ctx->sc->ir_sc = ctx->ir_sc; | |
7b33a0e0 PP |
616 | |
617 | end: | |
0476f6f7 | 618 | return; |
7b33a0e0 PP |
619 | } |
620 | ||
621 | static inline | |
35fa110e PP |
622 | void ctf_clock_class_to_ir(bt_clock_class *ir_cc, struct ctf_clock_class *cc) |
623 | { | |
624 | int ret; | |
625 | ||
626 | if (strlen(cc->name->str) > 0) { | |
627 | ret = bt_clock_class_set_name(ir_cc, cc->name->str); | |
628 | BT_ASSERT(ret == 0); | |
629 | } | |
630 | ||
631 | if (strlen(cc->description->str) > 0) { | |
632 | ret = bt_clock_class_set_description(ir_cc, cc->description->str); | |
633 | BT_ASSERT(ret == 0); | |
634 | } | |
635 | ||
636 | bt_clock_class_set_frequency(ir_cc, cc->frequency); | |
637 | bt_clock_class_set_precision(ir_cc, cc->precision); | |
638 | bt_clock_class_set_offset(ir_cc, cc->offset_seconds, cc->offset_cycles); | |
639 | ||
640 | if (cc->has_uuid) { | |
641 | bt_clock_class_set_uuid(ir_cc, cc->uuid); | |
642 | } | |
643 | ||
d608d675 | 644 | bt_clock_class_set_origin_is_unix_epoch(ir_cc, cc->is_absolute); |
35fa110e PP |
645 | } |
646 | ||
647 | static inline | |
0476f6f7 | 648 | int ctf_trace_class_to_ir(struct ctx *ctx) |
7b33a0e0 PP |
649 | { |
650 | int ret = 0; | |
651 | uint64_t i; | |
652 | ||
0476f6f7 PP |
653 | BT_ASSERT(ctx->tc); |
654 | BT_ASSERT(ctx->ir_tc); | |
7b33a0e0 | 655 | |
0476f6f7 PP |
656 | if (ctx->tc->is_translated) { |
657 | goto end; | |
7b33a0e0 PP |
658 | } |
659 | ||
0476f6f7 PP |
660 | for (i = 0; i < ctx->tc->clock_classes->len; i++) { |
661 | struct ctf_clock_class *cc = ctx->tc->clock_classes->pdata[i]; | |
35fa110e | 662 | |
16699f85 | 663 | cc->ir_cc = bt_clock_class_create(ctx->self_comp); |
35fa110e PP |
664 | ctf_clock_class_to_ir(cc->ir_cc, cc); |
665 | } | |
666 | ||
0476f6f7 | 667 | bt_trace_class_set_assigns_automatic_stream_class_id(ctx->ir_tc, |
7b33a0e0 | 668 | BT_FALSE); |
0476f6f7 PP |
669 | ctx->tc->is_translated = true; |
670 | ctx->tc->ir_tc = ctx->ir_tc; | |
7b33a0e0 PP |
671 | |
672 | end: | |
673 | return ret; | |
674 | } | |
675 | ||
676 | BT_HIDDEN | |
16699f85 | 677 | int ctf_trace_class_translate(bt_self_component *self_comp, |
c0c2ed34 | 678 | bt_trace_class *ir_tc, struct ctf_trace_class *tc) |
7b33a0e0 PP |
679 | { |
680 | int ret = 0; | |
681 | uint64_t i; | |
0476f6f7 | 682 | struct ctx ctx = { 0 }; |
7b33a0e0 | 683 | |
c0c2ed34 | 684 | ctx.self_comp = self_comp; |
0476f6f7 PP |
685 | ctx.tc = tc; |
686 | ctx.ir_tc = ir_tc; | |
687 | ret = ctf_trace_class_to_ir(&ctx); | |
7b33a0e0 PP |
688 | if (ret) { |
689 | goto end; | |
690 | } | |
691 | ||
692 | for (i = 0; i < tc->stream_classes->len; i++) { | |
693 | uint64_t j; | |
0476f6f7 | 694 | ctx.sc = tc->stream_classes->pdata[i]; |
7b33a0e0 | 695 | |
0476f6f7 | 696 | ctf_stream_class_to_ir(&ctx); |
7b33a0e0 | 697 | |
0476f6f7 PP |
698 | for (j = 0; j < ctx.sc->event_classes->len; j++) { |
699 | ctx.ec = ctx.sc->event_classes->pdata[j]; | |
7b33a0e0 | 700 | |
0476f6f7 PP |
701 | ctf_event_class_to_ir(&ctx); |
702 | ctx.ec = NULL; | |
7b33a0e0 | 703 | } |
0476f6f7 PP |
704 | |
705 | ctx.sc = NULL; | |
7b33a0e0 PP |
706 | } |
707 | ||
708 | end: | |
709 | return ret; | |
710 | } |