Skip to content

Commit 12187bc

Browse files
authored
Merge pull request #1499 from diffblue/gate-instance-grammar
Verilog: fix grammar for gate instances
2 parents 81cc8a0 + 734901a commit 12187bc

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

regression/verilog/nets/implicit2.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module main;
33
// Implicit nets are allowed in the port connection list of a module.
44
// The type of the implicit net is _not_ the type of the port,
55
// but an "implicit scalar net of default net type".
6-
and [3:0] (O, A, B);
6+
and my_instance[3:0] (O, A, B);
77

88
always assert final (O == (A & B));
99
always assert final ($bits(O) == 1);

regression/verilog/nets/implicit6.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module main;
55
// Implicit nets are allowed in the port connection list of a module.
66
// The type of the implicit net is _not_ the type of the port,
77
// but an "implicit scalar net of default net type".
8-
and [P:0] (O, A, B);
8+
and my_instance[P:0] (O, A, B);
99

1010
assert final ($bits(O) == 1);
1111

src/verilog/parser.y

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,20 +3108,31 @@ gate_instance_brace:
31083108
;
31093109

31103110
gate_instance:
3111-
name_of_gate_instance_opt range_opt '(' list_of_module_connections_opt ')'
3112-
{ init($$, ID_inst); addswap($$, ID_base_name, $1);
3113-
swapop($$, $4);
3114-
addswap($$, ID_range, $2);
3111+
name_of_gate_instance_opt '(' list_of_module_connections_opt ')'
3112+
{ $$ = $1;
3113+
swapop($$, $3);
31153114
}
31163115
;
31173116

31183117
name_of_gate_instance_opt:
31193118
/* Optional */
3120-
{ init($$, "$_&#ANON" + PARSER.get_next_id()); }
3119+
{ init($$, ID_inst);
3120+
stack_expr($$).set(ID_base_name, "$_&#ANON" + PARSER.get_next_id()); }
31213121
| name_of_gate_instance
31223122
;
31233123

3124-
name_of_gate_instance: TOK_NON_TYPE_IDENTIFIER;
3124+
name_of_gate_instance:
3125+
TOK_NON_TYPE_IDENTIFIER unpacked_dimension_brace
3126+
{ init($$, ID_inst);
3127+
addswap($$, ID_base_name, $1);
3128+
if(stack_expr($2).is_not_nil())
3129+
{
3130+
auto &range = stack_expr($$).add(ID_range);
3131+
range = stack_expr($2).find(ID_range);
3132+
range.id(ID_range);
3133+
}
3134+
}
3135+
;
31253136

31263137
// System Verilog standard 1800-2017
31273138
// A.4.1.1 Module instantiation

0 commit comments

Comments
 (0)