Fix for br992 - prevent assertion/crash on declarations outside a module.

parse.y has been updated to allow declarations outside a module (legal
in SystemVerilog), but not all types of declaration are supported yet.
Output a sorry or error message as appropriate.
This commit is contained in:
Martin Whitaker 2015-08-20 23:55:00 +01:00
parent 13bff8c50d
commit e25cdf86ac
1 changed files with 25 additions and 1 deletions

View File

@ -2591,6 +2591,15 @@ void pform_makewire(const struct vlltype&li,
NetNet::Type type, NetNet::Type type,
data_type_t*data_type) data_type_t*data_type)
{ {
if ((lexical_scope == 0) && (generation_flag < GN_VER2005_SV)) {
VLerror(li, "error: variable declarations must be contained within a module.");
return;
}
if (lexical_scope == 0) {
VLerror(li, "sorry: variable declarations in the $root scope are not yet supported.");
return;
}
list<perm_string>*names = new list<perm_string>; list<perm_string>*names = new list<perm_string>;
for (list<decl_assignment_t*>::iterator cur = assign_list->begin() for (list<decl_assignment_t*>::iterator cur = assign_list->begin()
@ -2887,6 +2896,14 @@ void pform_set_parameter(const struct vlltype&loc,
LexicalScope::range_t*value_range) LexicalScope::range_t*value_range)
{ {
LexicalScope*scope = lexical_scope; LexicalScope*scope = lexical_scope;
if ((scope == 0) && (generation_flag < GN_VER2005_SV)) {
VLerror(loc, "error: parameter declarations must be contained within a module.");
return;
}
if (scope == 0) {
VLerror(loc, "sorry: parameter declarations in the $root scope are not yet supported.");
return;
}
if (scope == pform_cur_generate) { if (scope == pform_cur_generate) {
VLerror("parameter declarations are not permitted in generate blocks"); VLerror("parameter declarations are not permitted in generate blocks");
return; return;
@ -2954,7 +2971,14 @@ void pform_set_localparam(const struct vlltype&loc,
bool signed_flag, list<pform_range_t>*range, PExpr*expr) bool signed_flag, list<pform_range_t>*range, PExpr*expr)
{ {
LexicalScope*scope = lexical_scope; LexicalScope*scope = lexical_scope;
ivl_assert(loc, scope); if ((scope == 0) && (generation_flag < GN_VER2005_SV)) {
VLerror(loc, "error: localparam declarations must be contained within a module.");
return;
}
if (scope == 0) {
VLerror(loc, "sorry: localparam declarations in the $root scope are not yet supported.");
return;
}
// Check if the localparam name is already in the dictionary. // Check if the localparam name is already in the dictionary.
if (scope->localparams.find(name) != scope->localparams.end()) { if (scope->localparams.find(name) != scope->localparams.end()) {