X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmetadata%2Fvisitor-generate-ir.cpp;h=c53c4d8a3432c2f86e8790ed73bb78442e7da9c3;hb=4b9e2e3d5986e17f1594c24dea430cb51a529360;hp=33fa1ccb3a2b076aa2cc80ccb86f06da19bfa8a7;hpb=e458ac29e6e221e35996f1f615e07a8fad4c7d27;p=babeltrace.git diff --git a/src/plugins/ctf/common/metadata/visitor-generate-ir.cpp b/src/plugins/ctf/common/metadata/visitor-generate-ir.cpp index 33fa1ccb..c53c4d8a 100644 --- a/src/plugins/ctf/common/metadata/visitor-generate-ir.cpp +++ b/src/plugins/ctf/common/metadata/visitor-generate-ir.cpp @@ -7,34 +7,32 @@ * Common Trace Format metadata visitor (generates CTF IR objects). */ +#include + +#include +#include +#include +#include +#include + +#include + #define BT_COMP_LOG_SELF_COMP (ctx->log_cfg.self_comp) #define BT_COMP_LOG_SELF_COMP_CLASS (ctx->log_cfg.self_comp_class) #define BT_LOG_OUTPUT_LEVEL (ctx->log_cfg.log_level) #define BT_LOG_TAG "PLUGIN/CTF/META/IR-VISITOR" +#include "logging.hpp" #include "logging/comp-logging.h" -#include -#include -#include -#include -#include -#include #include "common/assert.h" -#include -#include -#include -#include #include "common/common.h" #include "common/uuid.h" -#include "compat/endian.h" -#include +#include "compat/endian.h" /* IWYU pragma: keep */ -#include "logging.hpp" -#include "scanner.hpp" #include "ast.hpp" -#include "decoder.hpp" -#include "ctf-meta.hpp" #include "ctf-meta-visitors.hpp" +#include "ctf-meta.hpp" +#include "decoder.hpp" /* Bit value (left shift) */ #define _BV(_val) (1 << (_val)) @@ -263,8 +261,7 @@ end: * @param name Name * @returns Associated GQuark, or 0 on error */ -static GQuark get_prefixed_named_quark(struct ctf_visitor_generate_ir *ctx, char prefix, - const char *name) +static GQuark get_prefixed_named_quark(char prefix, const char *name) { BT_ASSERT(name); std::string prname = std::string {prefix} + name; @@ -282,10 +279,9 @@ static GQuark get_prefixed_named_quark(struct ctf_visitor_generate_ir *ctx, char * @returns Declaration (owned by caller if \p copy is true), * or NULL if not found */ -static struct ctf_field_class * -ctx_decl_scope_lookup_prefix_alias(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, char prefix, const char *name, - int levels, bool copy) +static struct ctf_field_class *ctx_decl_scope_lookup_prefix_alias(struct ctx_decl_scope *scope, + char prefix, const char *name, + int levels, bool copy) { GQuark qname = 0; int cur_levels = 0; @@ -294,7 +290,7 @@ ctx_decl_scope_lookup_prefix_alias(struct ctf_visitor_generate_ir *ctx, BT_ASSERT(scope); BT_ASSERT(name); - qname = get_prefixed_named_quark(ctx, prefix, name); + qname = get_prefixed_named_quark(prefix, name); if (!qname) { goto end; } @@ -334,11 +330,10 @@ end: * @returns Declaration (owned by caller if \p copy is true), * or NULL if not found */ -static struct ctf_field_class *ctx_decl_scope_lookup_alias(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, +static struct ctf_field_class *ctx_decl_scope_lookup_alias(struct ctx_decl_scope *scope, const char *name, int levels, bool copy) { - return ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_ALIAS, name, levels, copy); + return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ALIAS, name, levels, copy); } /** @@ -351,13 +346,11 @@ static struct ctf_field_class *ctx_decl_scope_lookup_alias(struct ctf_visitor_ge * @returns Declaration (owned by caller if \p copy is true), * or NULL if not found */ -static struct ctf_field_class_enum *ctx_decl_scope_lookup_enum(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, - const char *name, int levels, - bool copy) +static struct ctf_field_class_enum * +ctx_decl_scope_lookup_enum(struct ctx_decl_scope *scope, const char *name, int levels, bool copy) { return ctf_field_class_as_enum( - ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_ENUM, name, levels, copy)); + ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ENUM, name, levels, copy)); } /** @@ -371,11 +364,10 @@ static struct ctf_field_class_enum *ctx_decl_scope_lookup_enum(struct ctf_visito * or NULL if not found */ static struct ctf_field_class_struct * -ctx_decl_scope_lookup_struct(struct ctf_visitor_generate_ir *ctx, struct ctx_decl_scope *scope, - const char *name, int levels, bool copy) +ctx_decl_scope_lookup_struct(struct ctx_decl_scope *scope, const char *name, int levels, bool copy) { return ctf_field_class_as_struct( - ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_STRUCT, name, levels, copy)); + ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_STRUCT, name, levels, copy)); } /** @@ -389,11 +381,10 @@ ctx_decl_scope_lookup_struct(struct ctf_visitor_generate_ir *ctx, struct ctx_dec * or NULL if not found */ static struct ctf_field_class_variant * -ctx_decl_scope_lookup_variant(struct ctf_visitor_generate_ir *ctx, struct ctx_decl_scope *scope, - const char *name, int levels, bool copy) +ctx_decl_scope_lookup_variant(struct ctx_decl_scope *scope, const char *name, int levels, bool copy) { return ctf_field_class_as_variant( - ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_VARIANT, name, levels, copy)); + ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_VARIANT, name, levels, copy)); } /** @@ -405,8 +396,7 @@ ctx_decl_scope_lookup_variant(struct ctf_visitor_generate_ir *ctx, struct ctx_de * @param decl Field class to register (copied) * @returns 0 if registration went okay, negative value otherwise */ -static int ctx_decl_scope_register_prefix_alias(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, char prefix, +static int ctx_decl_scope_register_prefix_alias(struct ctx_decl_scope *scope, char prefix, const char *name, struct ctf_field_class *decl) { int ret = 0; @@ -415,14 +405,14 @@ static int ctx_decl_scope_register_prefix_alias(struct ctf_visitor_generate_ir * BT_ASSERT(scope); BT_ASSERT(name); BT_ASSERT(decl); - qname = get_prefixed_named_quark(ctx, prefix, name); + qname = get_prefixed_named_quark(prefix, name); if (!qname) { ret = -ENOMEM; goto end; } /* Make sure alias does not exist in local scope */ - if (ctx_decl_scope_lookup_prefix_alias(ctx, scope, prefix, name, 1, false)) { + if (ctx_decl_scope_lookup_prefix_alias(scope, prefix, name, 1, false)) { ret = -EEXIST; goto end; } @@ -443,11 +433,10 @@ end: * @param decl Field class to register (copied) * @returns 0 if registration went okay, negative value otherwise */ -static int ctx_decl_scope_register_alias(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, const char *name, +static int ctx_decl_scope_register_alias(struct ctx_decl_scope *scope, const char *name, struct ctf_field_class *decl) { - return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_ALIAS, name, decl); + return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ALIAS, name, decl); } /** @@ -458,12 +447,10 @@ static int ctx_decl_scope_register_alias(struct ctf_visitor_generate_ir *ctx, * @param decl Enumeration field class to register (copied) * @returns 0 if registration went okay, negative value otherwise */ -static int ctx_decl_scope_register_enum(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, const char *name, +static int ctx_decl_scope_register_enum(struct ctx_decl_scope *scope, const char *name, struct ctf_field_class_enum *decl) { - return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_ENUM, name, - &decl->base.base.base); + return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ENUM, name, &decl->base.base.base); } /** @@ -474,11 +461,10 @@ static int ctx_decl_scope_register_enum(struct ctf_visitor_generate_ir *ctx, * @param decl Structure field class to register (copied) * @returns 0 if registration went okay, negative value otherwise */ -static int ctx_decl_scope_register_struct(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, const char *name, +static int ctx_decl_scope_register_struct(struct ctx_decl_scope *scope, const char *name, struct ctf_field_class_struct *decl) { - return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_STRUCT, name, &decl->base); + return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_STRUCT, name, &decl->base); } /** @@ -489,11 +475,10 @@ static int ctx_decl_scope_register_struct(struct ctf_visitor_generate_ir *ctx, * @param decl Variant field class to register * @returns 0 if registration went okay, negative value otherwise */ -static int ctx_decl_scope_register_variant(struct ctf_visitor_generate_ir *ctx, - struct ctx_decl_scope *scope, const char *name, +static int ctx_decl_scope_register_variant(struct ctx_decl_scope *scope, const char *name, struct ctf_field_class_variant *decl) { - return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_VARIANT, name, &decl->base); + return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_VARIANT, name, &decl->base); } /** @@ -1138,8 +1123,8 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, */ qalias = create_class_alias_identifier(ctx, cls_specifier_list, node_field_class_declarator); - nested_decl = ctx_decl_scope_lookup_alias(ctx, ctx->current_scope, - g_quark_to_string(qalias), -1, true); + nested_decl = ctx_decl_scope_lookup_alias(ctx->current_scope, g_quark_to_string(qalias), + -1, true); if (!nested_decl) { _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, "Cannot find class alias: name=\"%s\"", @@ -1464,7 +1449,7 @@ static int visit_field_class_def(struct ctf_visitor_generate_ir *ctx, } } - ret = ctx_decl_scope_register_alias(ctx, ctx->current_scope, g_quark_to_string(qidentifier), + ret = ctx_decl_scope_register_alias(ctx->current_scope, g_quark_to_string(qidentifier), class_decl); if (ret) { _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot register field class alias: name=\"%s\"", @@ -1533,8 +1518,7 @@ static int visit_field_class_alias(struct ctf_visitor_generate_ir *ctx, struct c struct ctf_node, siblings); qalias = create_class_alias_identifier( ctx, alias->u.field_class_alias_name.field_class_specifier_list, node); - ret = ctx_decl_scope_register_alias(ctx, ctx->current_scope, g_quark_to_string(qalias), - class_decl); + ret = ctx_decl_scope_register_alias(ctx->current_scope, g_quark_to_string(qalias), class_decl); if (ret) { _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot register class alias: name=\"%s\"", g_quark_to_string(qalias)); @@ -1659,7 +1643,7 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na goto error; } - *struct_decl = ctx_decl_scope_lookup_struct(ctx, ctx->current_scope, name, -1, true); + *struct_decl = ctx_decl_scope_lookup_struct(ctx->current_scope, name, -1, true); if (!*struct_decl) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Cannot find structure field class: name=\"struct %s\"", name); @@ -1671,7 +1655,7 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na uint64_t min_align_value = 0; if (name) { - if (ctx_decl_scope_lookup_struct(ctx, ctx->current_scope, name, 1, false)) { + if (ctx_decl_scope_lookup_struct(ctx->current_scope, name, 1, false)) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Structure field class already declared in local scope: " "name=\"struct %s\"", @@ -1716,7 +1700,7 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na ctx_pop_scope(ctx); if (name) { - ret = ctx_decl_scope_register_struct(ctx, ctx->current_scope, name, *struct_decl); + ret = ctx_decl_scope_register_struct(ctx->current_scope, name, *struct_decl); if (ret) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Cannot register structure field class in declaration scope: " @@ -1753,8 +1737,7 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n goto error; } - untagged_variant_decl = - ctx_decl_scope_lookup_variant(ctx, ctx->current_scope, name, -1, true); + untagged_variant_decl = ctx_decl_scope_lookup_variant(ctx->current_scope, name, -1, true); if (!untagged_variant_decl) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Cannot find variant field class: name=\"variant %s\"", name); @@ -1765,7 +1748,7 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n struct ctf_node *entry_node; if (name) { - if (ctx_decl_scope_lookup_variant(ctx, ctx->current_scope, name, 1, false)) { + if (ctx_decl_scope_lookup_variant(ctx->current_scope, name, 1, false)) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Variant field class already declared in local scope: " "name=\"variant %s\"", @@ -1794,8 +1777,7 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n ctx_pop_scope(ctx); if (name) { - ret = ctx_decl_scope_register_variant(ctx, ctx->current_scope, name, - untagged_variant_decl); + ret = ctx_decl_scope_register_variant(ctx->current_scope, name, untagged_variant_decl); if (ret) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Cannot register variant field class in declaration scope: " @@ -1956,7 +1938,7 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name goto error; } - *enum_decl = ctx_decl_scope_lookup_enum(ctx, ctx->current_scope, name, -1, true); + *enum_decl = ctx_decl_scope_lookup_enum(ctx->current_scope, name, -1, true); if (!*enum_decl) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot find enumeration field class: " "name=\"enum %s\"", @@ -1975,7 +1957,7 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name }; if (name) { - if (ctx_decl_scope_lookup_enum(ctx, ctx->current_scope, name, 1, false)) { + if (ctx_decl_scope_lookup_enum(ctx->current_scope, name, 1, false)) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Enumeration field class already declared in local scope: " "name=\"enum %s\"", @@ -1987,7 +1969,7 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name if (!container_cls) { integer_decl = ctf_field_class_as_int( - ctx_decl_scope_lookup_alias(ctx, ctx->current_scope, "int", -1, true)); + ctx_decl_scope_lookup_alias(ctx->current_scope, "int", -1, true)); if (!integer_decl) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Cannot find implicit `int` field class alias for enumeration field class."); @@ -2036,7 +2018,7 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name } if (name) { - ret = ctx_decl_scope_register_enum(ctx, ctx->current_scope, name, *enum_decl); + ret = ctx_decl_scope_register_enum(ctx->current_scope, name, *enum_decl); if (ret) { _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Cannot register enumeration field class in declaration scope: " @@ -2075,7 +2057,7 @@ static int visit_field_class_specifier(struct ctf_visitor_generate_ir *ctx, goto error; } - *decl = ctx_decl_scope_lookup_alias(ctx, ctx->current_scope, str->str, -1, true); + *decl = ctx_decl_scope_lookup_alias(ctx->current_scope, str->str, -1, true); if (!*decl) { _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list, "Cannot find field class alias: name=\"%s\"", str->str); @@ -3298,21 +3280,21 @@ static int auto_map_field_to_trace_clock_class(struct ctf_visitor_generate_ir *c struct ctf_field_class *fc) { struct ctf_clock_class *clock_class_to_map_to = NULL; - struct ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); - int ret = 0; uint64_t clock_class_count; if (!fc) { - goto end; + return 0; } if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - goto end; + return 0; } + ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); + if (int_fc->mapped_clock_class) { /* Already mapped */ - goto end; + return 0; } clock_class_count = ctx->ctf_tc->clock_classes->len; @@ -3328,7 +3310,6 @@ static int auto_map_field_to_trace_clock_class(struct ctf_visitor_generate_ir *c BT_ASSERT(clock_class_to_map_to); clock_class_to_map_to->frequency = UINT64_C(1000000000); g_string_assign(clock_class_to_map_to->name, "default"); - BT_ASSERT(ret == 0); g_ptr_array_add(ctx->ctf_tc->clock_classes, clock_class_to_map_to); break; case 1: @@ -3346,15 +3327,13 @@ static int auto_map_field_to_trace_clock_class(struct ctf_visitor_generate_ir *c _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( "Timestamp field found with no mapped clock class, " "but there's more than one clock class in the trace at this point."); - ret = -1; - goto end; + return -1; } BT_ASSERT(clock_class_to_map_to); int_fc->mapped_clock_class = clock_class_to_map_to; -end: - return ret; + return 0; } static int auto_map_fields_to_trace_clock_class(struct ctf_visitor_generate_ir *ctx, @@ -4484,7 +4463,6 @@ end: return ret; } -BT_HIDDEN struct ctf_visitor_generate_ir * ctf_visitor_generate_ir_create(const struct ctf_metadata_decoder_config *decoder_config) { @@ -4508,13 +4486,11 @@ end: return ctx; } -BT_HIDDEN void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor) { ctx_destroy(visitor); } -BT_HIDDEN bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(struct ctf_visitor_generate_ir *ctx) { BT_ASSERT_DBG(ctx); @@ -4526,7 +4502,6 @@ bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(struct ctf_visitor_ge return ctx->trace_class; } -BT_HIDDEN struct ctf_trace_class * ctf_visitor_generate_ir_borrow_ctf_trace_class(struct ctf_visitor_generate_ir *ctx) { @@ -4535,7 +4510,6 @@ ctf_visitor_generate_ir_borrow_ctf_trace_class(struct ctf_visitor_generate_ir *c return ctx->ctf_tc; } -BT_HIDDEN int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node) { int ret = 0;