From fabff5ef5fc5d2a93f6cbbc3cac0afb46973fad9 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 19 Mar 2022 15:03:53 +0100 Subject: [PATCH] Restrict enum compatibility to the same scope An enum data type declared in a module is not compatible between different instances of the module. The type is unique in each hierarchical instance scope. The type can for example depend on module parameters which would result in conflicting definitions. This is defined in section 6.22 ("Type compatibility") of the LRM (1800-2017). At the moment enum compatibility is checked by comparing the enum_type_t. But the enum_type_t is shared among the netenum_t that are created for each module instance and gives the wrong result. Since there is exactly one netenum_t created for each enum and each instantiated scope use this to check if the data type of two enum type signals is compatible. Signed-off-by: Lars-Peter Clausen --- elab_scope.cc | 3 +-- netenum.cc | 10 ++++------ netenum.h | 5 +---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index aacedcc63..fe39506e9 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -186,8 +186,7 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope, netenum_t*use_enum = new netenum_t(enum_type->base_type, enum_type->signed_flag, enum_type->integer_flag, range, - enum_type->names->size(), - enum_type); + enum_type->names->size()); use_enum->set_line(*enum_type); scope->add_enumeration_set(enum_type, use_enum); diff --git a/netenum.cc b/netenum.cc index bb53088bc..7ff455926 100644 --- a/netenum.cc +++ b/netenum.cc @@ -24,11 +24,9 @@ using namespace std; netenum_t::netenum_t(ivl_variable_type_t btype, bool signed_flag, - bool integer_flag, const netrange_t &range, size_t name_count, - enum_type_t*enum_type) -: base_type_(btype), enum_type_(enum_type), signed_flag_(signed_flag), - integer_flag_(integer_flag), range_(range), - names_(name_count), bits_(name_count) + bool integer_flag, const netrange_t &range, size_t name_count) +: base_type_(btype), signed_flag_(signed_flag), integer_flag_(integer_flag), + range_(range), names_(name_count), bits_(name_count) { } @@ -159,5 +157,5 @@ perm_string netenum_t::bits_at(size_t idx) const bool netenum_t::matches(const netenum_t*other) const { - return enum_type_ == other->enum_type_; + return this == other; } diff --git a/netenum.h b/netenum.h index b05675cfe..94f7cd8cd 100644 --- a/netenum.h +++ b/netenum.h @@ -29,14 +29,12 @@ class NetScope; -struct enum_type_t; - class netenum_t : public LineInfo, public ivl_type_s { public: explicit netenum_t(ivl_variable_type_t base_type, bool signed_flag, bool isint_flag, const netrange_t &range, - size_t name_count, enum_type_t*enum_type); + size_t name_count); ~netenum_t(); virtual ivl_variable_type_t base_type() const; @@ -74,7 +72,6 @@ class netenum_t : public LineInfo, public ivl_type_s { private: ivl_variable_type_t base_type_; - enum_type_t*enum_type_; bool signed_flag_; bool integer_flag_; netrange_t range_;