-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathbv_refinement_loop.cpp
140 lines (114 loc) · 3.52 KB
/
bv_refinement_loop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************\
Module:
Author: Daniel Kroening, [email protected]
\*******************************************************************/
#include "bv_refinement.h"
#include <util/xml.h>
bv_refinementt::bv_refinementt(const infot &info)
: bv_pointerst(*info.ns, *info.prop, *info.message_handler),
progress(false),
config_(info)
{
// check features we need
PRECONDITION(prop.has_assumptions());
PRECONDITION(prop.has_set_to());
PRECONDITION(prop.has_is_in_conflict());
}
decision_proceduret::resultt bv_refinementt::dec_solve(const exprt &assumption)
{
// do the usual post-processing
log.status() << "BV-Refinement: post-processing" << messaget::eom;
finish_eager_conversion();
log.debug() << "Solving with " << prop.solver_text() << messaget::eom;
unsigned iteration=0;
// now enter the loop
while(true)
{
iteration++;
log.status() << "BV-Refinement: iteration " << iteration << messaget::eom;
// output the very same information in a structured fashion
if(config_.output_xml)
{
xmlt xml("refinement-iteration");
xml.data=std::to_string(iteration);
log.status() << xml << '\n';
}
switch(prop_solve())
{
case resultt::D_SATISFIABLE:
check_SAT();
if(!progress)
{
log.status() << "BV-Refinement: got SAT, and it simulates => SAT"
<< messaget::eom;
log.status() << "Total iterations: " << iteration << messaget::eom;
return resultt::D_SATISFIABLE;
}
else
log.status() << "BV-Refinement: got SAT, and it is spurious, refining"
<< messaget::eom;
break;
case resultt::D_UNSATISFIABLE:
check_UNSAT();
if(!progress)
{
log.status()
<< "BV-Refinement: got UNSAT, and the proof passes => UNSAT"
<< messaget::eom;
log.status() << "Total iterations: " << iteration << messaget::eom;
return resultt::D_UNSATISFIABLE;
}
else
log.status()
<< "BV-Refinement: got UNSAT, and the proof fails, refining"
<< messaget::eom;
break;
case resultt::D_ERROR:
return resultt::D_ERROR;
}
}
}
decision_proceduret::resultt bv_refinementt::prop_solve()
{
// this puts the underapproximations into effect
std::vector<exprt> assumptions;
for(const approximationt &approximation : approximations)
{
assumptions.insert(
assumptions.end(),
approximation.over_assumptions.begin(),
approximation.over_assumptions.end());
assumptions.insert(
assumptions.end(),
approximation.under_assumptions.begin(),
approximation.under_assumptions.end());
}
push(assumptions);
propt::resultt result = prop.prop_solve(assumption_stack);
pop();
// clang-format off
switch(result)
{
case propt::resultt::P_SATISFIABLE: return resultt::D_SATISFIABLE;
case propt::resultt::P_UNSATISFIABLE: return resultt::D_UNSATISFIABLE;
case propt::resultt::P_ERROR: return resultt::D_ERROR;
}
// clang-format off
UNREACHABLE;
}
void bv_refinementt::check_SAT()
{
progress=false;
arrays_overapproximated();
// get values before modifying the formula
for(approximationt &approximation : this->approximations)
get_values(approximation);
for(approximationt &approximation : this->approximations)
check_SAT(approximation);
}
void bv_refinementt::check_UNSAT()
{
progress=false;
for(approximationt &approximation : this->approximations)
check_UNSAT(approximation);
}