cprover
Loading...
Searching...
No Matches
boolbv_concatenation.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
11#include <util/bitvector_expr.h>
12#include <util/invariant.h>
13
15{
16 std::size_t width=boolbv_width(expr.type());
17
18 if(width==0)
19 return conversion_failed(expr);
20
21 const exprt::operandst &operands=expr.operands();
22
24 !operands.empty(), "concatentation shall have at least one operand");
25
26 std::size_t offset=width;
27 bvt bv;
28 bv.resize(width);
29
30 for(const auto &operand : operands)
31 {
32 const bvt &op = convert_bv(operand);
33
35 op.size() <= offset,
36 "concatentation operand must fit into the result bitvector");
37
38 offset-=op.size();
39
40 for(std::size_t i=0; i<op.size(); i++)
41 bv[offset+i]=op[i];
42 }
43
45 offset == 0,
46 "all bits in the result bitvector must have been filled up by the "
47 "concatentation operands");
48
49 return bv;
50}
API to expression classes for bitvectors.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:564
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
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 std::size_t boolbv_width(const typet &type) const
Definition boolbv.h:99
virtual bvt convert_concatenation(const concatenation_exprt &expr)
Concatenation of bit-vector operands.
std::vector< exprt > operandst
Definition expr.h:56
typet & type()
Return the type of the expression.
Definition expr.h:82
operandst & operands()
Definition expr.h:92
std::vector< literalt > bvt
Definition literal.h:201
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:510
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423