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  explicit endianness_mapt(const namespacet &_ns) : ns(_ns)
41  {
42  }
43 
44  virtual ~endianness_mapt() = default;
45 
46  size_t map_bit(size_t bit) const
47  {
48  assert(bit<map.size());
49  size_t result=map[bit];
50  assert(result<map.size());
51  return result;
52  }
53 
54  size_t number_of_bits() const
55  {
56  return map.size();
57  }
58 
59  void build(const typet &type, bool little_endian);
60 
61  void output(std::ostream &) const;
62 
63 protected:
64  const namespacet &ns;
65  std::vector<size_t> map; // bit-nr to bit-nr
66 
67  virtual void build_little_endian(const typet &type);
68  virtual void build_big_endian(const typet &type);
69 };
70 
71 inline std::ostream &operator<<(
72  std::ostream &out,
73  const endianness_mapt &m)
74 {
75  m.output(out);
76  return out;
77 }
78 
79 #endif // CPROVER_UTIL_ENDIANNESS_MAP_H
The type of an expression.
Definition: type.h:22
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:74
endianness_mapt(const namespacet &_ns)
virtual 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
virtual void build_little_endian(const typet &type)
virtual ~endianness_mapt()=default