Skip to content

Commit

Permalink
Check for primitive port mismatches and other error cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
caryr committed Dec 9, 2024
1 parent b745119 commit 8edf14a
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 25 deletions.
1 change: 1 addition & 0 deletions ivtest/gold/br_gh1175a.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./ivltests/br_gh1175a.v:1: error: The UDP input port count (1) does not match the number of input table entries (6) in primitive "id_0".
1 change: 1 addition & 0 deletions ivtest/gold/br_gh1175b.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./ivltests/br_gh1175b.v:1: error: The UDP input port count (1) does not match the number of input table entries (6) in primitive "id_0".
4 changes: 4 additions & 0 deletions ivtest/gold/br_gh1175c.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./ivltests/br_gh1175c.v:3: syntax error
./ivltests/br_gh1175c.v:3: errors in UDP table
./ivltests/br_gh1175c.v:1: error: Invalid table for UDP primitive id_0.

4 changes: 4 additions & 0 deletions ivtest/gold/br_gh1175d.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./ivltests/br_gh1175d.v:3: syntax error
./ivltests/br_gh1175d.v:3: errors in UDP table
./ivltests/br_gh1175d.v:1: error: Invalid table for UDP primitive id_0.

4 changes: 4 additions & 0 deletions ivtest/gold/br_gh1175e.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./ivltests/br_gh1175e.v:3: syntax error
./ivltests/br_gh1175e.v:3: errors in UDP table
./ivltests/br_gh1175e.v:1: error: Invalid table for UDP primitive id_0.

2 changes: 2 additions & 0 deletions ivtest/gold/br_gh1175f.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./ivltests/br_gh1175f.v:7: error: Primitive id_0 was already declared here: ./ivltests/br_gh1175f.v:1

5 changes: 5 additions & 0 deletions ivtest/ivltests/br_gh1175a.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primitive id_0(output id_2, input id_1);
table
? 1 ? 0 0 0 : 0;
endtable
endprimitive
5 changes: 5 additions & 0 deletions ivtest/ivltests/br_gh1175b.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primitive id_0(output reg id_2, input id_1);
table
? 1 ? 0 0 0 : 0 : 0;
endtable
endprimitive
5 changes: 5 additions & 0 deletions ivtest/ivltests/br_gh1175c.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primitive id_0(output id_2, input id_1);
table
0 : 0 0;
endtable
endprimitive
5 changes: 5 additions & 0 deletions ivtest/ivltests/br_gh1175d.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primitive id_0(output reg id_2, input id_1);
table
0 : 0 0 : 0;
endtable
endprimitive
5 changes: 5 additions & 0 deletions ivtest/ivltests/br_gh1175e.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primitive id_0(output reg id_2, input id_1);
table
0 : 0 : 0 0;
endtable
endprimitive
11 changes: 11 additions & 0 deletions ivtest/ivltests/br_gh1175f.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
primitive id_0(output reg id_2, input id_1);
table
0 : 0 : 0;
endtable
endprimitive

primitive id_0(output reg id_2, input id_1);
table
1 : 0 : 0;
endtable
endprimitive
6 changes: 6 additions & 0 deletions ivtest/regress-vlg.list
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ br_gh788 normal,-gno-io-range-error,-Wno-anachronisms ivltests gold=br_gh788.go
br_gh793 normal ivltests
br_gh827 normal ivltests gold=br_gh827.gold
br_gh889 normal,-gspecify ivltests gold=br_gh889.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
br_gh1175d CE ivltests gold=br_gh1175d.gold
br_gh1175e CE ivltests gold=br_gh1175e.gold
br_gh1175f CE ivltests gold=br_gh1175f.gold
br_gh1178a CE ivltests gold=br_gh1178a.gold
br_gh1178b normal ivltests
br_gh1178c normal ivltests
Expand Down
5 changes: 3 additions & 2 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -6703,7 +6703,8 @@ statement_item /* This is roughly statement_item in the LRM */
current_block_stack.push(tmp);
}
block_item_decls_opt
{ if (!$2) {
{
if (!$2) {
if ($4) {
pform_requires_sv(@4, "Variable declaration in unnamed block");
} else {
Expand Down Expand Up @@ -7133,7 +7134,7 @@ udp_body
}
| K_table error K_endtable
{ lex_end_table();
yyerror(@2, "Errors in UDP table");
yyerror(@2, "errors in UDP table");
yyerrok;
$$ = 0;
}
Expand Down
53 changes: 30 additions & 23 deletions pform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ static void process_udp_table(PUdp*udp, list<string>*table,
placed in the PUdp object.
The table strings are made up by the parser to be two or
three substrings separated by ';', i.e.:
three substrings separated by ':', i.e.:
0101:1:1 (synchronous device entry)
0101:0 (combinational device entry)
Expand All @@ -1814,40 +1814,36 @@ static void process_udp_table(PUdp*udp, list<string>*table,
output.resize(table->size());

{ unsigned idx = 0;
for (list<string>::iterator cur = table->begin()
; cur != table->end() ; ++ cur , idx += 1) {
for (list<string>::iterator cur = table->begin() ;
cur != table->end() ; ++cur , idx += 1) {
string tmp = *cur;

/* Pull the input values from the string. */
assert(tmp.find(':') == (udp->ports.size() - 1));
if (tmp.find(':') != (udp->ports.size()-1)) {
cerr << loc << ": error: "
<< "The UDP input port count (" << (udp->ports.size()-1)
<< ") does not match the number of input table entries ("
<< tmp.find(':') << ") in primitive \""
<< udp->name_ << "\"." << endl;
error_count += 1;
break;
}
input[idx] = tmp.substr(0, udp->ports.size()-1);
tmp = tmp.substr(udp->ports.size()-1);

assert(tmp[0] == ':');

/* If this is a synchronous device, get the current
output string. */
if (synchronous_flag) {
if (tmp.size() != 4) {
cerr << loc << ": error: "
<< "Invalid table format for"
<< " sequential primitive." << endl;
error_count += 1;
break;
}
assert(tmp[0] == ':');
assert(tmp.size() == 4);
current[idx] = tmp[1];
tmp = tmp.substr(2);

} else if (tmp.size() != 2) {
cerr << loc << ": error: "
<< "Invalid table format for"
<< " combinational primitive." << endl;
error_count += 1;
break;
}

/* Finally, extract the desired output. */
assert(tmp[0] == ':');
assert(tmp.size() == 2);
output[idx] = tmp[1];
}
Expand Down Expand Up @@ -2101,7 +2097,11 @@ void pform_make_udp(const struct vlltype&loc, perm_string name,

// Put the primitive into the primitives table
if (pform_primitives[name]) {
VLerror("error: UDP primitive already exists.");
ostringstream msg;
msg << "error: Primitive " << name << " was already declared here: "
<< pform_primitives[name]->get_fileline() << endl;
// Some compilers warn if there is just a single C string.
VLerror(loc, msg.str().c_str(), "");

} else {
PUdp*udp = new PUdp(name, pins.size());
Expand All @@ -2115,11 +2115,18 @@ void pform_make_udp(const struct vlltype&loc, perm_string name,
udp->ports[idx] = pins[idx]->basename();

ivl_assert(loc, udp);
ivl_assert(loc, table);
process_udp_table(udp, table, loc);
udp->initial = init;
if (table) {
process_udp_table(udp, table, loc);
udp->initial = init;

pform_primitives[name] = udp;
pform_primitives[name] = udp;
} else {
ostringstream msg;
msg << "error: Invalid table for UDP primitive " << name
<< "." << endl;
// Some compilers warn if there is just a single C string.
VLerror(loc, msg.str().c_str(), "");
}
}

delete parms;
Expand Down

0 comments on commit 8edf14a

Please sign in to comment.