ROSE  0.11.145.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 <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Sawyer/IntervalSet.h>
8 #include <Sawyer/Map.h>
9 #include <boost/serialization/access.hpp>
10 
11 namespace Rose {
12 namespace BinaryAnalysis {
13 
29 
30 private:
33 
34  // DQ (2/13/2017): Testing a simpler case.
35  // BitSet XXX;
36 
37 private:
38  class MajorMinor {
39  unsigned majr_, minr_;
40 
41 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
42  private:
43  friend class boost::serialization::access;
44 
45  template<class S>
46  void serialize(S &s, const unsigned /*version*/) {
47  s & BOOST_SERIALIZATION_NVP(majr_);
48  s & BOOST_SERIALIZATION_NVP(minr_);
49  }
50 #endif
51 
52  public:
53  MajorMinor(): majr_(0), minr_(0) {}
54 
55  MajorMinor(RegisterDescriptor reg) /*implicit*/
56  : majr_(reg.majorNumber()), minr_(reg.minorNumber()) {}
57 
58  bool operator<(const MajorMinor &other) const {
59  return majr_ < other.majr_ || (majr_ == other.majr_ && minr_ < other.minr_);
60  }
61 
62  unsigned get_major() const { return majr_; } // "get_" works around Windows #define pollution
63  unsigned get_minor() const { return minr_; } // "get_" works around Windows #define pollution
64  };
65 
66 private:
67  // DQ (2/13/2017): Test alternative formulation.
69 
70  // DQ (2/13/2017): Testing a simpler case.
71  // typedef Sawyer::Container::Map<MajorMinor, BitSet > MapXXX;
72  // MapXXX Map_YYY;
73 
74  // DQ (2/13/2017): Both of these work fine.
75  // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< Sawyer::Container::Interval<size_t> > > Map;
76  // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< BitRange > > Map;
77  Map map_;
78 
79 
80 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
81 private:
82  friend class boost::serialization::access;
83 
84  template<class S>
85  void serialize(S &s, const unsigned /*version*/) {
86  s & BOOST_SERIALIZATION_NVP(map_);
87  }
88 #endif
89 
90 public:
93 
98  insert(reg);
99  }
100 
104  bool isEmpty() const {
105  return map_.isEmpty();
106  }
107 
112  bool existsAny(RegisterDescriptor reg) const {
113  return map_.exists(reg) && map_[reg].overlaps(bitRange(reg));
114  }
115 
120  bool existsAll(RegisterDescriptor reg) const {
121  return map_.exists(reg) && map_[reg].contains(bitRange(reg));
122  }
123 
129  map_.insertMaybeDefault(reg).insert(bitRange(reg));
130  }
131 
136  void erase(RegisterDescriptor reg);
137 
141  void clear() {
142  map_.clear();
143  }
144 
148  RegisterParts& operator-=(const RegisterParts &other);
149 
153  RegisterParts operator-(const RegisterParts &other) const;
154 
158  RegisterParts& operator|=(const RegisterParts &other);
159 
163  RegisterParts operator|(const RegisterParts &other) const;
164 
168  RegisterParts& operator&=(const RegisterParts &other);
169 
173  RegisterParts operator&(const RegisterParts &other) const;
174 
184  std::vector<RegisterDescriptor> extract(const RegisterDictionaryPtr &regDict, bool extractAll = false);
185 
196  std::vector<RegisterDescriptor> listAll(const RegisterDictionaryPtr&) const;
197  std::vector<RegisterDescriptor> listNamed(const RegisterDictionaryPtr&) const;
201 private:
202  static BitRange bitRange(RegisterDescriptor reg) {
203  ASSERT_forbid(reg.isEmpty());
204  return BitRange::baseSize(reg.offset(), reg.nBits());
205  }
206 
207 };
208 
209 } // namespace
210 } // namespace
211 
212 #endif
213 #endif
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:475
size_t nBits() const
Property: Size in bits.
RegisterParts(RegisterDescriptor reg)
Constructor to insert a register.
Definition: RegisterParts.h:97
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:693
Main namespace for the ROSE library.
Map & clear()
Remove all nodes.
Definition: Sawyer/Map.h:714
Holds a set of registers without regard for register boundaries.
Definition: RegisterParts.h:28
void erase(RegisterDescriptor reg)
Erase register from container.
A container holding a set of values.
Definition: IntervalSet.h:55
std::vector< RegisterDescriptor > listAll(const RegisterDictionaryPtr &) const
List registers present.
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:413
void clear()
Erase everything.
std::vector< RegisterDescriptor > extract(const RegisterDictionaryPtr &regDict, bool extractAll=false)
Extract individual registers.
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.
RegisterParts operator&(const RegisterParts &other) const
Compute the intersection.
RegisterParts()
Default construct an object with no register parts.
Definition: RegisterParts.h:92
bool existsAny(RegisterDescriptor reg) const
Predicate checking if part of a register is present.
unsigned minorNumber() const
Property: Minor number.
std::vector< RegisterDescriptor > listNamed(const RegisterDictionaryPtr &) const
List registers present.
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.