cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_unary_minus.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_types.h
>
12
13
#include <
solvers/floatbv/float_utils.h
>
14
15
#include <algorithm>
16
#include <iterator>
17
18
#include "
boolbv_type.h
"
19
20
bvt
boolbvt::convert_unary_minus
(
const
unary_minus_exprt
&expr)
21
{
22
const
typet
&type = expr.
type
();
23
24
std::size_t width=
boolbv_width
(type);
25
26
const
exprt
&op = expr.
op
();
27
28
const
bvt
&op_bv =
convert_bv
(op, width);
29
30
bvtypet
bvtype=
get_bvtype
(type);
31
bvtypet
op_bvtype =
get_bvtype
(op.
type
());
32
33
if
(bvtype ==
bvtypet::IS_UNKNOWN
&& type.
id
() == ID_complex)
34
{
35
const
typet
&subtype =
to_type_with_subtype
(type).
subtype
();
36
37
std::size_t sub_width=
boolbv_width
(subtype);
38
39
INVARIANT
(
40
sub_width > 0,
41
"bitvector representation of type needs to have at least one bit"
);
42
43
INVARIANT
(
44
width % sub_width == 0,
45
"total bitvector width needs to be a multiple of the component bitvector "
46
"widths"
);
47
48
bvt
bv;
49
50
for
(std::size_t sub_idx = 0; sub_idx < width; sub_idx += sub_width)
51
{
52
bvt
tmp_op;
53
54
const
auto
sub_it = std::next(op_bv.begin(), sub_idx);
55
std::copy_n(sub_it, sub_width, std::back_inserter(tmp_op));
56
57
if
(subtype.
id
() == ID_floatbv)
58
{
59
float_utilst
float_utils(
prop
,
to_floatbv_type
(subtype));
60
tmp_op = float_utils.
negate
(tmp_op);
61
}
62
else
63
tmp_op =
bv_utils
.negate(tmp_op);
64
65
INVARIANT
(
66
tmp_op.size() == sub_width,
67
"bitvector after negation shall have same bit width"
);
68
69
std::copy(tmp_op.begin(), tmp_op.end(), std::back_inserter(bv));
70
}
71
72
return
bv;
73
}
74
else
if
(bvtype==
bvtypet::IS_FIXED
&& op_bvtype==
bvtypet::IS_FIXED
)
75
{
76
return
bv_utils
.negate(op_bv);
77
}
78
else
if
(bvtype==
bvtypet::IS_FLOAT
&& op_bvtype==
bvtypet::IS_FLOAT
)
79
{
80
float_utilst
float_utils(
prop
,
to_floatbv_type
(expr.
type
()));
81
return
float_utils.
negate
(op_bv);
82
}
83
else
if
((op_bvtype==
bvtypet::IS_SIGNED
|| op_bvtype==
bvtypet::IS_UNSIGNED
) &&
84
(bvtype==
bvtypet::IS_SIGNED
|| bvtype==
bvtypet::IS_UNSIGNED
))
85
{
86
return
bv_utils
.negate(op_bv);
87
}
88
89
return
conversion_failed
(expr);
90
}
bitvector_types.h
Pre-defined bitvector types.
to_floatbv_type
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
Definition
bitvector_types.h:386
boolbv.h
get_bvtype
bvtypet get_bvtype(const typet &type)
Definition
boolbv_type.cpp:13
boolbv_type.h
bvtypet
bvtypet
Definition
boolbv_type.h:17
bvtypet::IS_FIXED
@ IS_FIXED
Definition
boolbv_type.h:18
bvtypet::IS_UNKNOWN
@ IS_UNKNOWN
Definition
boolbv_type.h:19
bvtypet::IS_FLOAT
@ IS_FLOAT
Definition
boolbv_type.h:18
bvtypet::IS_SIGNED
@ IS_SIGNED
Definition
boolbv_type.h:18
bvtypet::IS_UNSIGNED
@ IS_UNSIGNED
Definition
boolbv_type.h:18
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_unary_minus
virtual bvt convert_unary_minus(const unary_minus_exprt &expr)
Definition
boolbv_unary_minus.cpp:20
boolbvt::bv_utils
bv_utilst bv_utils
Definition
boolbv.h:121
boolbvt::conversion_failed
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
Definition
boolbv.cpp:95
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
float_utilst
Definition
float_utils.h:18
float_utilst::negate
bvt negate(const bvt &)
Definition
float_utils.cpp:709
irept::id
const irep_idt & id() const
Definition
irep.h:388
prop_conv_solvert::prop
propt & prop
Definition
prop_conv_solver.h:130
type_with_subtypet::subtype
const typet & subtype() const
Definition
type.h:187
typet
The type of an expression, extends irept.
Definition
type.h:29
unary_exprt::op
const exprt & op() const
Definition
std_expr.h:384
unary_minus_exprt
The unary minus expression.
Definition
std_expr.h:467
float_utils.h
bvt
std::vector< literalt > bvt
Definition
literal.h:201
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition
invariant.h:423
to_type_with_subtype
const type_with_subtypet & to_type_with_subtype(const typet &type)
Definition
type.h:208
solvers
flattening
boolbv_unary_minus.cpp
Generated by
1.17.0