Skip to content

Commit 3e7de3e

Browse files
committed
Verilog: always_comb, always_ff, always_latch
This adds support for the variants of always that SystemVerilog has introduced.
1 parent fb82f4b commit 3e7de3e

16 files changed

+172
-67
lines changed

regression/verilog/delays/delay_with_unit1.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ delay_with_unit1.v
33

44
^EXIT=2$
55
^SIGNAL=0$
6-
^file .*: permanent assignment without event guard$
6+
^file .*: assignment in 'always' context without event guard$
77

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
always_comb1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module main(input [7:0] data1);
2+
3+
logic [7:0] data2;
4+
always_comb data2 = data1;
5+
6+
p1: assert property (data2 == data1);
7+
8+
endmodule
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
always_comb2.sv
3+
--bound 0
4+
^\[main\.property\.p0\] always \(main\.data == 0 |-> main\.decoded == 1\): PROVED up to bound 0$
5+
^\[main\.property\.p1\] always \(main\.data == 1 |-> main\.decoded == 2\): PROVED up to bound 0$
6+
^\[main\.property\.p2\] always \(main\.data == 2 |-> main\.decoded == 4\): PROVED up to bound 0$
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
11+
--
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module main(input [7:0] data);
2+
3+
// an 8-bit binary to unary decoder
4+
reg [255:0] decoded;
5+
6+
always_comb begin
7+
integer i;
8+
for(i = 0; i < 256; i = i + 1)
9+
decoded[i] = data == i;
10+
end
11+
12+
p0: assert property (data == 0 |-> decoded == 1);
13+
p1: assert property (data == 1 |-> decoded == 2);
14+
p2: assert property (data == 2 |-> decoded == 4);
15+
16+
endmodule
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
always_ff1.sv
3+
--module main --k-induction
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main\.property\.p0\] always main\.x >= 1 && main\.x <= 10: PROVED$
7+
--
8+
^warning: ignoring
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module main(input clk);
2+
reg [31:0] x;
3+
4+
initial x=1;
5+
always_ff @(posedge clk)
6+
if(x<10)
7+
x++;
8+
9+
// should pass
10+
p0: assert property (x >= 1 && x <= 10);
11+
12+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ IREP_ID_ONE(force)
6666
IREP_ID_ONE(deassign)
6767
IREP_ID_ONE(continuous_assign)
6868
IREP_ID_ONE(wait)
69-
IREP_ID_ONE(always)
69+
IREP_ID_ONE(verilog_always)
70+
IREP_ID_ONE(verilog_always_comb)
71+
IREP_ID_ONE(verilog_always_ff)
72+
IREP_ID_ONE(verilog_always_latch)
7073
IREP_ID_ONE(named_port_connection)
7174
IREP_ID_ONE(verilog_final)
7275
IREP_ID_ONE(initial)

src/verilog/parser.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,10 +2518,10 @@ always_construct: always_keyword statement
25182518
;
25192519

25202520
always_keyword:
2521-
TOK_ALWAYS { init($$, ID_always); }
2522-
| TOK_ALWAYS_COMB { init($$, ID_always); }
2523-
| TOK_ALWAYS_LATCH { init($$, ID_always); }
2524-
| TOK_ALWAYS_FF { init($$, ID_always); }
2521+
TOK_ALWAYS { init($$, ID_verilog_always); }
2522+
| TOK_ALWAYS_COMB { init($$, ID_verilog_always_comb); }
2523+
| TOK_ALWAYS_LATCH { init($$, ID_verilog_always_latch); }
2524+
| TOK_ALWAYS_FF { init($$, ID_verilog_always_ff); }
25252525
;
25262526

25272527
final_construct: TOK_FINAL function_statement

src/verilog/verilog_elaborate.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,13 @@ void verilog_typecheckt::collect_symbols(
729729
{
730730
collect_symbols(to_verilog_decl(module_item));
731731
}
732-
else if(module_item.id() == ID_always)
732+
else if(
733+
module_item.id() == ID_verilog_always ||
734+
module_item.id() == ID_verilog_always_comb ||
735+
module_item.id() == ID_verilog_always_ff ||
736+
module_item.id() == ID_verilog_always_latch)
733737
{
734-
collect_symbols(to_verilog_always(module_item).statement());
738+
collect_symbols(to_verilog_always_base(module_item).statement());
735739
}
736740
else if(module_item.id() == ID_initial)
737741
{

0 commit comments

Comments
 (0)