cprover
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  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 
34  INVARIANT(
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 
44  INVARIANT(
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 }
bvt
std::vector< literalt > bvt
Definition: literal.h:201
invariant.h
concatenation_exprt
Concatenation of bit-vector operands.
Definition: bitvector_expr.h:590
boolbvt::convert_concatenation
virtual bvt convert_concatenation(const concatenation_exprt &expr)
Definition: boolbv_concatenation.cpp:14
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:82
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:510
boolbvt::boolbv_width
virtual std::size_t boolbv_width(const typet &type) const
Definition: boolbv.h:97
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:56
boolbvt::convert_bv
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
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:84
boolbv.h
exprt::operands
operandst & operands()
Definition: expr.h:92
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:423
bitvector_expr.h
API to expression classes for bitvectors.