Skip to content

Commit 2a457e3

Browse files
committed
Verilog: add all remaining property_expr rules from 1800-2017
This adds all remaining property_expr productions given in IEEE 1800-2017: * strong * weak * case
1 parent 919a2f3 commit 2a457e3

File tree

15 files changed

+388
-34
lines changed

15 files changed

+388
-34
lines changed

regression/verilog/SVA/case1.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
case1.sv
3+
--bound 20 --numbered-trace
4+
^\[main\.property\.p0\] always \(case\(main\.x\) 10: 0; endcase\): REFUTED$
5+
^Counterexample with 11 states:$
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
--

regression/verilog/SVA/case1.sv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module main;
2+
3+
reg [31:0] x;
4+
wire clk;
5+
6+
initial x=0;
7+
8+
always @(posedge clk)
9+
x<=x+1;
10+
11+
// fails when x reaches 10
12+
p0: assert property (case(x) 10: 0; endcase);
13+
14+
endmodule
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
strong1.sv
3+
--bound 20
4+
^\[main\.property\.p0\] strong\(##\[0:9\] main\.x == 100\): REFUTED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--

regression/verilog/SVA/strong1.sv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module main;
2+
3+
reg [31:0] x;
4+
wire clk;
5+
6+
initial x=0;
7+
8+
always @(posedge clk)
9+
x<=x+1;
10+
11+
// fails
12+
initial p0: assert property (strong(##[0:9] x==100));
13+
14+
endmodule

regression/verilog/SVA/weak1.desc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
weak1.sv
3+
--bound 20
4+
^\[main\.property\.p0\] weak\(##\[0:9\] main\.x == 100\): REFUTED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--

regression/verilog/SVA/weak1.sv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module main;
2+
3+
reg [31:0] x;
4+
wire clk;
5+
6+
initial x=0;
7+
8+
always @(posedge clk)
9+
x<=x+1;
10+
11+
// fails
12+
initial p0: assert property (weak(##[0:9] x==100));
13+
14+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ IREP_ID_ONE(F)
1515
IREP_ID_ONE(E)
1616
IREP_ID_ONE(G)
1717
IREP_ID_ONE(X)
18+
IREP_ID_ONE(sva_strong)
19+
IREP_ID_ONE(sva_weak)
1820
IREP_ID_ONE(sva_if)
21+
IREP_ID_ONE(sva_case)
1922
IREP_ID_ONE(sva_cycle_delay)
2023
IREP_ID_ONE(sva_cycle_delay_star)
2124
IREP_ID_ONE(sva_cycle_delay_plus)

src/temporal-logic/normalize_property.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ exprt normalize_property(exprt expr)
135135
: sva_if_expr.false_case();
136136
expr = if_exprt{sva_if_expr.cond(), sva_if_expr.true_case(), false_case};
137137
}
138+
else if(expr.id() == ID_sva_strong)
139+
{
140+
expr = to_sva_strong_expr(expr).op();
141+
}
142+
else if(expr.id() == ID_sva_weak)
143+
{
144+
expr = to_sva_weak_expr(expr).op();
145+
}
146+
else if(expr.id() == ID_sva_case)
147+
{
148+
expr = to_sva_case_expr(expr).lowering();
149+
}
138150

139151
// normalize the operands
140152
for(auto &op : expr.operands())

src/temporal-logic/normalize_property.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Author: Daniel Kroening, dkr@amazon.com
2727
/// ¬Fφ --> G¬φ
2828
/// [*] φ --> F φ
2929
/// [+] φ --> X F φ
30+
/// strong(φ) --> φ
31+
/// weak(φ) --> φ
32+
/// sva_case --> ? :
3033
exprt normalize_property(exprt);
3134

3235
#endif

src/verilog/expr2verilog.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,42 @@ std::string expr2verilogt::convert_sva_ranged_predicate(
407407

408408
/*******************************************************************\
409409
410+
Function: expr2verilogt::convert_sva_case
411+
412+
Inputs:
413+
414+
Outputs:
415+
416+
Purpose:
417+
418+
\*******************************************************************/
419+
420+
std::string expr2verilogt::convert_sva_case(const sva_case_exprt &src)
421+
{
422+
std::string cases;
423+
424+
for(auto &case_item : src.case_items())
425+
{
426+
bool first = true;
427+
for(auto &pattern : case_item.patterns())
428+
{
429+
if(first)
430+
first = false;
431+
else
432+
cases += ", ";
433+
cases += convert(pattern);
434+
}
435+
436+
cases += ": ";
437+
cases += convert(case_item.result());
438+
cases += "; ";
439+
}
440+
441+
return "case(" + convert(src.case_op()) + ") " + cases + "endcase";
442+
}
443+
444+
/*******************************************************************\
445+
410446
Function: expr2verilogt::convert_sva_unary
411447
412448
Inputs:
@@ -1171,7 +1207,13 @@ std::string expr2verilogt::convert(
11711207
else if(src.id()==ID_sva_cycle_delay)
11721208
return convert_sva_cycle_delay(to_ternary_expr(src), precedence = 0);
11731209
// not sure about precedence
1174-
1210+
1211+
else if(src.id() == ID_sva_strong)
1212+
return convert_function("strong", src);
1213+
1214+
else if(src.id() == ID_sva_weak)
1215+
return convert_function("weak", src);
1216+
11751217
else if(src.id()==ID_sva_sequence_concatenation)
11761218
return convert_sva_sequence_concatenation(
11771219
to_binary_expr(src), precedence = 0);
@@ -1251,6 +1293,9 @@ std::string expr2verilogt::convert(
12511293
else if(src.id() == ID_sva_if)
12521294
return precedence = 0, convert_sva_if(to_sva_if_expr(src));
12531295

1296+
else if(src.id() == ID_sva_case)
1297+
return precedence = 0, convert_sva_case(to_sva_case_expr(src));
1298+
12541299
else if(src.id()==ID_function_call)
12551300
return convert_function_call(to_function_call_expr(src));
12561301

0 commit comments

Comments
 (0)