More refined check for enumeration width and constant width

This commit is contained in:
Cary R 2014-11-04 12:09:48 -08:00
parent 2e8c4e3dbc
commit 2e9c4cde55
1 changed files with 12 additions and 15 deletions

View File

@ -221,7 +221,7 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
if (val_const == 0) { if (val_const == 0) {
cerr << use_enum->get_fileline() cerr << use_enum->get_fileline()
<< ": error: Enumeration expression for " << ": error: Enumeration expression for "
<< cur->name <<" is not an integral constant." << cur->name <<" is not an integer constant."
<< endl; << endl;
des->errors += 1; des->errors += 1;
continue; continue;
@ -238,21 +238,18 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
<< " can not have an undefined value." << endl; << " can not have an undefined value." << endl;
des->errors += 1; des->errors += 1;
} }
// If the literal constant has a defined width then it // If this is a literal constant and it has a defined
// must match the enumeration width. In strict mode // width then the width must match the enumeration width.
// unsized integers are incorrectly given a defined size if (PENumber *tmp = dynamic_cast<PENumber*>(cur->parm)) {
// of integer width so handle that. Unfortunately this if (tmp->value().has_len() &&
// allows 32'd0 to work just like 0 which is wrong. (tmp->value().len() != enum_width)) {
if (dynamic_cast<PENumber*>(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() cerr << use_enum->get_fileline()
<< ": error: Enumeration name " << cur->name << ": error: Enumeration name " << cur->name
<< " has an incorrectly sized constant." << endl; << " has an incorrectly sized constant."
<< endl;
des->errors += 1; des->errors += 1;
} }
}
// If we are padding/truncating a negative value for an // If we are padding/truncating a negative value for an
// unsigned enumeration that is an error or if the new // unsigned enumeration that is an error or if the new