cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_extractbits.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/arith_tools.h
>
12
#include <
util/bitvector_expr.h
>
13
14
bvt
boolbvt::convert_extractbits
(
const
extractbits_exprt
&expr)
15
{
16
const
std::size_t
bv_width
=
boolbv_width
(expr.
type
());
17
18
auto
const
&src_bv =
convert_bv
(expr.
src
());
19
20
auto
const
maybe_index_as_int =
numeric_cast<mp_integer>
(expr.
index
());
21
22
// We only do constants for now.
23
// Should implement a shift here.
24
if
(!maybe_index_as_int.has_value())
25
return
conversion_failed
(expr);
26
27
auto
index_as_int = maybe_index_as_int.value();
28
29
DATA_INVARIANT_WITH_DIAGNOSTICS
(
30
index_as_int >= 0 && index_as_int < src_bv.size(),
31
"index of extractbits must be within the bitvector"
,
32
expr.
find_source_location
(),
33
irep_pretty_diagnosticst
{expr});
34
35
DATA_INVARIANT_WITH_DIAGNOSTICS
(
36
index_as_int +
bv_width
- 1 < src_bv.size(),
37
"index+width-1 of extractbits must be within the bitvector"
,
38
expr.
find_source_location
(),
39
irep_pretty_diagnosticst
{expr});
40
41
const
std::size_t offset =
numeric_cast_v<std::size_t>
(index_as_int);
42
43
bvt
result_bv(src_bv.begin() + offset, src_bv.begin() + offset +
bv_width
);
44
45
return
result_bv;
46
}
arith_tools.h
numeric_cast_v
Target numeric_cast_v(const mp_integer &arg)
Convert an mp_integer to integral type Target An invariant will fail if the conversion is not possibl...
Definition
arith_tools.h:135
numeric_cast
std::optional< Target > numeric_cast(const exprt &arg)
Converts an expression to any integral type.
Definition
arith_tools.h:124
bitvector_expr.h
API to expression classes for bitvectors.
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_width
boolbv_widtht bv_width
Definition
boolbv.h:120
boolbvt::convert_extractbits
virtual bvt convert_extractbits(const extractbits_exprt &expr)
Definition
boolbv_extractbits.cpp:14
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::find_source_location
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition
expr.cpp:68
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
extractbits_exprt
Extracts a sub-range of a bit-vector operand.
Definition
bitvector_expr.h:639
extractbits_exprt::index
exprt & index()
Definition
bitvector_expr.h:661
extractbits_exprt::src
exprt & src()
Definition
bitvector_expr.h:656
bvt
std::vector< literalt > bvt
Definition
literal.h:201
DATA_INVARIANT_WITH_DIAGNOSTICS
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Definition
invariant.h:535
irep_pretty_diagnosticst
Definition
irep.h:495
solvers
flattening
boolbv_extractbits.cpp
Generated by
1.17.0