From 6948c27c2d01de7257a47308c17f7f907ace1747 Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 4 Nov 2014 14:55:40 -0800 Subject: [PATCH] Enumerations are compatible if their type definitions match. --- elab_scope.cc | 3 ++- elaborate.cc | 4 +++- netenum.cc | 13 ++++++++++--- netenum.h | 8 +++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index d352261a6..6e594c241 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -180,7 +180,8 @@ 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, msb, lsb, - enum_type->names->size()); + enum_type->names->size(), + enum_type); use_enum->set_line(enum_type->li); if (scope) diff --git a/elaborate.cc b/elaborate.cc index 17d37c098..95005c140 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -38,6 +38,7 @@ # include "PPackage.h" # include "PSpec.h" # include "netlist.h" +# include "netenum.h" # include "netvector.h" # include "netdarray.h" # include "netparray.h" @@ -2668,7 +2669,8 @@ NetProc* PAssign::elaborate(Design*des, NetScope*scope) const return bl; } - if (lv->enumeration() && (lv->enumeration() != rv->enumeration())) { + if (lv->enumeration() && + ! lv->enumeration()->matches(rv->enumeration())) { cerr << get_fileline() << ": error: " << "Enumeration type mismatch in assignment." << endl; des->errors += 1; diff --git a/netenum.cc b/netenum.cc index cab73a55c..0ec7ca33d 100644 --- a/netenum.cc +++ b/netenum.cc @@ -24,9 +24,11 @@ using namespace std; netenum_t::netenum_t(ivl_variable_type_t btype, bool signed_flag, - bool integer_flag, long msb, long lsb, size_t name_count) -: base_type_(btype), signed_flag_(signed_flag), integer_flag_(integer_flag), - msb_(msb), lsb_(lsb), names_(name_count), bits_(name_count) + bool integer_flag, long msb, long lsb, size_t name_count, + enum_type_t*enum_type) +: base_type_(btype), enum_type_(enum_type), signed_flag_(signed_flag), + integer_flag_(integer_flag), msb_(msb), lsb_(lsb), + names_(name_count), bits_(name_count) { } @@ -161,3 +163,8 @@ perm_string netenum_t::bits_at(size_t idx) const { return bits_[idx]; } + +bool netenum_t::matches(const netenum_t*other) const +{ + return enum_type_ == other->enum_type_; +} diff --git a/netenum.h b/netenum.h index 64c2aac6a..8ff8a9063 100644 --- a/netenum.h +++ b/netenum.h @@ -29,12 +29,14 @@ 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, long msb, long lsb, - size_t name_count); + size_t name_count, enum_type_t*enum_type); ~netenum_t(); virtual ivl_variable_type_t base_type() const; @@ -67,8 +69,12 @@ class netenum_t : public LineInfo, public ivl_type_s { perm_string name_at(size_t idx) const; perm_string bits_at(size_t idx) const; + // Check if two enumerations have the same definition. + bool matches(const netenum_t*other) const; + private: ivl_variable_type_t base_type_; + enum_type_t*enum_type_; bool signed_flag_; bool integer_flag_; long msb_, lsb_;