Skip to content

Commit 7ac455c

Browse files
committed
Verilog: normalize ##[i:$]
This rewrites ##[i:$] to LTL, enabling the back-end to generate counterexamples of the correct length.
1 parent 8aeba7c commit 7ac455c

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

regression/verilog/SVA/sequence2.desc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CORE
2+
sequence2.sv
3+
--bound 10 --numbered-trace
4+
^\[main\.property\.1] ##\[0:\$\] main\.x == 10: REFUTED$
5+
^Counterexample with 7 states:$
6+
^main\.x@0 = 0$
7+
^main\.x@1 = 1$
8+
^main\.x@2 = 2$
9+
^main\.x@3 = 3$
10+
^main\.x@4 = 4$
11+
^main\.x@5 = 5$
12+
^main\.x@6 = 5$
13+
^EXIT=10$
14+
^SIGNAL=0$
15+
--
16+
^warning: ignoring
17+
--

regression/verilog/SVA/sequence2.sv

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

src/temporal-logic/normalize_property.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "normalize_property.h"
1010

11+
#include <util/arith_tools.h>
1112
#include <util/std_expr.h>
1213

1314
#include <verilog/sva_expr.h>
@@ -74,6 +75,27 @@ exprt normalize_pre_sva_non_overlapped_implication(
7475
return or_exprt{not_exprt{expr.lhs()}, X_exprt{expr.rhs()}};
7576
}
7677

78+
exprt normalize_pre_sva_cycle_delay(sva_cycle_delay_exprt expr)
79+
{
80+
if(expr.is_unbounded())
81+
{
82+
if(
83+
expr.from().is_constant() &&
84+
numeric_cast_v<mp_integer>(to_constant_expr(expr.from())) == 0)
85+
{
86+
// ##[0:$] φ --> F φ
87+
return F_exprt{expr.op()};
88+
}
89+
else
90+
{
91+
// ##[i:$] φ --> ##i F φ
92+
return sva_cycle_delay_exprt{expr.from(), F_exprt{expr.op()}};
93+
}
94+
}
95+
else
96+
return std::move(expr);
97+
}
98+
7799
exprt normalize_property(exprt expr)
78100
{
79101
// pre-traversal
@@ -93,6 +115,8 @@ exprt normalize_property(exprt expr)
93115
expr = X_exprt{to_sva_nexttime_expr(expr).op()};
94116
else if(expr.id() == ID_sva_s_nexttime)
95117
expr = X_exprt{to_sva_s_nexttime_expr(expr).op()};
118+
else if(expr.id() == ID_sva_cycle_delay)
119+
expr = normalize_pre_sva_cycle_delay(to_sva_cycle_delay_expr(expr));
96120

97121
// normalize the operands
98122
for(auto &op : expr.operands())

src/verilog/sva_expr.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ to_sva_non_overlapped_implication_expr(exprt &expr)
443443
class sva_cycle_delay_exprt : public ternary_exprt
444444
{
445445
public:
446-
explicit sva_cycle_delay_exprt(exprt from, exprt to, exprt op)
446+
sva_cycle_delay_exprt(exprt from, exprt to, exprt op)
447447
: ternary_exprt(
448448
ID_sva_cycle_delay,
449449
std::move(from),
@@ -453,6 +453,16 @@ class sva_cycle_delay_exprt : public ternary_exprt
453453
{
454454
}
455455

456+
sva_cycle_delay_exprt(exprt cycles, exprt op)
457+
: ternary_exprt(
458+
ID_sva_cycle_delay,
459+
std::move(cycles),
460+
nil_exprt{},
461+
std::move(op),
462+
bool_typet())
463+
{
464+
}
465+
456466
const exprt &from() const
457467
{
458468
return op0();
@@ -475,6 +485,11 @@ class sva_cycle_delay_exprt : public ternary_exprt
475485
return op1();
476486
}
477487

488+
bool is_unbounded() const
489+
{
490+
return to().id() == ID_infinity;
491+
}
492+
478493
const exprt &op() const
479494
{
480495
return op2();

0 commit comments

Comments
 (0)