Separate instances with and without parameter overrides

The module-instance grammar uses the optional `parameter_value_opt` rule
for both `M #(1) i_m();` and `M i_m();`. The former follows an instance
grammar path identified by `#`, while the latter starts with the same
two-identifier pattern as a named variable declaration such as `M value;`.

Separate these paths so that instances without overrides can later share
a grammar rule with named variable declarations, without involving the
parameter-override path in that disambiguation:

1) Previously, both examples matched the same `module_item` production.
   `parameter_value_opt` reduced `#(1)` for the first example and an empty
   production for the second.

2) Replace it with the nonempty `parameter_value_assignment` rule. The
   production using this rule still parses `M #(1) i_m();`.

3) Add a separate `module_item` production going directly from
   `IDENTIFIER` to `gate_instance_list`. This parses `M i_m();` without
   reducing an empty parameter rule.

Both productions still build instances. The accepted parameter overrides,
UDP delays and instance syntax are unchanged.

Signed-off-by: Lars-Peter Clausen <[email protected]>
This commit is contained in:
Lars-Peter Clausen
2026-09-07 16:29:29 -07:00
parent a5d904e22f
commit 7ca7e67aac
+16 -6
View File
@@ -1265,7 +1265,7 @@ Module::port_t *module_declare_interface_port(const YYLTYPE&loc, char *type,
%type <gatetype> gatetype switchtype
%type <porttype> port_direction port_direction_opt
%type <vartype> integer_vector_type integer_vector_type_no_reg
%type <parmvalue> parameter_value_opt
%type <parmvalue> parameter_value_assignment
%type <event_exprs> event_expression_list
%type <event_expr> event_expression
@@ -5813,19 +5813,31 @@ module_item
but then can have parameter lists. */
| attribute_list_opt
IDENTIFIER parameter_value_opt gate_instance_list ';'
IDENTIFIER parameter_value_assignment gate_instance_list ';'
{ perm_string tmp1 = lex_strings.make($2);
pform_make_modgates(@2, tmp1, $3, $4, $1);
delete[]$2;
}
| attribute_list_opt
IDENTIFIER parameter_value_opt error ';'
IDENTIFIER parameter_value_assignment error ';'
{ yyerror(@2, "error: Invalid module instantiation");
delete[]$2;
if ($1) delete $1;
}
| attribute_list_opt IDENTIFIER gate_instance_list ';'
{ auto type_name = lex_strings.make($2);
pform_make_modgates(@2, type_name, nullptr, $3, $1);
delete[]$2;
}
| attribute_list_opt IDENTIFIER error ';'
{ yyerror(@2, "error: Invalid module instantiation");
delete[]$2;
delete $1;
}
/* Continuous assignment can have an optional drive strength, then
an optional delay3 that applies to all the assignments in the
cont_assign_list. */
@@ -6338,7 +6350,7 @@ from_exclude : K_from { $$ = false; } | K_exclude { $$ = true; } ;
The parameter value by name syntax is OVI enhancement BTF-B06 as
approved by WG1364 on 6/28/1998. */
parameter_value_opt
parameter_value_assignment
: '#' '(' expression_list_with_nuls ')'
{ struct parmvalue_t*tmp = new struct parmvalue_t;
tmp->by_order = $3;
@@ -6378,8 +6390,6 @@ parameter_value_opt
{ yyerror(@1, "error: Syntax error in parameter value assignment list.");
$$ = 0;
}
|
{ $$ = 0; }
;
named_expression