Skip to content

Commit 639523b

Browse files
authored
Merge pull request #116 from diffblue/liveness-to-safety
ebmc: liveness to safety translation
2 parents 63abca3 + 7a33f58 commit 639523b

19 files changed

+507
-28
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
failing1.sv
3+
--bound 1 --liveness-to-safety
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.property\.p0\] always eventually main\.my_bit: REFUTED$
7+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module main(input clk);
2+
3+
reg my_bit;
4+
5+
initial my_bit=0;
6+
7+
always @(posedge clk)
8+
my_bit = 0;
9+
10+
// expected to fail
11+
p0: assert property (eventually my_bit);
12+
13+
endmodule
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
failing2.sv
3+
--bound 6 --liveness-to-safety
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.property\.p0\] always eventually main\.counter == 0: REFUTED$
7+
^\[main\.property\.p1\] always eventually main\.counter == 6: REFUTED$
8+
--
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module main(input clk);
2+
3+
reg [31:0] counter;
4+
5+
initial counter=0;
6+
7+
always @(posedge clk)
8+
if(counter == 5)
9+
counter = 5;
10+
else
11+
counter=counter+1;
12+
13+
// both expected to fail
14+
p0: assert property (eventually counter==0);
15+
p1: assert property (eventually counter==6);
16+
17+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
passing1.sv
3+
--bound 10 --liveness-to-safety
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main\.property\.p0\] always eventually main\.my_bit: PROVED up to bound 10$
7+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module main(input clk);
2+
3+
reg my_bit;
4+
5+
initial my_bit=0;
6+
7+
always @(posedge clk)
8+
my_bit = !my_bit;
9+
10+
// expected to pass
11+
p0: assert property (eventually my_bit);
12+
13+
endmodule
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
passing2.sv
3+
--bound 10 --liveness-to-safety
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main\.property\.p0\] always eventually main\.counter == 0: PROVED up to bound 10$
7+
^\[main\.property\.p1\] always eventually main\.counter == 8: PROVED up to bound 10$
8+
--
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module main(input clk);
2+
3+
reg [31:0] counter;
4+
5+
initial counter=0;
6+
7+
always @(posedge clk)
8+
counter=counter+1;
9+
10+
// both expected to pass
11+
p0: assert property (eventually counter==0);
12+
p1: assert property (eventually counter==8);
13+
14+
endmodule

src/ebmc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SRC = \
1515
ebmc_properties.cpp \
1616
ebmc_solver_factory.cpp \
1717
k_induction.cpp \
18+
liveness_to_safety.cpp \
1819
main.cpp \
1920
negate_property.cpp \
2021
neural_liveness.cpp \

src/ebmc/ebmc_base.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,6 @@ ebmc_baset::ebmc_baset(
5656

5757
/*******************************************************************\
5858
59-
Function: ebmc_baset::property_requires_lasso_constraints
60-
61-
Inputs:
62-
63-
Outputs:
64-
65-
Purpose:
66-
67-
\*******************************************************************/
68-
69-
bool ebmc_baset::property_requires_lasso_constraints() const
70-
{
71-
for(const auto &p : properties.properties)
72-
if(!p.is_disabled() && requires_lasso_constraints(p.expr))
73-
return true;
74-
75-
return false;
76-
}
77-
78-
/*******************************************************************\
79-
8059
Function: ebmc_baset::finish_word_level_bmc
8160
8261
Inputs:
@@ -108,7 +87,7 @@ void ebmc_baset::word_level_properties(decision_proceduret &solver)
10887
}
10988

11089
// lasso constraints, if needed
111-
if(property_requires_lasso_constraints())
90+
if(properties.requires_lasso_constraints())
11291
{
11392
message.status() << "Adding lasso constraints" << messaget::eom;
11493
lasso_constraints(

src/ebmc/ebmc_base.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ebmc_baset
3737
bool make_netlist(netlistt &);
3838

3939
transition_systemt transition_system;
40+
ebmc_propertiest properties;
4041

4142
protected:
4243
messaget message;
@@ -62,11 +63,7 @@ class ebmc_baset
6263
bool typecheck();
6364

6465
std::size_t bound;
65-
6666
using propertyt = ebmc_propertiest::propertyt;
67-
ebmc_propertiest properties;
68-
69-
bool property_requires_lasso_constraints() const;
7067

7168
public:
7269
int do_compute_ct();

src/ebmc/ebmc_error.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ class ebmc_errort
3636
return std::move(*this);
3737
}
3838

39+
ebmc_errort with_location(source_locationt _location) &&
40+
{
41+
__location = std::move(_location);
42+
return std::move(*this);
43+
}
44+
3945
protected:
4046
std::ostringstream message;
4147
optionalt<int> __exit_code = {};
48+
source_locationt __location = source_locationt::nil();
4249
};
4350

4451
/// add to the diagnostic information in the given ebmc_error exception

src/ebmc/ebmc_parse_options.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include "ebmc_version.h"
2121
#include "ic3_engine.h"
2222
#include "k_induction.h"
23+
#include "liveness_to_safety.h"
2324
#include "neural_liveness.h"
2425
#include "random_traces.h"
2526
#include "ranking_function.h"
@@ -293,7 +294,12 @@ int ebmc_parse_optionst::doit()
293294

294295
if(cmdline.isset("compute-ct"))
295296
return ebmc_base.do_compute_ct();
296-
else if(cmdline.isset("aig") || cmdline.isset("dimacs"))
297+
298+
// possibly apply liveness-to-safety
299+
if(cmdline.isset("liveness-to-safety"))
300+
liveness_to_safety(ebmc_base.transition_system, ebmc_base.properties);
301+
302+
if(cmdline.isset("aig") || cmdline.isset("dimacs"))
297303
return ebmc_base.do_bit_level_bmc();
298304
else
299305
return ebmc_base.do_word_level_bmc(); // default
@@ -354,6 +360,7 @@ void ebmc_parse_optionst::help()
354360
" {y--property} {uid} \t check the property with given ID\n"
355361
" {y-I} {upath} \t set include path\n"
356362
" {y--reset} {uexpr} \t set up module reset\n"
363+
" {y--liveness-to-safety} \t translate liveness properties to safety properties\n"
357364
"\n"
358365
"Methods:\n"
359366
" {y--k-induction} \t do k-induction with k=bound\n"

src/ebmc/ebmc_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ebmc_parse_optionst:public parse_options_baset
4444
"(compute-ct)(dot-netlist)(smv-netlist)(vcd):"
4545
"(random-traces)(trace-steps):(random-seed):(number-of-traces):"
4646
"(random-trace)(random-waveform)"
47+
"(liveness-to-safety)"
4748
"I:(preprocess)",
4849
argc,
4950
argv,

src/ebmc/ebmc_properties.h

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

1515
#include <solvers/prop/literal.h>
1616
#include <trans-netlist/trans_trace.h>
17+
#include <trans-word-level/property.h>
1718

1819
#include "transition_system.h"
1920

@@ -137,6 +138,11 @@ class ebmc_propertiest
137138
std::string status_as_string() const;
138139

139140
propertyt() = default;
141+
142+
bool requires_lasso_constraints() const
143+
{
144+
return ::requires_lasso_constraints(expr);
145+
}
140146
};
141147

142148
typedef std::list<propertyt> propertiest;
@@ -151,6 +157,15 @@ class ebmc_propertiest
151157
return true;
152158
}
153159

160+
bool requires_lasso_constraints() const
161+
{
162+
for(const auto &p : properties)
163+
if(!p.is_disabled() && p.requires_lasso_constraints())
164+
return true;
165+
166+
return false;
167+
}
168+
154169
static ebmc_propertiest from_command_line(
155170
const cmdlinet &,
156171
const transition_systemt &,

0 commit comments

Comments
 (0)