CBMC
boolbv_concatenation.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_expr.h>
12 #include <util/invariant.h>
13 
15 {
16  std::size_t width=boolbv_width(expr.type());
17 
18  const exprt::operandst &operands=expr.operands();
19 
21  !operands.empty(), "concatenation shall have at least one operand");
22 
23  std::size_t offset=width;
24  bvt bv;
25  bv.resize(width);
26 
27  for(const auto &operand : operands)
28  {
29  const bvt &op = convert_bv(operand);
30 
31  INVARIANT(
32  op.size() <= offset,
33  "concatenation operand must fit into the result bitvector");
34 
35  offset-=op.size();
36 
37  for(std::size_t i=0; i<op.size(); i++)
38  bv[offset+i]=op[i];
39  }
40 
41  INVARIANT(
42  offset == 0,
43  "all bits in the result bitvector must have been filled up by the "
44  "concatenation operands");
45 
46  return bv;
47 }
API to expression classes for bitvectors.
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:37
virtual std::size_t boolbv_width(const typet &type) const
Definition: boolbv.h:101
virtual bvt convert_concatenation(const concatenation_exprt &expr)
Concatenation of bit-vector operands.
std::vector< exprt > operandst
Definition: expr.h:58
typet & type()
Return the type of the expression.
Definition: expr.h:84
operandst & operands()
Definition: expr.h:94
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:534