Skip to content

Commit db3620a

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 6848ea4 commit db3620a

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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 char *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++), bool_typet()));
42+
43+
context_literals.push_back(context_literal);
44+
prop_conv.set_assumptions(context_literals);
45+
}
46+
47+
void context_prop_conv_solvert::pop_context()
48+
{
49+
PRECONDITION(!context_literals.empty());
50+
51+
// We remove the last context literal from the stack.
52+
context_literals.pop_back();
53+
prop_conv.set_assumptions(context_literals);
54+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_PROP_CONTEXT_PROP_CONV_SOLVER_H
13+
#define CPROVER_SOLVERS_PROP_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 char *context_prefix;
31+
32+
protected:
33+
// context literals used as assumptions
34+
bvt context_literals;
35+
36+
// unique context literal names
37+
std::size_t context_literal_counter = 0;
38+
};
39+
40+
#endif // CPROVER_SOLVERS_PROP_CONTEXT_PROP_CONV_SOLVER_H

0 commit comments

Comments
 (0)