Skip to content

Commit

Permalink
Permit assignment patterns as lvalues of assignments.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 325274727
  • Loading branch information
fangism authored and hzeller committed Aug 6, 2020
1 parent c1db566 commit 650c6cc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions verilog/parser/verilog.y
Original file line number Diff line number Diff line change
Expand Up @@ -5292,7 +5292,9 @@ signed_unsigned_opt
| /* empty */
{ $$ = nullptr; }
;

lpvalue
/* intended to cover 'net_lvalue' and 'variable_lvalue' in LRM */
: reference_or_call
{ $$ = MakeTaggedNode(N::kLPValue, $1); }
/* Unless functions can return by reference, calls should not be permitted
Expand All @@ -5304,9 +5306,16 @@ lpvalue
/* TODO(fangism): For lpvalue, verify that $1 is of the form
* '{' expression_list_proper '}' and that each item in the list is an lvalue.
*/
| assignment_pattern
/* for 'assignment_pattern_net_lvalue'
* and 'assignment_pattern_variable_lvalue'.
* TODO(fangism): verify that elements are lpvalue (not just any expr).
*/
{ $$ = MakeTaggedNode(N::kLPValue, $1); }
| streaming_concatenation
{ $$ = MakeTaggedNode(N::kLPValue, $1); }
;

cont_assign
: lpvalue '=' expression
{ $$ = MakeTaggedNode(N::kNetVariableAssignment, $1, $2, $3); }
Expand Down
37 changes: 37 additions & 0 deletions verilog/parser/verilog_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,43 @@ static const char* kFunctionTests[] = {
"function void unpack_id(utils_pkg::bytestream_t bytes);\n"
"{<< byte {this.reserved, this.id}} = bytes;\n"
"endfunction",
// concatenation lvalue
"module foo;\n"
" initial begin\n"
" {A, B, C} = bar;\n"
" end\n"
"endmodule\n",
// nested concatenation lvalue
"module foo;\n"
" initial begin\n"
" {{A, B}, {C, D}} = bar;\n"
" end\n"
"endmodule\n",
// assignment pattern lvalue
"module foo;\n"
" initial begin\n"
" '{A, B, C} = bar;\n"
" end\n"
"endmodule\n",
// assignment pattern lvalue and rvalue
"module foo;\n"
" initial begin\n"
" '{A, B, C} = '{D, E, F};\n"
" end\n"
"endmodule\n",
// nested assignment pattern lvalue
"module foo;\n"
" initial begin\n"
" '{'{A, B}, '{C, D}} = bar;\n"
" end\n"
"endmodule\n",
// mixed nested lvalue
"module foo;\n"
" initial begin\n"
" '{{A, B}, {C, D}} = bar1;\n"
" {'{E, F}, '{G, H}} = bar2;\n"
" end\n"
"endmodule\n",
// qualified expressions
"function void scoper;\n"
" a = b::c;\n"
Expand Down

0 comments on commit 650c6cc

Please sign in to comment.