cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_cond.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#include "
boolbv.h
"
10
11
#include <
util/invariant.h
>
12
13
bvt
boolbvt::convert_cond
(
const
cond_exprt
&expr)
14
{
15
const
exprt::operandst
&operands=expr.
operands
();
16
17
std::size_t width=
boolbv_width
(expr.
type
());
18
19
bvt
bv;
20
21
DATA_INVARIANT
(operands.size() >= 2,
"cond must have at least two operands"
);
22
23
DATA_INVARIANT
(
24
operands.size() % 2 == 0,
"number of cond operands must be even"
);
25
26
if
(
prop
.has_set_to())
27
{
28
bool
condition=
true
;
29
literalt
previous_cond=
const_literal
(
false
);
30
literalt
cond_literal=
const_literal
(
false
);
31
32
// make it free variables
33
bv =
prop
.new_variables(width);
34
35
for
(
const
auto
&operand : expr.
operands
())
36
{
37
if
(condition)
38
{
39
cond_literal =
convert
(operand);
40
cond_literal=
prop
.land(!previous_cond, cond_literal);
41
42
previous_cond=
prop
.lor(previous_cond, cond_literal);
43
}
44
else
45
{
46
const
bvt
&op =
convert_bv
(operand, bv.size());
47
48
literalt
value_literal=
bv_utils
.equal(bv, op);
49
50
prop
.l_set_to_true(
prop
.limplies(cond_literal, value_literal));
51
}
52
53
condition=!condition;
54
}
55
}
56
else
57
{
58
bv.resize(width);
59
60
// functional version -- go backwards
61
for
(std::size_t i=expr.
operands
().size(); i!=0; i-=2)
62
{
63
INVARIANT
(
64
i >= 2,
65
"since the number of operands is even if i is nonzero it must be "
66
"greater than two"
);
67
const
exprt
&cond=expr.
operands
()[i-2];
68
const
exprt
&value=expr.
operands
()[i-1];
69
70
literalt
cond_literal=
convert
(cond);
71
72
const
bvt
&op =
convert_bv
(value, bv.size());
73
74
for
(std::size_t j = 0; j < bv.size(); j++)
75
bv[j] =
prop
.lselect(cond_literal, op[j], bv[j]);
76
}
77
}
78
79
return
bv;
80
}
boolbv.h
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition
boolbv.cpp:40
boolbvt::convert_cond
virtual bvt convert_cond(const cond_exprt &)
Definition
boolbv_cond.cpp:13
boolbvt::bv_utils
bv_utilst bv_utils
Definition
boolbv.h:121
boolbvt::boolbv_width
virtual std::size_t boolbv_width(const typet &type) const
Definition
boolbv.h:106
cond_exprt
this is a parametric version of an if-expression: it returns the value of the first case (using the o...
Definition
std_expr.h:3393
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::operandst
std::vector< exprt > operandst
Definition
expr.h:59
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
literalt
Definition
literal.h:26
prop_conv_solvert::convert
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
Definition
prop_conv_solver.cpp:154
prop_conv_solvert::prop
propt & prop
Definition
prop_conv_solver.h:130
bvt
std::vector< literalt > bvt
Definition
literal.h:201
const_literal
literalt const_literal(bool value)
Definition
literal.h:188
invariant.h
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition
invariant.h:534
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition
invariant.h:423
solvers
flattening
boolbv_cond.cpp
Generated by
1.17.0