Skip to content

Commit d726a2b

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 f14c080 commit d726a2b

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 = "prop_conv::context$";
20+
21+
void context_prop_conv_solvert::set_to(const exprt &expr, bool value)
22+
{
23+
if(context_literals.empty())
24+
{
25+
// We are in the root context.
26+
prop_conv.set_to(expr, value);
27+
}
28+
else
29+
{
30+
// We have a child context. We add context_literal ==> expr to the formula.
31+
prop_conv.set_to(
32+
or_exprt(literal_exprt(!context_literals.back()), expr), value);
33+
}
34+
}
35+
36+
void context_prop_conv_solvert::push_context()
37+
{
38+
// We create a new context literal.
39+
literalt context_literal = prop_conv.convert(symbol_exprt(
40+
context_prefix + std::to_string(context_literal_counter++), bool_typet()));
41+
42+
context_literals.push_back(context_literal);
43+
prop_conv.set_assumptions(context_literals);
44+
}
45+
46+
void context_prop_conv_solvert::pop_context()
47+
{
48+
PRECONDITION(!context_literals.empty());
49+
50+
// We remove the last context literal from the stack.
51+
context_literals.pop_back();
52+
prop_conv.set_assumptions(context_literals);
53+
}
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)