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