Skip to content

Commit 883fd0d

Browse files
authored
Merge pull request #133 from diffblue/ebmc-cegar
ebmc CEGAR
2 parents f38d738 + 1fd30cd commit 883fd0d

File tree

11 files changed

+126
-157
lines changed

11 files changed

+126
-157
lines changed

regression/ebmc/cegar/basic1.desc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
basic1.sv
3+
--cegar
4+
^VERIFICATION SUCCESSFUL -- PROPERTY HOLDS$
5+
^EXIT=0$
6+
^SIGNAL=0$

regression/ebmc/cegar/basic1.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module top(input clk);
2+
3+
reg important;
4+
reg not_important;
5+
6+
initial important = 1;
7+
always @(posedge clk)
8+
important = important;
9+
10+
assert property (important == 1);
11+
12+
endmodule

regression/ebmc/cegar/basic2.desc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
KNOWNBUG
2+
basic2.sv
3+
--cegar
4+
^VERIFICATION FAILED -- PROPERTY REFUTED$
5+
^EXIT=0$
6+
^SIGNAL=0$

regression/ebmc/cegar/basic2.sv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module top(input clk);
2+
3+
reg important;
4+
reg not_important;
5+
6+
initial important = 1;
7+
always @(posedge clk)
8+
important = 0;
9+
10+
// should fail after one transition
11+
assert property (important == 1);
12+
13+
endmodule

src/ebmc/cegar/abstract.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ void bmc_cegart::abstract()
4545
latch_orderingt latch_ordering;
4646
latch_ordering.compute(ldg);
4747

48-
for(unsigned l=0; l<latch_ordering.node_ordering.size(); l++)
49-
std::cout << "Latch " << l << ": "
50-
<< latch_ordering.node_ordering[l] << std::endl;
51-
52-
exit(0);
48+
for(std::size_t l = 0; l < latch_ordering.node_ordering.size(); l++)
49+
std::cout << "Latch " << l << ": " << latch_ordering.node_ordering[l]
50+
<< std::endl;
5351
}
5452
}

src/ebmc/cegar/bmc_cegar.cpp

Lines changed: 30 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ Function: bmc_cegart::bmc_cegar
3131

3232
void bmc_cegart::bmc_cegar()
3333
{
34-
make_netlist();
35-
36-
if(properties.empty())
34+
if(properties.properties.empty())
3735
{
3836
error() << "No properties given" << eom;
3937
return;
@@ -68,68 +66,24 @@ Function: bmc_cegart::unwind
6866
\*******************************************************************/
6967

7068
void bmc_cegart::unwind(
71-
unsigned bound,
69+
std::size_t bound,
7270
const netlistt &netlist,
73-
propt &prop)
71+
cnft &solver)
7472
{
75-
// allocate timeframes
76-
const auto bmc_map = bmc_mapt{netlist, bound + 1, prop};
77-
78-
#if 0
79-
for(unsigned timeframe=0; timeframe<=bound; timeframe++)
80-
bmc_map.timeframe_map[timeframe].resize(aig_map.no_vars);
73+
::unwind(netlist, bmc_map, *this, solver);
8174

82-
// do initial state
83-
for(unsigned v=0; v<aig_map.no_vars; v++)
84-
bmc_map.timeframe_map[0][v]=prop.new_variable();
75+
// one of the properties needs to fail
76+
bvt disjuncts;
8577

86-
// do transitions
87-
for(unsigned timeframe=0; timeframe<bound; timeframe++)
78+
for(auto &property_it : netlist.properties)
8879
{
89-
status() << "Round " << timeframe << eom;
90-
91-
aig.clear_convert_cache();
92-
93-
// set current state bits
94-
for(unsigned v=0; v<aig_map.no_vars; v++)
95-
{
96-
//std::cout << "SETTING "
97-
// << aig_map.timeframe_map[0][v] << std::endl;
98-
99-
aig.set_l(prop,
100-
aig_map.timeframe_map[0][v],
101-
bmc_map.timeframe_map[timeframe][v]);
102-
}
80+
auto &prop_bv = prop_bv_map[property_it.first];
81+
unwind_property(property_it.second, bmc_map, prop_bv);
10382

104-
// convert next state bits
105-
for(unsigned v=0; v<aig_map.no_vars; v++)
106-
{
107-
literalt a=aig_map.timeframe_map[1][v];
108-
109-
// std::cout << "CONVERTING " << a << std::endl;
110-
111-
literalt l;
112-
113-
if(latches.find(v)!=latches.end())
114-
{
115-
assert(aig.can_convert(a));
116-
117-
l=aig.convert_prop(prop, a);
118-
}
119-
else
120-
l=prop.new_variable();
121-
122-
bmc_map.timeframe_map[timeframe+1][v]=l;
123-
}
83+
disjuncts.push_back(!solver.land(prop_bv));
12484
}
12585

126-
instantiate(prop, bmc_map, initial_state_predicate, 0, 1,
127-
false, ns);
128-
129-
// do the property
130-
property(properties, prop_bv, get_message_handler(), prop,
131-
bmc_map, ns);
132-
#endif
86+
solver.lcnf(disjuncts);
13387
}
13488

13589
/*******************************************************************\
@@ -144,21 +98,19 @@ Function: bmc_cegart::compute_ct
14498
14599
\*******************************************************************/
146100

147-
unsigned bmc_cegart::compute_ct()
101+
std::size_t bmc_cegart::compute_ct()
148102
{
149-
status() << "Computing CT" << eom;
150-
151103
status() << "Computing abstract LDG" << eom;
152104

153105
ldgt ldg;
154-
106+
155107
ldg.compute(abstract_netlist);
156-
157-
status() << "Computing CT" << eom;
158108

159-
unsigned ct=::compute_ct(ldg);
109+
status() << "Computing abstract CT" << eom;
160110

161-
result() << "CT=" << ct << eom;
111+
auto ct = ::compute_ct(ldg);
112+
113+
result() << "Abstract CT=" << ct << eom;
162114

163115
return ct;
164116
}
@@ -182,8 +134,8 @@ void bmc_cegart::cegar_loop()
182134
while(true)
183135
{
184136
abstract();
185-
186-
unsigned ct=compute_ct();
137+
138+
auto ct = compute_ct();
187139

188140
if(ct>=MAX_CT)
189141
{
@@ -192,8 +144,8 @@ void bmc_cegart::cegar_loop()
192144
}
193145

194146
// this is enough
195-
unsigned bound=ct;
196-
147+
auto bound = ct;
148+
197149
if(verify(bound))
198150
{
199151
status() << "VERIFICATION SUCCESSFUL -- PROPERTY HOLDS" << eom;
@@ -212,7 +164,7 @@ void bmc_cegart::cegar_loop()
212164

213165
/*******************************************************************\
214166
215-
Function: bmc_cegart::make_netlist
167+
Function: do_bmc_cegar
216168
217169
Inputs:
218170
@@ -222,34 +174,14 @@ Function: bmc_cegart::make_netlist
222174
223175
\*******************************************************************/
224176

225-
void bmc_cegart::make_netlist()
177+
int do_bmc_cegar(
178+
const netlistt &netlist,
179+
ebmc_propertiest &properties,
180+
const namespacet &ns,
181+
message_handlert &message_handler)
226182
{
227-
// make net-list
228-
status() << "Making Netlist" << eom;
229-
230-
try
231-
{
232-
const symbolt &module_symbol = ns.lookup(main_module);
233-
const transt &trans = to_trans_expr(module_symbol.value);
234-
235-
std::map<irep_idt, exprt> property_map;
236-
237-
convert_trans_to_netlist(
238-
symbol_table,
239-
main_module,
240-
trans,
241-
property_map,
242-
concrete_netlist,
243-
get_message_handler());
244-
}
245-
246-
catch(const std::string &error_msg)
247-
{
248-
error() << error_msg << eom;
249-
return;
250-
}
183+
bmc_cegart bmc_cegar(netlist, properties, ns, message_handler);
251184

252-
statistics()
253-
<< "Latches: " << concrete_netlist.var_map.latches.size()
254-
<< ", nodes: " << concrete_netlist.number_of_nodes() << eom;
185+
bmc_cegar.bmc_cegar();
186+
return 0;
255187
}

src/ebmc/cegar/bmc_cegar.h

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,69 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include <util/std_expr.h>
9+
#ifndef EBMC_CEGAR_BMC_CEGAR_H
10+
#define EBMC_CEGAR_BMC_CEGAR_H
11+
1012
#include <util/message.h>
1113
#include <util/namespace.h>
14+
#include <util/std_expr.h>
1215

16+
#include <ebmc/ebmc_properties.h>
17+
#include <ebmc/transition_system.h>
1318
#include <trans-netlist/bmc_map.h>
1419
#include <trans-netlist/netlist.h>
1520

21+
class cnft;
22+
1623
class bmc_cegart:public messaget
1724
{
1825
public:
1926
bmc_cegart(
20-
symbol_table_baset &_symbol_table,
21-
const irep_idt &_main_module,
22-
message_handlert &_message_handler,
23-
const std::list<exprt> &_properties)
27+
const netlistt &_netlist,
28+
ebmc_propertiest &_properties,
29+
const namespacet &_ns,
30+
message_handlert &_message_handler)
2431
: messaget(_message_handler),
25-
symbol_table(_symbol_table),
26-
ns(_symbol_table),
27-
main_module(_main_module),
28-
properties(_properties)
32+
properties(_properties),
33+
concrete_netlist(_netlist),
34+
ns(_ns)
2935
{
3036
}
3137

3238
void bmc_cegar();
3339

3440
protected:
35-
symbol_table_baset &symbol_table;
36-
const namespacet ns;
37-
const irep_idt &main_module;
38-
const std::list<exprt> &properties;
39-
41+
ebmc_propertiest &properties;
4042
bmc_mapt bmc_map;
4143
netlistt concrete_netlist, abstract_netlist;
44+
const namespacet &ns;
4245

4346
bool initial_abstraction;
4447

4548
typedef std::set<literalt> cut_pointst;
4649
cut_pointst cut_points;
47-
48-
void make_netlist();
49-
50+
5051
void cegar_loop();
5152

5253
void abstract();
5354
void refine();
54-
bool verify(unsigned bound);
55-
bool simulate(unsigned bound);
56-
unsigned compute_ct();
57-
58-
void unwind(
59-
unsigned bound,
60-
const netlistt &netlist,
61-
propt &prop);
62-
63-
std::list<bvt> prop_bv;
55+
bool verify(std::size_t bound);
56+
bool simulate(std::size_t bound);
57+
std::size_t compute_ct();
58+
59+
void unwind(std::size_t bound, const netlistt &netlist, cnft &solver);
60+
61+
std::map<irep_idt, bvt> prop_bv_map;
6462
};
63+
64+
class ebmc_propertiest;
65+
class message_handlert;
66+
class netlistt;
67+
68+
int do_bmc_cegar(
69+
const netlistt &,
70+
ebmc_propertiest &,
71+
const namespacet &,
72+
message_handlert &);
73+
74+
#endif // EBMC_CEGAR_BMC_CEGAR_H

src/ebmc/cegar/simulate.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Function: bmc_cegart::simulate
2525
2626
\*******************************************************************/
2727

28-
bool bmc_cegart::simulate(unsigned bound)
28+
bool bmc_cegart::simulate(std::size_t bound)
2929
{
3030
status() << "Simulating Counterexample" << eom;
3131

@@ -40,9 +40,6 @@ bool bmc_cegart::simulate(unsigned bound)
4040
{
4141
case propt::resultt::P_SATISFIABLE:
4242
status() << "SAT: bug found within bound" << eom;
43-
44-
show_counterexample(properties, prop_bv, get_message_handler(), solver,
45-
bmc_map, ns);
4643
return true;
4744

4845
case propt::resultt::P_UNSATISFIABLE:

src/ebmc/cegar/verify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Function: bmc_cegart::verify
2222
2323
\*******************************************************************/
2424

25-
bool bmc_cegart::verify(unsigned bound)
25+
bool bmc_cegart::verify(const std::size_t bound)
2626
{
27-
status() << "Checking Abstract Model (bound=" << bound << ")" << eom;
27+
status() << "Checking abstract model (bound=" << bound << ")" << eom;
2828

2929
satcheckt satcheck{*message_handler};
3030
cnft &solver=satcheck;

src/ebmc/ebmc_base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ebmc_baset
3737
bool make_netlist(netlistt &);
3838

3939
transition_systemt transition_system;
40+
41+
using propertyt = ebmc_propertiest::propertyt;
4042
ebmc_propertiest properties;
4143

4244
protected:
@@ -53,7 +55,6 @@ class ebmc_baset
5355
bool typecheck();
5456

5557
std::size_t bound;
56-
using propertyt = ebmc_propertiest::propertyt;
5758

5859
public:
5960
int do_compute_ct();

0 commit comments

Comments
 (0)