diff --git a/elab_scope.cc b/elab_scope.cc index 72a367ad0..a93c9a08c 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -213,6 +213,16 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope, des->errors += 1; } + // The enumeration value must be unique. + perm_string dup_name = use_enum->find_value(cur_value); + if (dup_name) { + cerr << use_enum->get_fileline() + << ": error: Enumeration name " + << cur->name << " and " << dup_name + << " have the same value: " << cur_value << endl; + des->errors += 1; + } + // The values are explicitly sized to the width of the // base type of the enumeration. verinum tmp_val (0); diff --git a/netenum.cc b/netenum.cc index 01bab4c00..2f5f14aed 100644 --- a/netenum.cc +++ b/netenum.cc @@ -55,6 +55,22 @@ netenum_t::iterator netenum_t::find_name(perm_string name) const return names_map_.find(name); } +/* + * Check to see if the given value is already in the enumeration mapping. + */ +perm_string netenum_t::find_value(const verinum&val) const +{ + perm_string res; + for(netenum_t::iterator cur = names_map_.begin(); + cur != names_map_.end(); cur++) { + if (cur->second == val) { + res = cur->first; + break; + } + } + return res; +} + netenum_t::iterator netenum_t::end_name() const { return names_map_.end(); diff --git a/netenum.h b/netenum.h index b88f75918..81080f9e3 100644 --- a/netenum.h +++ b/netenum.h @@ -50,6 +50,7 @@ class netenum_t : public LineInfo { typedef std::map::const_iterator iterator; iterator find_name(perm_string name) const; iterator end_name() const; + perm_string find_value(const verinum&val) const; // These methods roughly match the .first() and .last() methods. iterator first_name() const; diff --git a/parse.y b/parse.y index 0f96c5b02..2bab54732 100644 --- a/parse.y +++ b/parse.y @@ -117,7 +117,7 @@ static list* make_range_from_width(uint64_t wid) } /* - * Make a rqange vector from an existing pair of expressions. + * Make a range vector from an existing pair of expressions. */ static vector* make_range_vector(list*that) {