cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_bitwise.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/bitvector_expr.h
>
12
13
bvt
boolbvt::convert_bitwise
(
const
exprt
&expr)
14
{
15
const
std::size_t width =
boolbv_width
(expr.
type
());
16
17
if
(expr.
id
()==ID_bitnot)
18
{
19
const
exprt
&op =
to_bitnot_expr
(expr).
op
();
20
const
bvt
&op_bv =
convert_bv
(op, width);
21
return
bv_utils
.inverted(op_bv);
22
}
23
else
if
(expr.
id
()==ID_bitand || expr.
id
()==ID_bitor ||
24
expr.
id
()==ID_bitxor ||
25
expr.
id
()==ID_bitnand || expr.
id
()==ID_bitnor ||
26
expr.
id
()==ID_bitxnor)
27
{
28
std::function<
literalt
(
literalt
,
literalt
)> f;
29
30
if
(expr.
id
() == ID_bitand || expr.
id
() == ID_bitnand)
31
f = [
this
](
literalt
a,
literalt
b) {
return
prop
.land(a, b); };
32
else
if
(expr.
id
() == ID_bitor || expr.
id
() == ID_bitnor)
33
f = [
this
](
literalt
a,
literalt
b) {
return
prop
.lor(a, b); };
34
else
if
(expr.
id
() == ID_bitxor || expr.
id
() == ID_bitxnor)
35
f = [
this
](
literalt
a,
literalt
b) {
return
prop
.lxor(a, b); };
36
else
37
UNIMPLEMENTED
;
38
39
bvt
bv;
40
bv.resize(width);
41
42
forall_operands
(it, expr)
43
{
44
const
bvt
&op =
convert_bv
(*it, width);
45
46
if
(it==expr.
operands
().begin())
47
bv=op;
48
else
49
{
50
for
(std::size_t i=0; i<width; i++)
51
{
52
bv[i] = f(bv[i], op[i]);
53
}
54
}
55
}
56
57
if
(
58
expr.
id
() == ID_bitnand || expr.
id
() == ID_bitnor ||
59
expr.
id
() == ID_bitxnor)
60
{
61
return
bv_utils
.inverted(bv);
62
}
63
else
64
return
bv;
65
}
66
67
UNIMPLEMENTED
;
68
}
bitvector_expr.h
API to expression classes for bitvectors.
to_bitnot_expr
const bitnot_exprt & to_bitnot_expr(const exprt &expr)
Cast an exprt to a bitnot_exprt.
Definition
bitvector_expr.h:106
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::bv_utils
bv_utilst bv_utils
Definition
boolbv.h:121
boolbvt::convert_bitwise
virtual bvt convert_bitwise(const exprt &expr)
Definition
boolbv_bitwise.cpp:13
boolbvt::boolbv_width
virtual std::size_t boolbv_width(const typet &type) const
Definition
boolbv.h:106
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
irept::id
const irep_idt & id() const
Definition
irep.h:388
literalt
Definition
literal.h:26
prop_conv_solvert::prop
propt & prop
Definition
prop_conv_solver.h:130
unary_exprt::op
const exprt & op() const
Definition
std_expr.h:384
forall_operands
#define forall_operands(it, expr)
Definition
expr.h:21
bvt
std::vector< literalt > bvt
Definition
literal.h:201
UNIMPLEMENTED
#define UNIMPLEMENTED
Definition
invariant.h:558
solvers
flattening
boolbv_bitwise.cpp
Generated by
1.17.0