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/invariant.h>
12 
14 {
15  const std::size_t width = boolbv_width(expr.type());
16 
17  // width must be multiple of bytes
18  const std::size_t byte_bits = expr.get_bits_per_byte();
19  if(width % byte_bits != 0)
20  return conversion_failed(expr);
21 
22  bvt result = convert_bv(expr.op());
23  CHECK_RETURN(result.size() == 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 }
const exprt & op() const
Definition: std_expr.h:340
boolbv_widtht boolbv_width
Definition: boolbv.h:90
typet & type()
Definition: expr.h:56
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:245
virtual const bvt & convert_bv(const exprt &expr)
Definition: boolbv.cpp:116
virtual bvt convert_bswap(const bswap_exprt &expr)
void conversion_failed(const exprt &expr, bvt &bv)
Definition: boolbv.h:108
mstreamt & result() const
Definition: message.h:312
std::size_t get_bits_per_byte() const
Definition: std_expr.h:521
std::vector< literalt > bvt
Definition: literal.h:200
The byte swap expression.
Definition: std_expr.h:506