Enumerations are compatible if their type definitions match.

This commit is contained in:
Cary R 2014-11-04 14:55:40 -08:00
parent 2e9c4cde55
commit 6948c27c2d
4 changed files with 22 additions and 6 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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_;
}

View File

@ -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_;