From 5e7d7731edf9a4c2fc4805eefcdf157d62eb1b3b Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Fri, 15 Dec 2023 13:29:13 -0800 Subject: [PATCH] Verilog: move grammar rules into correct section This moves statement-related rules into the right section, and adjusts initial/always rules to match the System Verilog standard. --- src/verilog/parser.y | 109 +++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/src/verilog/parser.y b/src/verilog/parser.y index 4a4dd96d7..fe32ad096 100644 --- a/src/verilog/parser.y +++ b/src/verilog/parser.y @@ -2122,17 +2122,22 @@ net_assignment: net_lvalue '=' expression { init($$, ID_equal); mto($$, $1); mto($$, $3); } ; -variable_assignment: net_assignment; - // System Verilog standard 1800-2017 // A.6.2 Procedural blocks and assignments -initial_construct: TOK_INITIAL statement +initial_construct: TOK_INITIAL statement_or_null { init($$, ID_initial); mto($$, $2); } ; -always_construct: TOK_ALWAYS statement - { init($$, ID_always); mto($$, $2); } +always_construct: always_keyword statement + { $$=$1; mto($$, $2); } + ; + +always_keyword: + TOK_ALWAYS { init($$, ID_always); } + | TOK_ALWAYS_COMB { init($$, ID_always); } + | TOK_ALWAYS_LATCH { init($$, ID_always); } + | TOK_ALWAYS_FF { init($$, ID_always); } ; blocking_assignment: @@ -2169,36 +2174,21 @@ nonblocking_assignment: { init($$, ID_non_blocking_assign); mto($$, $1); mto($$, $4); } ; -// The extra rule to allow block_item_declaration is to avoid an ambiguity -// caused by the attribute_instance_brace. -statement: -/* block_identifier TOK_COLON attribute_instance_brace statement_item - { $$=$4; } - | */ - attribute_instance_brace statement_item - { $$=$2; } - | block_item_declaration - ; - -statement_item: - blocking_assignment ';' { $$ = $1; } - | nonblocking_assignment ';' { $$ = $1; } - | case_statement - | concurrent_assertion_statement - | conditional_statement - | inc_or_dec_expression ';' - | subroutine_call_statement - | disable_statement - | event_trigger - | loop_statement - | par_block - | procedural_timing_control_statement - | procedural_continuous_assignments ';' - | seq_block - | wait_statement - | procedural_assertion_statement +procedural_continuous_assignment: + TOK_ASSIGN variable_assignment + { init($$, ID_continuous_assign); mto($$, $2); } + | TOK_DEASSIGN variable_lvalue + { init($$, ID_deassign); mto($$, $2); } + | TOK_FORCE variable_assignment + { init($$, ID_force); swapop($$, $2); } + /* | TOK_FORCE net_assignment */ + | TOK_RELEASE variable_lvalue + { init($$, ID_release); mto($$, $2); } + /* | TOK_RELEASE net_lvalue */ ; +variable_assignment: net_assignment; + subroutine_call_statement: subroutine_call ';' { $$=$1; } @@ -2249,6 +2239,11 @@ concurrent_cover_statement: cover_property_statement // System Verilog standard 1800-2017 // A.6.4 Statements +statement_or_null: + statement + | attribute_instance_brace ';' { init($$, ID_skip); } + ; + statement_or_null_brace: /* Optional */ { init($$); } @@ -2256,6 +2251,36 @@ statement_or_null_brace: { $$=$1; mto($$, $2); } ; +// The extra rule to allow block_item_declaration is to avoid an ambiguity +// caused by the attribute_instance_brace. +statement: +/* block_identifier TOK_COLON attribute_instance_brace statement_item + { $$=$4; } + | */ + attribute_instance_brace statement_item + { $$=$2; } + | block_item_declaration + ; + +statement_item: + blocking_assignment ';' { $$ = $1; } + | nonblocking_assignment ';' { $$ = $1; } + | case_statement + | concurrent_assertion_statement + | conditional_statement + | inc_or_dec_expression ';' + | subroutine_call_statement + | disable_statement + | event_trigger + | loop_statement + | par_block + | procedural_timing_control_statement + | procedural_continuous_assignment ';' + | seq_block + | wait_statement + | procedural_assertion_statement + ; + system_task_name: TOK_SYSIDENT { init($$, ID_symbol); stack_expr($$).set(ID_identifier, stack_expr($1).id()); @@ -2449,19 +2474,6 @@ wait_statement: TOK_WAIT '(' expression ')' statement_or_null { init($$, ID_wait); mto($$, $3); mto($$, $5); } ; -procedural_continuous_assignments: - TOK_ASSIGN variable_assignment - { init($$, ID_continuous_assign); mto($$, $2); } - | TOK_DEASSIGN variable_lvalue - { init($$, ID_deassign); mto($$, $2); } - | TOK_FORCE variable_assignment - { init($$, ID_force); swapop($$, $2); } - /* | TOK_FORCE net_assignment */ - | TOK_RELEASE variable_lvalue - { init($$, ID_release); mto($$, $2); } - /* | TOK_RELEASE net_lvalue */ - ; - procedural_timing_control_statement: procedural_timing_control statement_or_null { $$=$1; mto($$, $2); } @@ -2629,11 +2641,6 @@ system_tf_call: ; -statement_or_null: - statement - | attribute_instance_brace ';' { init($$, ID_skip); } - ; - event_trigger: TOK_MINUSGREATER hierarchical_event_identifier ';' ;