Commit | Line | Data |
---|---|---|
44c440bc 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 | ||
15 | #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-TRANSLATE" | |
16 | #include "logging.h" | |
17 | ||
3fadfbc0 MJ |
18 | #include <babeltrace2/babeltrace.h> |
19 | #include <babeltrace2/babeltrace-internal.h> | |
20 | #include <babeltrace2/assert-internal.h> | |
44c440bc PP |
21 | #include <glib.h> |
22 | #include <stdint.h> | |
23 | #include <string.h> | |
24 | #include <inttypes.h> | |
25 | ||
26 | #include "ctf-meta-visitors.h" | |
27 | ||
83ebb7f1 | 28 | struct ctx { |
7fcdb0a9 | 29 | bt_self_component_source *self_comp; |
83ebb7f1 PP |
30 | bt_trace_class *ir_tc; |
31 | bt_stream_class *ir_sc; | |
32 | struct ctf_trace_class *tc; | |
33 | struct ctf_stream_class *sc; | |
34 | struct ctf_event_class *ec; | |
35 | enum ctf_scope scope; | |
36 | }; | |
37 | ||
44c440bc | 38 | static inline |
83ebb7f1 PP |
39 | bt_field_class *ctf_field_class_to_ir(struct ctx *ctx, |
40 | struct ctf_field_class *fc); | |
44c440bc PP |
41 | |
42 | static inline | |
5cd6d0e5 | 43 | void ctf_field_class_int_set_props(struct ctf_field_class_int *fc, |
b19ff26f | 44 | bt_field_class *ir_fc) |
44c440bc | 45 | { |
40f4ba76 | 46 | bt_field_class_integer_set_field_value_range(ir_fc, |
e5be10ef | 47 | fc->base.size); |
40f4ba76 | 48 | bt_field_class_integer_set_preferred_display_base(ir_fc, |
5cd6d0e5 | 49 | fc->disp_base); |
44c440bc PP |
50 | } |
51 | ||
52 | static inline | |
83ebb7f1 | 53 | bt_field_class *ctf_field_class_int_to_ir(struct ctx *ctx, |
e5be10ef | 54 | struct ctf_field_class_int *fc) |
44c440bc | 55 | { |
b19ff26f | 56 | bt_field_class *ir_fc; |
44c440bc | 57 | |
5cd6d0e5 | 58 | if (fc->is_signed) { |
83ebb7f1 | 59 | ir_fc = bt_field_class_signed_integer_create(ctx->ir_tc); |
44c440bc | 60 | } else { |
83ebb7f1 | 61 | ir_fc = bt_field_class_unsigned_integer_create(ctx->ir_tc); |
44c440bc PP |
62 | } |
63 | ||
5cd6d0e5 PP |
64 | BT_ASSERT(ir_fc); |
65 | ctf_field_class_int_set_props(fc, ir_fc); | |
66 | return ir_fc; | |
44c440bc PP |
67 | } |
68 | ||
69 | static inline | |
83ebb7f1 | 70 | bt_field_class *ctf_field_class_enum_to_ir(struct ctx *ctx, |
e5be10ef | 71 | struct ctf_field_class_enum *fc) |
44c440bc PP |
72 | { |
73 | int ret; | |
b19ff26f | 74 | bt_field_class *ir_fc; |
44c440bc PP |
75 | uint64_t i; |
76 | ||
5cd6d0e5 | 77 | if (fc->base.is_signed) { |
83ebb7f1 | 78 | ir_fc = bt_field_class_signed_enumeration_create(ctx->ir_tc); |
44c440bc | 79 | } else { |
83ebb7f1 | 80 | ir_fc = bt_field_class_unsigned_enumeration_create(ctx->ir_tc); |
44c440bc PP |
81 | } |
82 | ||
5cd6d0e5 PP |
83 | BT_ASSERT(ir_fc); |
84 | ctf_field_class_int_set_props((void *) fc, ir_fc); | |
44c440bc | 85 | |
5cd6d0e5 PP |
86 | for (i = 0; i < fc->mappings->len; i++) { |
87 | struct ctf_field_class_enum_mapping *mapping = | |
88 | ctf_field_class_enum_borrow_mapping_by_index(fc, i); | |
44c440bc | 89 | |
5cd6d0e5 | 90 | if (fc->base.is_signed) { |
40f4ba76 | 91 | ret = bt_field_class_signed_enumeration_map_range( |
5cd6d0e5 | 92 | ir_fc, mapping->label->str, |
44c440bc PP |
93 | mapping->range.lower.i, mapping->range.upper.i); |
94 | } else { | |
40f4ba76 | 95 | ret = bt_field_class_unsigned_enumeration_map_range( |
5cd6d0e5 | 96 | ir_fc, mapping->label->str, |
44c440bc PP |
97 | mapping->range.lower.u, mapping->range.upper.u); |
98 | } | |
99 | ||
100 | BT_ASSERT(ret == 0); | |
101 | } | |
102 | ||
5cd6d0e5 | 103 | return ir_fc; |
44c440bc PP |
104 | } |
105 | ||
106 | static inline | |
83ebb7f1 | 107 | bt_field_class *ctf_field_class_float_to_ir(struct ctx *ctx, |
5cd6d0e5 | 108 | struct ctf_field_class_float *fc) |
44c440bc | 109 | { |
b19ff26f | 110 | bt_field_class *ir_fc; |
44c440bc | 111 | |
83ebb7f1 | 112 | ir_fc = bt_field_class_real_create(ctx->ir_tc); |
5cd6d0e5 | 113 | BT_ASSERT(ir_fc); |
44c440bc | 114 | |
5cd6d0e5 | 115 | if (fc->base.size == 32) { |
40f4ba76 | 116 | bt_field_class_real_set_is_single_precision(ir_fc, |
44c440bc | 117 | BT_TRUE); |
44c440bc PP |
118 | } |
119 | ||
5cd6d0e5 | 120 | return ir_fc; |
44c440bc PP |
121 | } |
122 | ||
123 | static inline | |
83ebb7f1 | 124 | bt_field_class *ctf_field_class_string_to_ir(struct ctx *ctx, |
5cd6d0e5 | 125 | struct ctf_field_class_string *fc) |
44c440bc | 126 | { |
83ebb7f1 | 127 | bt_field_class *ir_fc = bt_field_class_string_create(ctx->ir_tc); |
44c440bc | 128 | |
5cd6d0e5 PP |
129 | BT_ASSERT(ir_fc); |
130 | return ir_fc; | |
44c440bc PP |
131 | } |
132 | ||
133 | static inline | |
83ebb7f1 PP |
134 | void translate_struct_field_class_members(struct ctx *ctx, |
135 | struct ctf_field_class_struct *fc, bt_field_class *ir_fc, | |
136 | bool with_header_prefix, | |
137 | struct ctf_field_class_struct *context_fc) | |
44c440bc | 138 | { |
44c440bc | 139 | uint64_t i; |
83ebb7f1 | 140 | int ret; |
44c440bc | 141 | |
5cd6d0e5 PP |
142 | for (i = 0; i < fc->members->len; i++) { |
143 | struct ctf_named_field_class *named_fc = | |
144 | ctf_field_class_struct_borrow_member_by_index(fc, i); | |
b19ff26f | 145 | bt_field_class *member_ir_fc; |
83ebb7f1 | 146 | const char *name = named_fc->name->str; |
44c440bc | 147 | |
5cd6d0e5 | 148 | if (!named_fc->fc->in_ir) { |
44c440bc PP |
149 | continue; |
150 | } | |
151 | ||
83ebb7f1 | 152 | member_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc); |
5cd6d0e5 | 153 | BT_ASSERT(member_ir_fc); |
83ebb7f1 PP |
154 | ret = bt_field_class_structure_append_member(ir_fc, name, |
155 | member_ir_fc); | |
44c440bc | 156 | BT_ASSERT(ret == 0); |
c5b9b441 | 157 | bt_field_class_put_ref(member_ir_fc); |
44c440bc | 158 | } |
83ebb7f1 | 159 | } |
44c440bc | 160 | |
83ebb7f1 PP |
161 | static inline |
162 | bt_field_class *ctf_field_class_struct_to_ir(struct ctx *ctx, | |
163 | struct ctf_field_class_struct *fc) | |
164 | { | |
165 | bt_field_class *ir_fc = bt_field_class_structure_create(ctx->ir_tc); | |
166 | ||
167 | BT_ASSERT(ir_fc); | |
168 | translate_struct_field_class_members(ctx, fc, ir_fc, false, NULL); | |
5cd6d0e5 | 169 | return ir_fc; |
44c440bc PP |
170 | } |
171 | ||
172 | static inline | |
83ebb7f1 PP |
173 | bt_field_class *borrow_ir_fc_from_field_path(struct ctx *ctx, |
174 | struct ctf_field_path *field_path) | |
44c440bc | 175 | { |
b19ff26f | 176 | bt_field_class *ir_fc = NULL; |
5cd6d0e5 | 177 | struct ctf_field_class *fc = ctf_field_path_borrow_field_class( |
83ebb7f1 | 178 | field_path, ctx->tc, ctx->sc, ctx->ec); |
44c440bc | 179 | |
5cd6d0e5 | 180 | BT_ASSERT(fc); |
44c440bc | 181 | |
5cd6d0e5 PP |
182 | if (fc->in_ir) { |
183 | ir_fc = fc->ir_fc; | |
44c440bc PP |
184 | } |
185 | ||
5cd6d0e5 | 186 | return ir_fc; |
44c440bc PP |
187 | } |
188 | ||
189 | static inline | |
83ebb7f1 PP |
190 | bt_field_class *ctf_field_class_variant_to_ir(struct ctx *ctx, |
191 | struct ctf_field_class_variant *fc) | |
44c440bc PP |
192 | { |
193 | int ret; | |
83ebb7f1 | 194 | bt_field_class *ir_fc = bt_field_class_variant_create(ctx->ir_tc); |
44c440bc PP |
195 | uint64_t i; |
196 | ||
5cd6d0e5 | 197 | BT_ASSERT(ir_fc); |
83ebb7f1 PP |
198 | |
199 | if (fc->tag_path.root != CTF_SCOPE_PACKET_HEADER && | |
200 | fc->tag_path.root != CTF_SCOPE_EVENT_HEADER) { | |
201 | ret = bt_field_class_variant_set_selector_field_class( | |
202 | ir_fc, borrow_ir_fc_from_field_path(ctx, | |
203 | &fc->tag_path)); | |
204 | BT_ASSERT(ret == 0); | |
205 | } | |
44c440bc | 206 | |
5cd6d0e5 PP |
207 | for (i = 0; i < fc->options->len; i++) { |
208 | struct ctf_named_field_class *named_fc = | |
209 | ctf_field_class_variant_borrow_option_by_index(fc, i); | |
b19ff26f | 210 | bt_field_class *option_ir_fc; |
44c440bc | 211 | |
5cd6d0e5 | 212 | BT_ASSERT(named_fc->fc->in_ir); |
83ebb7f1 | 213 | option_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc); |
5cd6d0e5 | 214 | BT_ASSERT(option_ir_fc); |
40f4ba76 | 215 | ret = bt_field_class_variant_append_option( |
e5be10ef | 216 | ir_fc, named_fc->name->str, option_ir_fc); |
44c440bc | 217 | BT_ASSERT(ret == 0); |
c5b9b441 | 218 | bt_field_class_put_ref(option_ir_fc); |
44c440bc PP |
219 | } |
220 | ||
5cd6d0e5 | 221 | return ir_fc; |
44c440bc PP |
222 | } |
223 | ||
224 | static inline | |
83ebb7f1 PP |
225 | bt_field_class *ctf_field_class_array_to_ir(struct ctx *ctx, |
226 | struct ctf_field_class_array *fc) | |
44c440bc | 227 | { |
b19ff26f PP |
228 | bt_field_class *ir_fc; |
229 | bt_field_class *elem_ir_fc; | |
44c440bc | 230 | |
5cd6d0e5 | 231 | if (fc->base.is_text) { |
83ebb7f1 | 232 | ir_fc = bt_field_class_string_create(ctx->ir_tc); |
5cd6d0e5 | 233 | BT_ASSERT(ir_fc); |
44c440bc PP |
234 | goto end; |
235 | } | |
236 | ||
83ebb7f1 | 237 | elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc); |
5cd6d0e5 | 238 | BT_ASSERT(elem_ir_fc); |
83ebb7f1 | 239 | ir_fc = bt_field_class_static_array_create(ctx->ir_tc, elem_ir_fc, |
e5be10ef | 240 | fc->length); |
5cd6d0e5 | 241 | BT_ASSERT(ir_fc); |
c5b9b441 | 242 | bt_field_class_put_ref(elem_ir_fc); |
44c440bc PP |
243 | |
244 | end: | |
5cd6d0e5 | 245 | return ir_fc; |
44c440bc PP |
246 | } |
247 | ||
248 | static inline | |
83ebb7f1 PP |
249 | bt_field_class *ctf_field_class_sequence_to_ir(struct ctx *ctx, |
250 | struct ctf_field_class_sequence *fc) | |
44c440bc PP |
251 | { |
252 | int ret; | |
b19ff26f PP |
253 | bt_field_class *ir_fc; |
254 | bt_field_class *elem_ir_fc; | |
44c440bc | 255 | |
5cd6d0e5 | 256 | if (fc->base.is_text) { |
83ebb7f1 | 257 | ir_fc = bt_field_class_string_create(ctx->ir_tc); |
5cd6d0e5 | 258 | BT_ASSERT(ir_fc); |
44c440bc PP |
259 | goto end; |
260 | } | |
261 | ||
83ebb7f1 | 262 | elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc); |
5cd6d0e5 | 263 | BT_ASSERT(elem_ir_fc); |
83ebb7f1 | 264 | ir_fc = bt_field_class_dynamic_array_create(ctx->ir_tc, elem_ir_fc); |
5cd6d0e5 | 265 | BT_ASSERT(ir_fc); |
c5b9b441 | 266 | bt_field_class_put_ref(elem_ir_fc); |
5cd6d0e5 | 267 | BT_ASSERT(ir_fc); |
83ebb7f1 PP |
268 | |
269 | if (fc->length_path.root != CTF_SCOPE_PACKET_HEADER && | |
270 | fc->length_path.root != CTF_SCOPE_EVENT_HEADER) { | |
271 | ret = bt_field_class_dynamic_array_set_length_field_class( | |
272 | ir_fc, borrow_ir_fc_from_field_path(ctx, &fc->length_path)); | |
273 | BT_ASSERT(ret == 0); | |
274 | } | |
44c440bc PP |
275 | |
276 | end: | |
5cd6d0e5 | 277 | return ir_fc; |
44c440bc PP |
278 | } |
279 | ||
280 | static inline | |
83ebb7f1 PP |
281 | bt_field_class *ctf_field_class_to_ir(struct ctx *ctx, |
282 | struct ctf_field_class *fc) | |
44c440bc | 283 | { |
b19ff26f | 284 | bt_field_class *ir_fc = NULL; |
44c440bc | 285 | |
5cd6d0e5 PP |
286 | BT_ASSERT(fc); |
287 | BT_ASSERT(fc->in_ir); | |
44c440bc | 288 | |
864cad70 PP |
289 | switch (fc->type) { |
290 | case CTF_FIELD_CLASS_TYPE_INT: | |
83ebb7f1 | 291 | ir_fc = ctf_field_class_int_to_ir(ctx, (void *) fc); |
44c440bc | 292 | break; |
864cad70 | 293 | case CTF_FIELD_CLASS_TYPE_ENUM: |
83ebb7f1 | 294 | ir_fc = ctf_field_class_enum_to_ir(ctx, (void *) fc); |
44c440bc | 295 | break; |
864cad70 | 296 | case CTF_FIELD_CLASS_TYPE_FLOAT: |
83ebb7f1 | 297 | ir_fc = ctf_field_class_float_to_ir(ctx, (void *) fc); |
44c440bc | 298 | break; |
864cad70 | 299 | case CTF_FIELD_CLASS_TYPE_STRING: |
83ebb7f1 | 300 | ir_fc = ctf_field_class_string_to_ir(ctx, (void *) fc); |
44c440bc | 301 | break; |
864cad70 | 302 | case CTF_FIELD_CLASS_TYPE_STRUCT: |
83ebb7f1 | 303 | ir_fc = ctf_field_class_struct_to_ir(ctx, (void *) fc); |
44c440bc | 304 | break; |
864cad70 | 305 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
83ebb7f1 | 306 | ir_fc = ctf_field_class_array_to_ir(ctx, (void *) fc); |
44c440bc | 307 | break; |
864cad70 | 308 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: |
83ebb7f1 | 309 | ir_fc = ctf_field_class_sequence_to_ir(ctx, (void *) fc); |
44c440bc | 310 | break; |
864cad70 | 311 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
83ebb7f1 | 312 | ir_fc = ctf_field_class_variant_to_ir(ctx, (void *) fc); |
44c440bc PP |
313 | break; |
314 | default: | |
315 | abort(); | |
316 | } | |
317 | ||
5cd6d0e5 PP |
318 | fc->ir_fc = ir_fc; |
319 | return ir_fc; | |
44c440bc PP |
320 | } |
321 | ||
322 | static inline | |
5cd6d0e5 PP |
323 | bool ctf_field_class_struct_has_immediate_member_in_ir( |
324 | struct ctf_field_class_struct *fc) | |
44c440bc PP |
325 | { |
326 | uint64_t i; | |
327 | bool has_immediate_member_in_ir = false; | |
328 | ||
b2c863b0 PP |
329 | /* |
330 | * If the structure field class has no members at all, then it | |
331 | * was an empty structure in the beginning, so leave it existing | |
332 | * and empty. | |
333 | */ | |
334 | if (fc->members->len == 0) { | |
335 | has_immediate_member_in_ir = true; | |
336 | goto end; | |
337 | } | |
338 | ||
5cd6d0e5 PP |
339 | for (i = 0; i < fc->members->len; i++) { |
340 | struct ctf_named_field_class *named_fc = | |
341 | ctf_field_class_struct_borrow_member_by_index(fc, i); | |
44c440bc | 342 | |
5cd6d0e5 | 343 | if (named_fc->fc->in_ir) { |
44c440bc PP |
344 | has_immediate_member_in_ir = true; |
345 | goto end; | |
346 | } | |
347 | } | |
348 | ||
349 | end: | |
350 | return has_immediate_member_in_ir; | |
351 | } | |
352 | ||
353 | static inline | |
83ebb7f1 | 354 | bt_field_class *scope_ctf_field_class_to_ir(struct ctx *ctx) |
44c440bc | 355 | { |
b19ff26f | 356 | bt_field_class *ir_fc = NULL; |
83ebb7f1 | 357 | struct ctf_field_class *fc = NULL; |
44c440bc | 358 | |
83ebb7f1 PP |
359 | switch (ctx->scope) { |
360 | case CTF_SCOPE_PACKET_CONTEXT: | |
361 | fc = ctx->sc->packet_context_fc; | |
362 | break; | |
363 | case CTF_SCOPE_EVENT_COMMON_CONTEXT: | |
364 | fc = ctx->sc->event_common_context_fc; | |
365 | break; | |
366 | case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT: | |
367 | fc = ctx->ec->spec_context_fc; | |
368 | break; | |
369 | case CTF_SCOPE_EVENT_PAYLOAD: | |
370 | fc = ctx->ec->payload_fc; | |
371 | break; | |
372 | default: | |
373 | abort(); | |
44c440bc PP |
374 | } |
375 | ||
83ebb7f1 PP |
376 | if (fc && ctf_field_class_struct_has_immediate_member_in_ir( |
377 | (void *) fc)) { | |
378 | ir_fc = ctf_field_class_to_ir(ctx, fc); | |
44c440bc PP |
379 | } |
380 | ||
5cd6d0e5 | 381 | return ir_fc; |
44c440bc PP |
382 | } |
383 | ||
44c440bc | 384 | static inline |
83ebb7f1 | 385 | void ctf_event_class_to_ir(struct ctx *ctx) |
44c440bc PP |
386 | { |
387 | int ret; | |
b19ff26f | 388 | bt_event_class *ir_ec = NULL; |
83ebb7f1 | 389 | bt_field_class *ir_fc; |
44c440bc | 390 | |
83ebb7f1 PP |
391 | BT_ASSERT(ctx->ec); |
392 | ||
393 | if (ctx->ec->is_translated) { | |
40f4ba76 | 394 | ir_ec = bt_stream_class_borrow_event_class_by_id( |
83ebb7f1 | 395 | ctx->ir_sc, ctx->ec->id); |
44c440bc PP |
396 | BT_ASSERT(ir_ec); |
397 | goto end; | |
398 | } | |
399 | ||
83ebb7f1 | 400 | ir_ec = bt_event_class_create_with_id(ctx->ir_sc, ctx->ec->id); |
44c440bc | 401 | BT_ASSERT(ir_ec); |
c5b9b441 | 402 | bt_event_class_put_ref(ir_ec); |
83ebb7f1 PP |
403 | ctx->scope = CTF_SCOPE_EVENT_SPECIFIC_CONTEXT; |
404 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
405 | if (ir_fc) { | |
406 | ret = bt_event_class_set_specific_context_field_class( | |
407 | ir_ec, ir_fc); | |
408 | BT_ASSERT(ret == 0); | |
409 | bt_field_class_put_ref(ir_fc); | |
44c440bc PP |
410 | } |
411 | ||
83ebb7f1 PP |
412 | ctx->scope = CTF_SCOPE_EVENT_PAYLOAD; |
413 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
414 | if (ir_fc) { | |
415 | ret = bt_event_class_set_payload_field_class(ir_ec, | |
416 | ir_fc); | |
417 | BT_ASSERT(ret == 0); | |
418 | bt_field_class_put_ref(ir_fc); | |
44c440bc PP |
419 | } |
420 | ||
83ebb7f1 PP |
421 | if (ctx->ec->name->len > 0) { |
422 | ret = bt_event_class_set_name(ir_ec, ctx->ec->name->str); | |
44c440bc PP |
423 | BT_ASSERT(ret == 0); |
424 | } | |
425 | ||
83ebb7f1 PP |
426 | if (ctx->ec->emf_uri->len > 0) { |
427 | ret = bt_event_class_set_emf_uri(ir_ec, ctx->ec->emf_uri->str); | |
44c440bc PP |
428 | BT_ASSERT(ret == 0); |
429 | } | |
430 | ||
83ebb7f1 PP |
431 | if (ctx->ec->log_level != -1) { |
432 | bt_event_class_set_log_level(ir_ec, ctx->ec->log_level); | |
44c440bc PP |
433 | } |
434 | ||
83ebb7f1 PP |
435 | ctx->ec->is_translated = true; |
436 | ctx->ec->ir_ec = ir_ec; | |
44c440bc PP |
437 | |
438 | end: | |
83ebb7f1 | 439 | return; |
44c440bc PP |
440 | } |
441 | ||
442 | ||
443 | static inline | |
83ebb7f1 | 444 | void ctf_stream_class_to_ir(struct ctx *ctx) |
44c440bc PP |
445 | { |
446 | int ret; | |
83ebb7f1 | 447 | bt_field_class *ir_fc; |
44c440bc | 448 | |
83ebb7f1 | 449 | BT_ASSERT(ctx->sc); |
44c440bc | 450 | |
83ebb7f1 PP |
451 | if (ctx->sc->is_translated) { |
452 | ctx->ir_sc = bt_trace_class_borrow_stream_class_by_id( | |
453 | ctx->ir_tc, ctx->sc->id); | |
454 | BT_ASSERT(ctx->ir_sc); | |
455 | goto end; | |
44c440bc PP |
456 | } |
457 | ||
83ebb7f1 PP |
458 | ctx->ir_sc = bt_stream_class_create_with_id(ctx->ir_tc, ctx->sc->id); |
459 | BT_ASSERT(ctx->ir_sc); | |
460 | bt_stream_class_put_ref(ctx->ir_sc); | |
461 | ctx->scope = CTF_SCOPE_PACKET_CONTEXT; | |
462 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
463 | if (ir_fc) { | |
464 | ret = bt_stream_class_set_packet_context_field_class( | |
465 | ctx->ir_sc, ir_fc); | |
466 | BT_ASSERT(ret == 0); | |
467 | bt_field_class_put_ref(ir_fc); | |
44c440bc PP |
468 | } |
469 | ||
83ebb7f1 PP |
470 | ctx->scope = CTF_SCOPE_EVENT_COMMON_CONTEXT; |
471 | ir_fc = scope_ctf_field_class_to_ir(ctx); | |
472 | if (ir_fc) { | |
473 | ret = bt_stream_class_set_event_common_context_field_class( | |
474 | ctx->ir_sc, ir_fc); | |
475 | BT_ASSERT(ret == 0); | |
476 | bt_field_class_put_ref(ir_fc); | |
44c440bc PP |
477 | } |
478 | ||
83ebb7f1 | 479 | bt_stream_class_set_assigns_automatic_event_class_id(ctx->ir_sc, |
44c440bc | 480 | BT_FALSE); |
83ebb7f1 | 481 | bt_stream_class_set_assigns_automatic_stream_id(ctx->ir_sc, BT_FALSE); |
44c440bc | 482 | |
83ebb7f1 PP |
483 | if (ctx->sc->default_clock_class) { |
484 | BT_ASSERT(ctx->sc->default_clock_class->ir_cc); | |
485 | ret = bt_stream_class_set_default_clock_class(ctx->ir_sc, | |
486 | ctx->sc->default_clock_class->ir_cc); | |
44c440bc PP |
487 | BT_ASSERT(ret == 0); |
488 | } | |
489 | ||
9b24b6aa | 490 | bt_stream_class_set_packets_have_beginning_default_clock_snapshot( |
afd45274 | 491 | ctx->ir_sc, ctx->sc->packets_have_ts_begin); |
9b24b6aa | 492 | bt_stream_class_set_packets_have_end_default_clock_snapshot( |
afd45274 PP |
493 | ctx->ir_sc, ctx->sc->packets_have_ts_end); |
494 | bt_stream_class_set_supports_discarded_events(ctx->ir_sc, | |
495 | ctx->sc->has_discarded_events, | |
496 | ctx->sc->discarded_events_have_default_cs); | |
497 | bt_stream_class_set_supports_discarded_packets(ctx->ir_sc, | |
498 | ctx->sc->has_discarded_packets, | |
499 | ctx->sc->discarded_packets_have_default_cs); | |
83ebb7f1 PP |
500 | ctx->sc->is_translated = true; |
501 | ctx->sc->ir_sc = ctx->ir_sc; | |
44c440bc PP |
502 | |
503 | end: | |
83ebb7f1 | 504 | return; |
44c440bc PP |
505 | } |
506 | ||
507 | static inline | |
0f2d58c9 PP |
508 | void ctf_clock_class_to_ir(bt_clock_class *ir_cc, struct ctf_clock_class *cc) |
509 | { | |
510 | int ret; | |
511 | ||
512 | if (strlen(cc->name->str) > 0) { | |
513 | ret = bt_clock_class_set_name(ir_cc, cc->name->str); | |
514 | BT_ASSERT(ret == 0); | |
515 | } | |
516 | ||
517 | if (strlen(cc->description->str) > 0) { | |
518 | ret = bt_clock_class_set_description(ir_cc, cc->description->str); | |
519 | BT_ASSERT(ret == 0); | |
520 | } | |
521 | ||
522 | bt_clock_class_set_frequency(ir_cc, cc->frequency); | |
523 | bt_clock_class_set_precision(ir_cc, cc->precision); | |
524 | bt_clock_class_set_offset(ir_cc, cc->offset_seconds, cc->offset_cycles); | |
525 | ||
526 | if (cc->has_uuid) { | |
527 | bt_clock_class_set_uuid(ir_cc, cc->uuid); | |
528 | } | |
529 | ||
5552377a | 530 | bt_clock_class_set_origin_is_unix_epoch(ir_cc, cc->is_absolute); |
0f2d58c9 PP |
531 | } |
532 | ||
533 | static inline | |
83ebb7f1 | 534 | int ctf_trace_class_to_ir(struct ctx *ctx) |
44c440bc PP |
535 | { |
536 | int ret = 0; | |
537 | uint64_t i; | |
538 | ||
83ebb7f1 PP |
539 | BT_ASSERT(ctx->tc); |
540 | BT_ASSERT(ctx->ir_tc); | |
44c440bc | 541 | |
83ebb7f1 PP |
542 | if (ctx->tc->is_translated) { |
543 | goto end; | |
44c440bc PP |
544 | } |
545 | ||
83ebb7f1 PP |
546 | if (ctx->tc->is_uuid_set) { |
547 | bt_trace_class_set_uuid(ctx->ir_tc, ctx->tc->uuid); | |
44c440bc PP |
548 | } |
549 | ||
83ebb7f1 | 550 | for (i = 0; i < ctx->tc->env_entries->len; i++) { |
44c440bc | 551 | struct ctf_trace_class_env_entry *env_entry = |
83ebb7f1 | 552 | ctf_trace_class_borrow_env_entry_by_index(ctx->tc, i); |
44c440bc PP |
553 | |
554 | switch (env_entry->type) { | |
555 | case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT: | |
862ca4ed | 556 | ret = bt_trace_class_set_environment_entry_integer( |
83ebb7f1 | 557 | ctx->ir_tc, env_entry->name->str, |
44c440bc PP |
558 | env_entry->value.i); |
559 | break; | |
560 | case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR: | |
862ca4ed | 561 | ret = bt_trace_class_set_environment_entry_string( |
83ebb7f1 | 562 | ctx->ir_tc, env_entry->name->str, |
44c440bc PP |
563 | env_entry->value.str->str); |
564 | break; | |
565 | default: | |
566 | abort(); | |
567 | } | |
568 | ||
569 | if (ret) { | |
570 | goto end; | |
571 | } | |
572 | } | |
573 | ||
83ebb7f1 PP |
574 | for (i = 0; i < ctx->tc->clock_classes->len; i++) { |
575 | struct ctf_clock_class *cc = ctx->tc->clock_classes->pdata[i]; | |
0f2d58c9 | 576 | |
7fcdb0a9 FD |
577 | cc->ir_cc = bt_clock_class_create( |
578 | bt_self_component_source_as_self_component( | |
579 | ctx->self_comp)); | |
0f2d58c9 PP |
580 | ctf_clock_class_to_ir(cc->ir_cc, cc); |
581 | } | |
582 | ||
83ebb7f1 | 583 | bt_trace_class_set_assigns_automatic_stream_class_id(ctx->ir_tc, |
44c440bc | 584 | BT_FALSE); |
83ebb7f1 PP |
585 | ctx->tc->is_translated = true; |
586 | ctx->tc->ir_tc = ctx->ir_tc; | |
44c440bc PP |
587 | |
588 | end: | |
589 | return ret; | |
590 | } | |
591 | ||
592 | BT_HIDDEN | |
7fcdb0a9 FD |
593 | int ctf_trace_class_translate(bt_self_component_source *self_comp, |
594 | bt_trace_class *ir_tc, struct ctf_trace_class *tc) | |
44c440bc PP |
595 | { |
596 | int ret = 0; | |
597 | uint64_t i; | |
83ebb7f1 | 598 | struct ctx ctx = { 0 }; |
44c440bc | 599 | |
7fcdb0a9 | 600 | ctx.self_comp = self_comp; |
83ebb7f1 PP |
601 | ctx.tc = tc; |
602 | ctx.ir_tc = ir_tc; | |
603 | ret = ctf_trace_class_to_ir(&ctx); | |
44c440bc PP |
604 | if (ret) { |
605 | goto end; | |
606 | } | |
607 | ||
608 | for (i = 0; i < tc->stream_classes->len; i++) { | |
609 | uint64_t j; | |
83ebb7f1 | 610 | ctx.sc = tc->stream_classes->pdata[i]; |
44c440bc | 611 | |
83ebb7f1 | 612 | ctf_stream_class_to_ir(&ctx); |
44c440bc | 613 | |
83ebb7f1 PP |
614 | for (j = 0; j < ctx.sc->event_classes->len; j++) { |
615 | ctx.ec = ctx.sc->event_classes->pdata[j]; | |
44c440bc | 616 | |
83ebb7f1 PP |
617 | ctf_event_class_to_ir(&ctx); |
618 | ctx.ec = NULL; | |
44c440bc | 619 | } |
83ebb7f1 PP |
620 | |
621 | ctx.sc = NULL; | |
44c440bc PP |
622 | } |
623 | ||
624 | end: | |
625 | return ret; | |
626 | } |