cprover
Loading...
Searching...
No Matches
boolbv_union.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "boolbv.h"
10
12{
13 std::size_t width=boolbv_width(expr.type());
14
15 if(width==0)
16 return conversion_failed(expr);
17
18 const bvt &op_bv=convert_bv(expr.op());
19
21 op_bv.size() <= width,
22 "operand bitvector width shall not be larger than the width indicated by "
23 "the union type");
24
25 bvt bv;
26 bv.resize(width);
27
28 endianness_mapt map_u = endianness_map(expr.type());
29 endianness_mapt map_op = endianness_map(expr.op().type());
30
31 for(std::size_t i = 0; i < op_bv.size(); i++)
32 bv[map_u.map_bit(i)] = op_bv[map_op.map_bit(i)];
33
34 // pad with nondets
35 for(std::size_t i = op_bv.size(); i < bv.size(); i++)
36 bv[map_u.map_bit(i)] = prop.new_variable();
37
38 return bv;
39}
40
42{
43 return {};
44}
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition: boolbv.cpp:40
virtual bvt convert_empty_union(const empty_union_exprt &expr)
virtual bvt convert_union(const union_exprt &expr)
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:84
virtual endianness_mapt endianness_map(const typet &type, bool little_endian) const
Definition: boolbv.h:105
virtual std::size_t boolbv_width(const typet &type) const
Definition: boolbv.h:99
Union constructor to support unions without any member (a GCC/Clang feature).
Definition: std_expr.h:1677
Maps a big-endian offset to a little-endian offset.
size_t map_bit(size_t bit) const
typet & type()
Return the type of the expression.
Definition: expr.h:82
virtual literalt new_variable()=0
const exprt & op() const
Definition: std_expr.h:293
Union constructor from single element.
Definition: std_expr.h:1611
std::vector< literalt > bvt
Definition: literal.h:201
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:423