Skip to content

Commit 45db0db

Browse files
Check that port default values are constant expressions.
1 parent c7eaa06 commit 45db0db

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

elaborate.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,14 +1320,20 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const
13201320

13211321
for (unsigned idx = 0 ; idx < pins.size() ; idx += 1) {
13221322
bool unconnected_port = false;
1323+
bool using_default = false;
13231324

13241325
perm_string port_name = rmod->get_port_name(idx);
13251326

13261327
// If the port is unconnected, substitute the default
13271328
// value. The parser ensures that a default value only
13281329
// exists for input ports.
1329-
if (pins[idx] == 0)
1330-
pins[idx] = rmod->get_port_default_value(idx);
1330+
if (pins[idx] == 0) {
1331+
PExpr*default_value = rmod->get_port_default_value(idx);
1332+
if (default_value) {
1333+
pins[idx] = default_value;
1334+
using_default = true;
1335+
}
1336+
}
13311337

13321338
// Skip unconnected module ports. This happens when a
13331339
// null parameter is passed in and there is no default
@@ -1511,10 +1517,11 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const
15111517
port is actually empty on the inside. We assume
15121518
in that case that the port is input. */
15131519

1514-
NetExpr*tmp_expr = elab_and_eval(des, scope, pins[idx], -1);
1520+
NetExpr*tmp_expr = elab_and_eval(des, scope, pins[idx], -1, using_default);
15151521
if (tmp_expr == 0) {
15161522
cerr << pins[idx]->get_fileline()
1517-
<< ": error: Failed to elaborate port expression."
1523+
<< ": error: Failed to elaborate port "
1524+
<< (using_default ? "default value." : "expression.")
15181525
<< endl;
15191526
des->errors += 1;
15201527
continue;

0 commit comments

Comments
 (0)