ROSE  0.11.51.0
RegisterParts.h
1 #ifndef ROSE_BinaryAnalysis_RegisterParts_H
2 #define ROSE_BinaryAnalysis_RegisterParts_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Sawyer/IntervalSet.h>
7 #include <Sawyer/Map.h>
8 #include <boost/serialization/access.hpp>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 
28 
29 private:
32 
33  // DQ (2/13/2017): Testing a simpler case.
34  // BitSet XXX;
35 
36 private:
37  class MajorMinor {
38  unsigned majr_, minr_;
39 
40 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
41  private:
42  friend class boost::serialization::access;
43 
44  template<class S>
45  void serialize(S &s, const unsigned /*version*/) {
46  s & BOOST_SERIALIZATION_NVP(majr_);
47  s & BOOST_SERIALIZATION_NVP(minr_);
48  }
49 #endif
50 
51  public:
52  MajorMinor(): majr_(0), minr_(0) {}
53 
54  MajorMinor(RegisterDescriptor reg) /*implicit*/
55  : majr_(reg.majorNumber()), minr_(reg.minorNumber()) {}
56 
57  bool operator<(const MajorMinor &other) const {
58  return majr_ < other.majr_ || (majr_ == other.majr_ && minr_ < other.minr_);
59  }
60 
61  unsigned get_major() const { return majr_; } // "get_" works around Windows #define pollution
62  unsigned get_minor() const { return minr_; } // "get_" works around Windows #define pollution
63  };
64 
65 private:
66  // DQ (2/13/2017): Test alternative formulation.
68 
69  // DQ (2/13/2017): Testing a simpler case.
70  // typedef Sawyer::Container::Map<MajorMinor, BitSet > MapXXX;
71  // MapXXX Map_YYY;
72 
73  // DQ (2/13/2017): Both of these work fine.
74  // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< Sawyer::Container::Interval<size_t> > > Map;
75  // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< BitRange > > Map;
76  Map map_;
77 
78 
79 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
80 private:
81  friend class boost::serialization::access;
82 
83  template<class S>
84  void serialize(S &s, const unsigned /*version*/) {
85  s & BOOST_SERIALIZATION_NVP(map_);
86  }
87 #endif
88 
89 public:
92 
97  insert(reg);
98  }
99 
103  bool isEmpty() const {
104  return map_.isEmpty();
105  }
106 
111  bool existsAny(RegisterDescriptor reg) const {
112  return map_.exists(reg) && map_[reg].isOverlapping(bitRange(reg));
113  }
114 
119  bool existsAll(RegisterDescriptor reg) const {
120  return map_.exists(reg) && map_[reg].contains(bitRange(reg));
121  }
122 
128  map_.insertMaybeDefault(reg).insert(bitRange(reg));
129  }
130 
135  void erase(RegisterDescriptor reg);
136 
140  void clear() {
141  map_.clear();
142  }
143 
147  RegisterParts& operator-=(const RegisterParts &other);
148 
152  RegisterParts operator-(const RegisterParts &other) const;
153 
157  RegisterParts& operator|=(const RegisterParts &other);
158 
162  RegisterParts operator|(const RegisterParts &other) const;
163 
167  RegisterParts& operator&=(const RegisterParts &other);
168 
172  RegisterParts operator&(const RegisterParts &other) const;
173 
183  std::vector<RegisterDescriptor> extract(const RegisterDictionary *regDict = NULL, bool extractAll = false);
184 
195  std::vector<RegisterDescriptor> listAll(const RegisterDictionary*) const;
196  std::vector<RegisterDescriptor> listNamed(const RegisterDictionary*) const;
200 private:
201  static BitRange bitRange(RegisterDescriptor reg) {
202  ASSERT_forbid(reg.isEmpty());
203  return BitRange::baseSize(reg.offset(), reg.nBits());
204  }
205 
206 };
207 
208 } // namespace
209 } // namespace
210 
211 #endif
212 #endif
std::vector< RegisterDescriptor > listAll(const RegisterDictionary *) const
List registers present.
void insert(RegisterDescriptor reg)
Insert register into container.
unsigned majorNumber() const
Property: Major number.
RegisterParts & operator&=(const RegisterParts &other)
Erase some register parts.
bool exists(const Key &key) const
Determine if a key exists.
Definition: Sawyer/Map.h:441
size_t nBits() const
Property: Size in bits.
RegisterParts(RegisterDescriptor reg)
Constructor to insert a register.
Definition: RegisterParts.h:96
RegisterParts operator-(const RegisterParts &other) const
Compute difference.
Value & insertMaybeDefault(const Key &key)
Conditionally insert a new key with default value.
Definition: Sawyer/Map.h:659
Main namespace for the ROSE library.
Map & clear()
Remove all nodes.
Definition: Sawyer/Map.h:680
Holds a set of registers without regard for register boundaries.
Definition: RegisterParts.h:27
std::vector< RegisterDescriptor > extract(const RegisterDictionary *regDict=NULL, bool extractAll=false)
Extract individual registers.
void erase(RegisterDescriptor reg)
Erase register from container.
A container holding a set of values.
Definition: IntervalSet.h:55
static Interval baseSize(size_t lo, size_t size)
Construct an interval from one endpoint and a size.
Definition: Interval.h:162
bool isEmpty() const
Determines whether this container is empty.
Definition: Sawyer/Map.h:379
void clear()
Erase everything.
Describes (part of) a physical CPU register.
bool isEmpty() const
Predicate checking whether this container is empty.
size_t offset() const
Property: Offset to least-significant bit.
std::vector< RegisterDescriptor > listNamed(const RegisterDictionary *) const
List registers present.
RegisterParts operator&(const RegisterParts &other) const
Compute the intersection.
RegisterParts()
Default construct an object with no register parts.
Definition: RegisterParts.h:91
bool existsAny(RegisterDescriptor reg) const
Predicate checking if part of a register is present.
Defines registers available for a particular architecture.
Definition: Registers.h:37
unsigned minorNumber() const
Property: Minor number.
RegisterParts & operator-=(const RegisterParts &other)
Erase some register parts.
bool isEmpty() const
Predicate returns true if the width is zero.
bool existsAll(RegisterDescriptor reg) const
Predicate checking if all of a register is present.
RegisterParts operator|(const RegisterParts &other) const
Compute the union.
RegisterParts & operator|=(const RegisterParts &other)
Add some register parts.