cprover
boolbv_bswap.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Bit-blasting of bswap
4 
5 Author: Michael Tautschnig
6 
7 \*******************************************************************/
8 
9 #include "boolbv.h"
10 
11 #include <util/bitvector_expr.h>
12 #include <util/invariant.h>
13 
15 {
16  const std::size_t width = boolbv_width(expr.type());
17 
18  // width must be multiple of bytes
19  const std::size_t byte_bits = expr.get_bits_per_byte();
20  if(width % byte_bits != 0)
21  return conversion_failed(expr);
22 
23  bvt result = convert_bv(expr.op(), width);
24 
25  std::size_t dest_base = width;
26 
27  for(std::size_t src = 0; src < width; ++src)
28  {
29  std::size_t bit_offset = src % byte_bits;
30  if(bit_offset == 0)
31  dest_base -= byte_bits;
32 
33  if(src >= dest_base)
34  break;
35 
36  result[src].swap(result[dest_base + bit_offset]);
37  }
38 
39  return result;
40 }
API to expression classes for bitvectors.
virtual bvt convert_bswap(const bswap_exprt &expr)
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:38
void conversion_failed(const exprt &expr, bvt &bv)
Definition: boolbv.h:124
virtual std::size_t boolbv_width(const typet &type) const
Definition: boolbv.h:96
The byte swap expression.
std::size_t get_bits_per_byte() const
typet & type()
Return the type of the expression.
Definition: expr.h:82
const exprt & op() const
Definition: std_expr.h:294
std::vector< literalt > bvt
Definition: literal.h:201