Skip to content

Commit

Permalink
Parse nonblocking event trigger operator '->>'. LRM 15.5.1
Browse files Browse the repository at this point in the history
Also factored out a kRepeatControl grammar rule for reuse.

'delay_or_event_control' now matches LRM description.

Renamed event trigger constructs to distinguish between blocking/nonblocking.

Also handle new operator in formatter token_annotator.
Adds new and missing tests for '->' and '->>'.

fixes #227

PiperOrigin-RevId: 299368975
  • Loading branch information
fangism authored and hzeller committed Mar 11, 2020
1 parent 48ced6e commit 4ecb59b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 4 deletions.
3 changes: 2 additions & 1 deletion verilog/CST/verilog_nonterminals.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ enum class NodeEnum {
kIfBody,
kElseBody,
kDisableStatement,
kEventTriggerStatement,
kBlockingEventTriggerStatement,
kNonblockingEventTriggerStatement,
kForLoopStatement,
kLoopHeader,
kJumpStatement,
Expand Down
46 changes: 46 additions & 0 deletions verilog/formatting/token_annotator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,52 @@ TEST(TokenAnnotatorTest, AnnotateFormattingWithContextTest) {
{0, SpacingOptions::MustAppend},
},

// Handle '->' as a unary prefix expression.
{
DefaultStyle,
{TK_TRIGGER, "->"},
{verilog_tokentype::SymbolIdentifier, "a"},
{/* any context */}, // context
{0, SpacingOptions::Undecided}, // could be MustAppend though
},
{
DefaultStyle,
{TK_NONBLOCKING_TRIGGER, "->>"},
{verilog_tokentype::SymbolIdentifier, "a"},
{/* any context */}, // context
{0, SpacingOptions::Undecided}, // could be MustAppend though
},

// Handle '->' as a binary operator
{
DefaultStyle,
{TK_LOGICAL_IMPLIES, "->"},
{verilog_tokentype::SymbolIdentifier, "right"},
{/* any context */}, // context
{1, SpacingOptions::Undecided},
},
{
DefaultStyle,
{verilog_tokentype::SymbolIdentifier, "left"},
{TK_LOGICAL_IMPLIES, "->"},
{/* any context */}, // context
{1, SpacingOptions::Undecided},
},
{
DefaultStyle,
{TK_CONSTRAINT_IMPLIES, "->"},
{verilog_tokentype::SymbolIdentifier, "right"},
{/* any context */}, // context
{1, SpacingOptions::Undecided},
},
{
DefaultStyle,
{verilog_tokentype::SymbolIdentifier, "left"},
{TK_CONSTRAINT_IMPLIES, "->"},
{/* any context */}, // context
{1, SpacingOptions::Undecided},
},

// Inside dimension ranges, force space preservation if not around ':'
{
DefaultStyle,
Expand Down
3 changes: 2 additions & 1 deletion verilog/formatting/verilog_token.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ static const auto* FormatTokenTypeMap =
{verilog_tokentype::TK_TAND, FTT::binary_operator},
{verilog_tokentype::TK_NXOR, FTT::binary_operator},
{verilog_tokentype::TK_LOGEQUIV, FTT::binary_operator},
{verilog_tokentype::TK_TRIGGER, FTT::binary_operator},
{verilog_tokentype::TK_LOGICAL_IMPLIES, FTT::binary_operator},
{verilog_tokentype::TK_CONSTRAINT_IMPLIES, FTT::binary_operator},
{verilog_tokentype::TK_COLON_EQ, FTT::binary_operator},
Expand Down Expand Up @@ -536,6 +535,8 @@ static const auto* FormatTokenTypeMap =
{verilog_tokentype::TK_DECR, FTT::unary_operator},
{verilog_tokentype::TK_NAND, FTT::unary_operator},
{verilog_tokentype::TK_NOR, FTT::unary_operator},
{verilog_tokentype::TK_TRIGGER, FTT::unary_operator},
{verilog_tokentype::TK_NONBLOCKING_TRIGGER, FTT::unary_operator},

// hierarchy
{verilog_tokentype::TK_SCOPE_RES, FTT::hierarchy},
Expand Down
1 change: 1 addition & 0 deletions verilog/parser/verilog.lex
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ zi_zp { UpdateLocation(); return TK_zi_zp; }
"~^" { UpdateLocation(); return TK_NXOR; }
"^~" { UpdateLocation(); return TK_NXOR; }
"~&" { UpdateLocation(); return TK_NAND; }
"->>" { UpdateLocation(); return TK_NONBLOCKING_TRIGGER; }
"->" { UpdateLocation(); return _TK_RARROW; }
"<->" { UpdateLocation(); return TK_LOGEQUIV; }
"+:" { UpdateLocation(); return TK_PO_POS; }
Expand Down
7 changes: 5 additions & 2 deletions verilog/parser/verilog.y
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ is not locally defined, so the grammar here uses only generic identifiers.
// or "^~"
%token TK_LOGEQUIV "<->"

%token TK_NONBLOCKING_TRIGGER "->>"
%token _TK_RARROW "->"
// _TK_RARROW is disambiguated into one of the following symbols
// (see verilog_lexical_context.cc):
Expand Down Expand Up @@ -6614,8 +6615,10 @@ conditional_statement

event_trigger
: TK_TRIGGER reference ';'
{ $$ = MakeTaggedNode(N::kEventTriggerStatement, $1, $2, $3); }
/* TODO(fangism): ->> operator */
{ $$ = MakeTaggedNode(N::kBlockingEventTriggerStatement, $1, $2, $3); }
| TK_NONBLOCKING_TRIGGER delay_or_event_control_opt reference ';'
{ $$ = MakeTaggedNode(N::kNonblockingEventTriggerStatement,
$1, $2, $3, $4); }
;

repeat_control
Expand Down
1 change: 1 addition & 0 deletions verilog/parser/verilog_lexer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ static std::initializer_list<LexerTestData> kKeywordTests = {
{{TK_NAND, "~&"}},
{{TK_NOR, "~|"}},
{{TK_NXOR, "~^"}},
{{TK_NONBLOCKING_TRIGGER, "->>"}},
{{_TK_RARROW, "->"}}, // This can disambiguate to different enums,
// depending on context.
{{TK_LOGEQUIV, "<->"}},
Expand Down
20 changes: 20 additions & 0 deletions verilog/parser/verilog_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,26 @@ static const char* kModuleTests[] = {
" x = 0;\n"
" end\n"
"endmodule\n",
"module triggerer;\n"
" always @* begin\n"
" ->>c;\n" // nonblocking event trigger
" end\n"
"endmodule\n",
"module triggerer;\n"
" always @* begin\n"
" ->> #5 c;\n" // nonblocking event trigger, delayed
" end\n"
"endmodule\n",
"module triggerer;\n"
" always @* begin\n"
" ->> @(posedge y) c;\n" // nonblocking event trigger, edge
" end\n"
"endmodule\n",
"module triggerer;\n"
" always @* begin\n"
" ->> repeat(2) @foo c;\n" // nonblocking event trigger, repeat
" end\n"
"endmodule\n",
// streaming concatenations with macros
"module streaming_cats;\n"
"assign s1 = {>>`BAR};\n"
Expand Down

0 comments on commit 4ecb59b

Please sign in to comment.