ROSE  0.9.9.109
RegisterParts.h
1 #ifndef ROSE_BinaryAnalysis_RegisterParts_H
2 #define ROSE_BinaryAnalysis_RegisterParts_H
3 
4 #include <Sawyer/IntervalSet.h>
5 #include <Sawyer/Map.h>
6 #include <boost/serialization/access.hpp>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 
26 
27 private:
30 
31  // DQ (2/13/2017): Testing a simpler case.
32  // BitSet XXX;
33 
34 private:
35  class MajorMinor {
36  unsigned majr_, minr_;
37 
38 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
39  private:
40  friend class boost::serialization::access;
41 
42  template<class S>
43  void serialize(S &s, const unsigned version) {
44  s & BOOST_SERIALIZATION_NVP(majr_);
45  s & BOOST_SERIALIZATION_NVP(minr_);
46  }
47 #endif
48 
49  public:
50  MajorMinor(): majr_(0), minr_(0) {}
51 
52  MajorMinor(RegisterDescriptor reg) /*implicit*/
53  : majr_(reg.get_major()), minr_(reg.get_minor()) {}
54 
55  bool operator<(const MajorMinor &other) const {
56  return majr_ < other.majr_ || (majr_ == other.majr_ && minr_ < other.minr_);
57  }
58 
59  unsigned get_major() const { return majr_; } // "get_" works around Windows #define pollution
60  unsigned get_minor() const { return minr_; } // "get_" works around Windows #define pollution
61  };
62 
63 private:
64  // DQ (2/13/2017): Test alternative formulation.
66 
67  // DQ (2/13/2017): Testing a simpler case.
68  // typedef Sawyer::Container::Map<MajorMinor, BitSet > MapXXX;
69  // MapXXX Map_YYY;
70 
71  // DQ (2/13/2017): Both of these work fine.
72  // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< Sawyer::Container::Interval<size_t> > > Map;
73  // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< BitRange > > Map;
74  Map map_;
75 
76 
77 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
78 private:
79  friend class boost::serialization::access;
80 
81  template<class S>
82  void serialize(S &s, const unsigned version) {
83  s & BOOST_SERIALIZATION_NVP(map_);
84  }
85 #endif
86 
87 public:
90 
95  insert(reg);
96  }
97 
101  bool isEmpty() const {
102  return map_.isEmpty();
103  }
104 
109  bool existsAny(RegisterDescriptor reg) const {
110  return map_.exists(reg) && map_[reg].isOverlapping(bitRange(reg));
111  }
112 
117  bool existsAll(RegisterDescriptor reg) const {
118  return map_.exists(reg) && map_[reg].contains(bitRange(reg));
119  }
120 
126  map_.insertMaybeDefault(reg).insert(bitRange(reg));
127  }
128 
133  void erase(RegisterDescriptor reg);
134 
138  void clear() {
139  map_.clear();
140  }
141 
145  RegisterParts& operator-=(const RegisterParts &other);
146 
150  RegisterParts operator-(const RegisterParts &other) const;
151 
155  RegisterParts& operator|=(const RegisterParts &other);
156 
160  RegisterParts operator|(const RegisterParts &other) const;
161 
165  RegisterParts& operator&=(const RegisterParts &other);
166 
170  RegisterParts operator&(const RegisterParts &other) const;
171 
181  std::vector<RegisterDescriptor> extract(const RegisterDictionary *regDict = NULL, bool extractAll = false);
182 
193  std::vector<RegisterDescriptor> listAll(const RegisterDictionary*) const;
194  std::vector<RegisterDescriptor> listNamed(const RegisterDictionary*) const;
198 private:
199  static BitRange bitRange(RegisterDescriptor reg) {
200  ASSERT_require(reg.is_valid());
201  return BitRange::baseSize(reg.get_offset(), reg.get_nbits());
202  }
203 
204 };
205 
206 } // namespace
207 } // namespace
208 
209 #endif
std::vector< RegisterDescriptor > listAll(const RegisterDictionary *) const
List registers present.
void insert(RegisterDescriptor reg)
Insert register into container.
RegisterParts & operator&=(const RegisterParts &other)
Erase some register parts.
bool exists(const Key &key) const
Determine if a key exists.
Definition: Sawyer/Map.h:377
RegisterParts(RegisterDescriptor reg)
Constructor to insert a register.
Definition: RegisterParts.h:94
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:595
Main namespace for the ROSE library.
Describes (part of) a physical CPU register.
Map & clear()
Remove all nodes.
Definition: Sawyer/Map.h:616
Holds a set of registers without regard for register boundaries.
Definition: RegisterParts.h:25
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:161
bool isEmpty() const
Determines whether this container is empty.
Definition: Sawyer/Map.h:315
void clear()
Erase everything.
bool isEmpty() const
Predicate checking whether this container is empty.
std::vector< RegisterDescriptor > listNamed(const RegisterDictionary *) const
List registers present.
Defines registers available for a particular architecture.
Definition: Registers.h:32
RegisterParts operator&(const RegisterParts &other) const
Compute the intersection.
RegisterParts()
Default construct an object with no register parts.
Definition: RegisterParts.h:89
bool existsAny(RegisterDescriptor reg) const
Predicate checking if part of a register is present.
RegisterParts & operator-=(const RegisterParts &other)
Erase some register parts.
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.