cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_mult.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
bvt
boolbvt::convert_mult
(
const
mult_exprt
&expr)
14
{
15
std::size_t width=
boolbv_width
(expr.
type
());
16
17
bvt
bv;
18
bv.resize(width);
19
20
const
exprt::operandst
&operands=expr.
operands
();
21
DATA_INVARIANT
(!operands.empty(),
"multiplication must have operands"
);
22
23
const
exprt
&op0=expr.
op0
();
24
25
DATA_INVARIANT
(
26
op0.
type
() == expr.
type
(),
27
"multiplication operands should have same type as expression"
);
28
29
if
(expr.
type
().
id
()==ID_fixedbv)
30
{
31
bv =
convert_bv
(op0, width);
32
33
std::size_t fraction_bits=
34
to_fixedbv_type
(expr.
type
()).
get_fraction_bits
();
35
36
for
(exprt::operandst::const_iterator it=operands.begin()+1;
37
it!=operands.end(); it++)
38
{
39
DATA_INVARIANT
(
40
it->type() == expr.
type
(),
41
"multiplication operands should have same type as expression"
);
42
43
// do a sign extension by fraction_bits bits
44
bv=
bv_utils
.sign_extension(bv, bv.size()+fraction_bits);
45
46
bvt
op =
convert_bv
(*it, width);
47
48
op=
bv_utils
.sign_extension(op, bv.size());
49
50
bv=
bv_utils
.signed_multiplier(bv, op);
51
52
// cut it down again
53
bv.erase(bv.begin(), bv.begin()+fraction_bits);
54
}
55
56
return
bv;
57
}
58
else
if
(expr.
type
().
id
()==ID_unsignedbv ||
59
expr.
type
().
id
()==ID_signedbv)
60
{
61
bv_utilst::representationt
rep=
62
expr.
type
().
id
()==ID_signedbv?
bv_utilst::representationt::SIGNED
:
63
bv_utilst::representationt::UNSIGNED
;
64
65
bv =
convert_bv
(op0, width);
66
67
for
(exprt::operandst::const_iterator it=operands.begin()+1;
68
it!=operands.end(); it++)
69
{
70
DATA_INVARIANT
(
71
it->type() == expr.
type
(),
72
"multiplication operands should have same type as expression"
);
73
74
const
bvt
&op =
convert_bv
(*it, width);
75
76
bv =
bv_utils
.multiplier(bv, op, rep);
77
}
78
79
return
bv;
80
}
81
82
return
conversion_failed
(expr);
83
}
bitvector_types.h
Pre-defined bitvector types.
to_fixedbv_type
const fixedbv_typet & to_fixedbv_type(const typet &type)
Cast a typet to a fixedbv_typet.
Definition
bitvector_types.h:324
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_mult
virtual bvt convert_mult(const mult_exprt &expr)
Definition
boolbv_mult.cpp:13
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
bv_utilst::representationt
representationt
Definition
bv_utils.h:28
bv_utilst::representationt::SIGNED
@ SIGNED
Definition
bv_utils.h:28
bv_utilst::representationt::UNSIGNED
@ UNSIGNED
Definition
bv_utils.h:28
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
fixedbv_typet::get_fraction_bits
std::size_t get_fraction_bits() const
Definition
bitvector_types.h:286
irept::id
const irep_idt & id() const
Definition
irep.h:388
mult_exprt
Binary multiplication Associativity is not specified.
Definition
std_expr.h:1094
multi_ary_exprt::op0
exprt & op0()
Definition
std_expr.h:926
bvt
std::vector< literalt > bvt
Definition
literal.h:201
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
solvers
flattening
boolbv_mult.cpp
Generated by
1.17.0