Skip to content

Commit 6948c27

Browse files
committed
Enumerations are compatible if their type definitions match.
1 parent 2e9c4cd commit 6948c27

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

elab_scope.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
180180
netenum_t*use_enum = new netenum_t(enum_type->base_type,
181181
enum_type->signed_flag,
182182
enum_type->integer_flag, msb, lsb,
183-
enum_type->names->size());
183+
enum_type->names->size(),
184+
enum_type);
184185

185186
use_enum->set_line(enum_type->li);
186187
if (scope)

elaborate.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# include "PPackage.h"
3939
# include "PSpec.h"
4040
# include "netlist.h"
41+
# include "netenum.h"
4142
# include "netvector.h"
4243
# include "netdarray.h"
4344
# include "netparray.h"
@@ -2668,7 +2669,8 @@ NetProc* PAssign::elaborate(Design*des, NetScope*scope) const
26682669
return bl;
26692670
}
26702671

2671-
if (lv->enumeration() && (lv->enumeration() != rv->enumeration())) {
2672+
if (lv->enumeration() &&
2673+
! lv->enumeration()->matches(rv->enumeration())) {
26722674
cerr << get_fileline() << ": error: "
26732675
<< "Enumeration type mismatch in assignment." << endl;
26742676
des->errors += 1;

netenum.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
using namespace std;
2525

2626
netenum_t::netenum_t(ivl_variable_type_t btype, bool signed_flag,
27-
bool integer_flag, long msb, long lsb, size_t name_count)
28-
: base_type_(btype), signed_flag_(signed_flag), integer_flag_(integer_flag),
29-
msb_(msb), lsb_(lsb), names_(name_count), bits_(name_count)
27+
bool integer_flag, long msb, long lsb, size_t name_count,
28+
enum_type_t*enum_type)
29+
: base_type_(btype), enum_type_(enum_type), signed_flag_(signed_flag),
30+
integer_flag_(integer_flag), msb_(msb), lsb_(lsb),
31+
names_(name_count), bits_(name_count)
3032
{
3133
}
3234

@@ -161,3 +163,8 @@ perm_string netenum_t::bits_at(size_t idx) const
161163
{
162164
return bits_[idx];
163165
}
166+
167+
bool netenum_t::matches(const netenum_t*other) const
168+
{
169+
return enum_type_ == other->enum_type_;
170+
}

netenum.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929

3030
class NetScope;
3131

32+
struct enum_type_t;
33+
3234
class netenum_t : public LineInfo, public ivl_type_s {
3335

3436
public:
3537
explicit netenum_t(ivl_variable_type_t base_type, bool signed_flag,
3638
bool isint_flag, long msb, long lsb,
37-
size_t name_count);
39+
size_t name_count, enum_type_t*enum_type);
3840
~netenum_t();
3941

4042
virtual ivl_variable_type_t base_type() const;
@@ -67,8 +69,12 @@ class netenum_t : public LineInfo, public ivl_type_s {
6769
perm_string name_at(size_t idx) const;
6870
perm_string bits_at(size_t idx) const;
6971

72+
// Check if two enumerations have the same definition.
73+
bool matches(const netenum_t*other) const;
74+
7075
private:
7176
ivl_variable_type_t base_type_;
77+
enum_type_t*enum_type_;
7278
bool signed_flag_;
7379
bool integer_flag_;
7480
long msb_, lsb_;

0 commit comments

Comments
 (0)