From 7ca7e67aacf9463ee5c0f0860b86cf2b75eaed36 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 6 Sep 2026 22:11:41 -0700 Subject: [PATCH] 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 --- parse.y | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/parse.y b/parse.y index bd972d244..87bfebbcb 100644 --- a/parse.y +++ b/parse.y @@ -1265,7 +1265,7 @@ Module::port_t *module_declare_interface_port(const YYLTYPE&loc, char *type, %type gatetype switchtype %type port_direction port_direction_opt %type integer_vector_type integer_vector_type_no_reg -%type parameter_value_opt +%type parameter_value_assignment %type event_expression_list %type 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