Skip to content

Commit f9663a4

Browse files
Context solver implementation for propt-based solvers
Allows us to use, e.g. bv_refinementt, incrementally with a push/pop interface.
1 parent 0210344 commit f9663a4

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

src/solvers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ SRC = $(BOOLEFORCE_SRC) \
145145
lowering/popcount.cpp \
146146
bdd/miniBDD/miniBDD.cpp \
147147
prop/bdd_expr.cpp \
148+
prop/context_prop_conv_solver.cpp \
148149
prop/context_solver.cpp \
149150
prop/cover_goals.cpp \
150151
prop/literal.cpp \
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************\
2+
3+
Module: Push/pop-context wrapper for propt-based refinement solvers
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Push/pop-context wrapper for `propt`-based refinement solvers
11+
12+
#include "context_prop_conv_solver.h"
13+
14+
context_prop_conv_solvert::context_prop_conv_solvert(prop_convt &prop_conv)
15+
: context_solvert(prop_conv)
16+
{
17+
}
18+
19+
const std::string context_prop_conv_solvert::context_prefix =
20+
"prop_conv::context$";
21+
22+
void context_prop_conv_solvert::set_to(const exprt &expr, bool value)
23+
{
24+
if(context_literals.empty())
25+
{
26+
// We are in the root context.
27+
prop_conv.set_to(expr, value);
28+
}
29+
else
30+
{
31+
// We have a child context. We add context_literal ==> expr to the formula.
32+
prop_conv.set_to(
33+
or_exprt(literal_exprt(!context_literals.back()), expr), value);
34+
}
35+
}
36+
37+
void context_prop_conv_solvert::push_context()
38+
{
39+
// We create a new context literal.
40+
literalt context_literal = prop_conv.convert(symbol_exprt(
41+
context_prefix + std::to_string(context_literal_counter++),
42+
bool_typet()));
43+
44+
context_literals.push_back(context_literal);
45+
prop_conv.set_assumptions(context_literals);
46+
}
47+
48+
void context_prop_conv_solvert::pop_context()
49+
{
50+
PRECONDITION(!context_literals.empty());
51+
52+
// We remove the last context literal from the stack.
53+
context_literals.pop_back();
54+
prop_conv.set_assumptions(context_literals);
55+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*******************************************************************\
2+
3+
Module: Push/pop-context wrapper for propt-based refinement solvers
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Push/pop-context wrapper for `propt`-based refinement solvers
11+
12+
#ifndef CPROVER_SOLVERS_CONTEXT_PROP_CONV_SOLVER_H
13+
#define CPROVER_SOLVERS_CONTEXT_PROP_CONV_SOLVER_H
14+
15+
#include "context_solver.h"
16+
17+
/// Provides a push/pop-context interface for incremental solving
18+
/// to `propt`-based solvers such as `bv_refinementt`.
19+
class context_prop_conv_solvert : public context_solvert
20+
{
21+
public:
22+
explicit context_prop_conv_solvert(prop_convt &prop_conv);
23+
24+
void set_to(const exprt &expr, bool value) override;
25+
26+
void push_context() override;
27+
28+
void pop_context() override;
29+
30+
static const std::string context_prefix;
31+
protected:
32+
// context literals used as assumptions
33+
bvt context_literals;
34+
35+
// unique context literal names
36+
std::size_t context_literal_counter = 0;
37+
};
38+
39+
#endif // CPROVER_SOLVERS_PROP_CONTEXT_PROP_CONV_SOLVER_H

0 commit comments

Comments
 (0)