From 2e9c4cde55fd73c39cd8d64c38defa94f5a0dde4 Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 4 Nov 2014 12:09:48 -0800 Subject: [PATCH] More refined check for enumeration width and constant width --- elab_scope.cc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index a28f116c2..d352261a6 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -221,7 +221,7 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope, if (val_const == 0) { cerr << use_enum->get_fileline() << ": error: Enumeration expression for " - << cur->name <<" is not an integral constant." + << cur->name <<" is not an integer constant." << endl; des->errors += 1; continue; @@ -238,20 +238,17 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope, << " can not have an undefined value." << endl; des->errors += 1; } - // If the literal constant has a defined width then it - // must match the enumeration width. In strict mode - // unsized integers are incorrectly given a defined size - // of integer width so handle that. Unfortunately this - // allows 32'd0 to work just like 0 which is wrong. - if (dynamic_cast(cur->parm) && - cur_value.has_len() && - (cur_value.len() != enum_width) && - (! gn_strict_expr_width_flag || - (cur_value.len() != integer_width))) { - cerr << use_enum->get_fileline() - << ": error: Enumeration name " << cur->name - << " has an incorrectly sized constant." << endl; - des->errors += 1; + // If this is a literal constant and it has a defined + // width then the width must match the enumeration width. + if (PENumber *tmp = dynamic_cast(cur->parm)) { + if (tmp->value().has_len() && + (tmp->value().len() != enum_width)) { + cerr << use_enum->get_fileline() + << ": error: Enumeration name " << cur->name + << " has an incorrectly sized constant." + << endl; + des->errors += 1; + } } // If we are padding/truncating a negative value for an