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