Skip to content

Commit d3ed44f

Browse files
committed
Verilog: grammar for unique case and unique if
This adds the Verilog grammar rules for unique case and unique if.
1 parent d3071f4 commit d3ed44f

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
unique_case1.sv
3+
4+
^no properties$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module main(input x);
2+
3+
always_comb // unique
4+
unique casex (x)
5+
0:;
6+
1:;
7+
endcase
8+
9+
always_comb // not unique
10+
unique casex (x)
11+
0:;
12+
'b1?:;
13+
endcase
14+
15+
endmodule

regression/verilog/if/unique_if1.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
unique_if1.sv
3+
4+
^no properties$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

regression/verilog/if/unique_if1.sv

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module main(input x);
2+
3+
always_comb // unique
4+
unique if (x == 0)
5+
;
6+
else if(x == 1)
7+
;
8+
9+
always_comb // not unique
10+
unique if (x == 0)
11+
;
12+
else if(x&'b10 == 1)
13+
;
14+
15+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ IREP_ID_TWO(C_little_endian, #little_endian)
3535
IREP_ID_ONE(ports)
3636
IREP_ID_ONE(inst)
3737
IREP_ID_ONE(Verilog)
38+
IREP_ID_ONE(verilog_unique)
39+
IREP_ID_ONE(verilog_unique0)
40+
IREP_ID_ONE(verilog_priority)
3841
IREP_ID_ONE(verilog_non_indexed_part_select)
3942
IREP_ID_ONE(verilog_indexed_part_select_plus)
4043
IREP_ID_ONE(verilog_indexed_part_select_minus)

src/verilog/parser.y

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,27 +2755,38 @@ disable_statement: TOK_DISABLE hierarchical_task_or_block_identifier ';'
27552755
// A.6.6 Conditional statements
27562756

27572757
conditional_statement:
2758-
TOK_IF '(' expression ')' statement_or_null %prec LT_TOK_ELSE
2759-
{ init($$, ID_if); mto($$, $3); mto($$, $5); }
2760-
| TOK_IF '(' expression ')' statement_or_null TOK_ELSE statement_or_null
2761-
{ init($$, ID_if); mto($$, $3); mto($$, $5); mto($$, $7); }
2758+
unique_priority_opt TOK_IF '(' expression ')' statement_or_null %prec LT_TOK_ELSE
2759+
{ init($$, ID_if); mto($$, $4); mto($$, $6); }
2760+
| unique_priority_opt TOK_IF '(' expression ')' statement_or_null TOK_ELSE statement_or_null
2761+
{ init($$, ID_if); mto($$, $4); mto($$, $6); mto($$, $8); }
2762+
;
2763+
2764+
unique_priority_opt:
2765+
/* Optional */
2766+
{ init($$); }
2767+
| TOK_UNIQUE
2768+
{ init($$, ID_verilog_unique); }
2769+
| TOK_UNIQUE0
2770+
{ init($$, ID_verilog_unique0); }
2771+
| TOK_PRIORITY
2772+
{ init($$, ID_verilog_priority); }
27622773
;
27632774

27642775
// System Verilog standard 1800-2017
27652776
// A.6.7 Case statements
27662777

27672778
case_statement:
2768-
TOK_CASE '(' expression ')' case_item_brace TOK_ENDCASE
2769-
{ init($$, ID_case); mto($$, $3);
2770-
Forall_operands(it, stack_expr($5))
2779+
unique_priority_opt TOK_CASE '(' expression ')' case_item_brace TOK_ENDCASE
2780+
{ init($$, ID_case); mto($$, $4);
2781+
Forall_operands(it, stack_expr($6))
27712782
stack_expr($$).add_to_operands(std::move(*it)); }
2772-
| TOK_CASEX '(' expression ')' case_item_brace TOK_ENDCASE
2773-
{ init($$, ID_casex); mto($$, $3);
2774-
Forall_operands(it, stack_expr($5))
2783+
| unique_priority_opt TOK_CASEX '(' expression ')' case_item_brace TOK_ENDCASE
2784+
{ init($$, ID_casex); mto($$, $4);
2785+
Forall_operands(it, stack_expr($6))
27752786
stack_expr($$).add_to_operands(std::move(*it)); }
2776-
| TOK_CASEZ '(' expression ')' case_item_brace TOK_ENDCASE
2777-
{ init($$, ID_casez); mto($$, $3);
2778-
Forall_operands(it, stack_expr($5))
2787+
| unique_priority_opt TOK_CASEZ '(' expression ')' case_item_brace TOK_ENDCASE
2788+
{ init($$, ID_casez); mto($$, $4);
2789+
Forall_operands(it, stack_expr($6))
27792790
stack_expr($$).add_to_operands(std::move(*it)); }
27802791
;
27812792

0 commit comments

Comments
 (0)