cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_case.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 <
util/invariant.h
>
10
#include <
util/std_expr.h
>
11
12
#include "
boolbv.h
"
13
14
bvt
boolbvt::convert_case
(
const
case_exprt
&expr)
15
{
16
const
std::vector<exprt> &operands=expr.
operands
();
17
18
std::size_t width=
boolbv_width
(expr.
type
());
19
20
// make it free variables
21
bvt
bv =
prop
.new_variables(width);
22
23
DATA_INVARIANT
(
24
operands.size() >= 3,
"case should have at least three operands"
);
25
26
DATA_INVARIANT
(
27
operands.size() % 2 == 1,
"number of case operands should be odd"
);
28
29
enum
{ FIRST, COMPARE, VALUE } what=FIRST;
30
bvt
compare_bv;
31
literalt
previous_compare=
const_literal
(
false
);
32
literalt
compare_literal=
const_literal
(
false
);
33
34
for
(
const
auto
&operand : expr.
operands
())
35
{
36
bvt
op =
convert_bv
(operand);
37
38
switch
(what)
39
{
40
case
FIRST:
41
compare_bv.swap(op);
42
what=COMPARE;
43
break
;
44
45
case
COMPARE:
46
DATA_INVARIANT
(
47
compare_bv.size() == op.size(),
48
std::string(
"size of compare operand does not match:\n"
) +
49
"compare operand: "
+ std::to_string(compare_bv.size()) +
50
"\noperand: "
+ std::to_string(op.size()) +
'\n'
+ operand.pretty());
51
52
compare_literal=
bv_utils
.equal(compare_bv, op);
53
compare_literal=
prop
.land(!previous_compare, compare_literal);
54
55
previous_compare=
prop
.lor(previous_compare, compare_literal);
56
57
what=VALUE;
58
break
;
59
60
case
VALUE:
61
DATA_INVARIANT
(
62
bv.size() == op.size(),
63
std::string(
"size of value operand does not match:\n"
) +
64
"result size: "
+ std::to_string(bv.size()) +
65
"\noperand: "
+ std::to_string(op.size()) +
'\n'
+ operand.pretty());
66
67
{
68
literalt
value_literal=
bv_utils
.equal(bv, op);
69
70
prop
.l_set_to_true(
71
prop
.limplies(compare_literal, value_literal));
72
}
73
74
what=COMPARE;
75
break
;
76
77
default
:
78
UNREACHABLE
;
79
}
80
}
81
82
return
bv;
83
}
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_case
virtual bvt convert_case(const case_exprt &)
Definition
boolbv_case.cpp:14
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
case_exprt
Case expression: evaluates to the value corresponding to the first matching case.
Definition
std_expr.h:3456
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::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
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition
invariant.h:525
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
std_expr.h
API to expression classes.
solvers
flattening
boolbv_case.cpp
Generated by
1.17.0