cprover
endianness_map.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_ENDIANNESS_MAP_H
11 #define CPROVER_UTIL_ENDIANNESS_MAP_H
12 
20 #include <cassert>
21 #include <iosfwd>
22 #include <vector>
23 
24 class namespacet;
25 class typet;
26 
30 {
31 public:
33  const typet &type,
34  bool little_endian,
35  const namespacet &_ns):ns(_ns)
36  {
37  build(type, little_endian);
38  }
39 
40  size_t map_bit(size_t bit) const
41  {
42  assert(bit<map.size());
43  size_t result=map[bit];
44  assert(result<map.size());
45  return result;
46  }
47 
48  size_t number_of_bits() const
49  {
50  return map.size();
51  }
52 
53  void build(const typet &type, bool little_endian);
54 
55  void output(std::ostream &) const;
56 
57 protected:
58  const namespacet &ns;
59  std::vector<size_t> map; // bit-nr to bit-nr
60 
61  void build_little_endian(const typet &type);
62  void build_big_endian(const typet &type);
63 };
64 
65 inline std::ostream &operator<<(
66  std::ostream &out,
67  const endianness_mapt &m)
68 {
69  m.output(out);
70  return out;
71 }
72 
73 #endif // CPROVER_UTIL_ENDIANNESS_MAP_H
The type of an expression.
Definition: type.h:20
Maps a big-endian offset to a little-endian offset.
void build(const typet &type, bool little_endian)
std::ostream & operator<<(std::ostream &out, const endianness_mapt &m)
void output(std::ostream &) const
TO_BE_DOCUMENTED.
Definition: namespace.h:62
void build_big_endian(const typet &type)
endianness_mapt(const typet &type, bool little_endian, const namespacet &_ns)
size_t number_of_bits() const
std::vector< size_t > map
const namespacet & ns
size_t map_bit(size_t bit) const
void build_little_endian(const typet &type)