Improve error messages when bad code is passed to the parser

This commit is contained in:
Cary R 2025-07-21 14:46:01 -07:00
parent c7d37bcc21
commit b979441de2
8 changed files with 69 additions and 1 deletions

View File

@ -544,6 +544,10 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope,
if (sig == 0) {
cerr << get_fileline() << ": error: Net " << path_
<< " is not defined in this context." << endl;
if (sr.is_found()) {
cerr << sr.scope->get_fileline() << ": : Found a "
<< sr.result_type() << " with this name here." << endl;
}
if (sr.decl_after_use) {
cerr << sr.decl_after_use->get_fileline() << ": : "
"A symbol with that name was declared here. "
@ -1161,6 +1165,10 @@ NetNet*PEIdent::elaborate_unpacked_net(Design*des, NetScope*scope) const
if (!sr.net) {
cerr << get_fileline() << ": error: Net " << path_
<< " is not defined in this context." << endl;
if (sr.is_found()) {
cerr << sr.scope->get_fileline() << ": : Found a "
<< sr.result_type() << " with this name here." << endl;
}
if (sr.decl_after_use) {
cerr << sr.decl_after_use->get_fileline() << ": : "
"A symbol with that name was declared here. "

View File

@ -0,0 +1,4 @@
./ivltests/br_gh1174a.v:14: error: generate else is missing matching if.
./ivltests/br_gh1174a.v:20: syntax error
./ivltests/br_gh1174a.v:20: error: Invalid module instantiation
./ivltests/br_gh1174a.v:15: error: generate else is missing matching if.

View File

@ -0,0 +1,3 @@
./ivltests/br_gh1174b.v:10: error: Net id_8 is not defined in this context.
./ivltests/br_gh1174b.v:1: : Found a parameter with this name here.
1 error(s) during elaboration.

View File

@ -0,0 +1,29 @@
module module_0 #(
parameter id_1 = 32'd92,
parameter id_3 = 32'd50,
parameter id_4 = 32'd25,
parameter id_8 = 32'd99,
parameter id_9 = 32'd40
) ();
// Was this intended to be a generate case or procedural case?
case ((1))
1: begin
if (id_3) begin
// else with no if or missing end.
else begin
end else begin
if (1)
// This is parsed as a generate case so no procedural
// assignment is allowed. Plus you cannot assign
// to a parameter.
id_3 = id_9[1];
end
// This is the closing for the begin above, but the
// else likely broke the sequence. So there is now
// an extra end.
end
end
endcase
endmodule

View File

@ -0,0 +1,12 @@
module module_0 #(
parameter id_1 = 32'd92,
parameter id_3 = 32'd50,
parameter id_4 = 32'd25,
parameter id_8 = 32'd99,
parameter id_9 = 32'd40
) ();
// Cannot assign to a parameter.
assign id_8 = 1;
endmodule

View File

@ -357,6 +357,8 @@ br_gh956a CE ivltests gold=br_gh956a.gold
br_gh956b CE ivltests gold=br_gh956b.gold
br_gh1117 CE ivltests gold=br_gh1117.gold
br_gh1173 CE ivltests gold=br_gh1173.gold
br_gh1174a CE ivltests gold=br_gh1174a.gold
br_gh1174b CE ivltests gold=br_gh1174b.gold
br_gh1175a CE ivltests gold=br_gh1175a.gold
br_gh1175b CE ivltests gold=br_gh1175b.gold
br_gh1175c CE ivltests gold=br_gh1175c.gold

View File

@ -1,7 +1,7 @@
#ifndef IVL_netmisc_H
#define IVL_netmisc_H
/*
* Copyright (c) 1999-2024 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2025 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -68,6 +68,14 @@ struct symbol_search_results {
return false;
}
inline const char *result_type() const {
if (net) return "net";
if (eve) return "named event";
if (par_val) return "parameter";
if (scope) return "scope";
return "nothing found";
}
// Scope where symbol was located. This is set in all cases,
// assuming the search succeeded.
NetScope*scope;

View File

@ -5241,6 +5241,8 @@ module_item
generate_block %prec less_than_K_else
{ pform_endgenerate(true); }
| K_else generate_block { yyerror(@1, "error: generate else is missing matching if."); }
| K_case '(' expression ')'
{ pform_start_generate_case(@1, $3); }
generate_case_items