ROSE 0.11.145.247
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
8#include <Sawyer/IntervalSet.h>
9#include <Sawyer/Map.h>
10
11#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
12#include <boost/serialization/access.hpp>
13#endif
14
15namespace Rose {
16namespace BinaryAnalysis {
17
33
34private:
37
38 // DQ (2/13/2017): Testing a simpler case.
39 // BitSet XXX;
40
41private:
42 class MajorMinor {
43 unsigned majr_, minr_;
44
45#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
46 private:
47 friend class boost::serialization::access;
48
49 template<class S>
50 void serialize(S &s, const unsigned /*version*/) {
51 s & BOOST_SERIALIZATION_NVP(majr_);
52 s & BOOST_SERIALIZATION_NVP(minr_);
53 }
54#endif
55
56 public:
57 MajorMinor(): majr_(0), minr_(0) {}
58
59 MajorMinor(RegisterDescriptor reg) /*implicit*/
60 : majr_(reg.majorNumber()), minr_(reg.minorNumber()) {}
61
62 bool operator<(const MajorMinor &other) const {
63 return majr_ < other.majr_ || (majr_ == other.majr_ && minr_ < other.minr_);
64 }
65
66 unsigned get_major() const { return majr_; } // "get_" works around Windows #define pollution
67 unsigned get_minor() const { return minr_; } // "get_" works around Windows #define pollution
68 };
69
70private:
71 // DQ (2/13/2017): Test alternative formulation.
73
74 // DQ (2/13/2017): Testing a simpler case.
75 // typedef Sawyer::Container::Map<MajorMinor, BitSet > MapXXX;
76 // MapXXX Map_YYY;
77
78 // DQ (2/13/2017): Both of these work fine.
79 // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< Sawyer::Container::Interval<size_t> > > Map;
80 // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< BitRange > > Map;
81 Map map_;
82
83
84#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
85private:
86 friend class boost::serialization::access;
87
88 template<class S>
89 void serialize(S &s, const unsigned /*version*/) {
90 s & BOOST_SERIALIZATION_NVP(map_);
91 }
92#endif
93
94public:
97
102 insert(reg);
103 }
104
108 bool isEmpty() const {
109 return map_.isEmpty();
110 }
111
117 return map_.exists(reg) && map_[reg].overlaps(bitRange(reg));
118 }
119
125 return map_.exists(reg) && map_[reg].contains(bitRange(reg));
126 }
127
133 map_.insertMaybeDefault(reg).insert(bitRange(reg));
134 }
135
141
145 void clear() {
146 map_.clear();
147 }
148
153
158
163
168
173
178
188 std::vector<RegisterDescriptor> extract(const RegisterDictionaryPtr &regDict, bool extractAll = false);
189
200 std::vector<RegisterDescriptor> listAll(const RegisterDictionaryPtr&) const;
201 std::vector<RegisterDescriptor> listNamed(const RegisterDictionaryPtr&) const;
205private:
206 static BitRange bitRange(RegisterDescriptor reg) {
207 ASSERT_forbid(reg.isEmpty());
208 return BitRange::baseSize(reg.offset(), reg.nBits());
209 }
210
211};
212
213} // namespace
214} // namespace
215
216#endif
217#endif
Describes (part of) a physical CPU register.
size_t offset() const
Property: Offset to least-significant bit.
unsigned minorNumber() const
Property: Minor number.
bool isEmpty() const
Predicate returns true if the width is zero.
unsigned majorNumber() const
Property: Major number.
size_t nBits() const
Property: Size in bits.
Holds a set of registers without regard for register boundaries.
RegisterParts(RegisterDescriptor reg)
Constructor to insert a register.
bool existsAll(RegisterDescriptor reg) const
Predicate checking if all of a register is present.
void erase(RegisterDescriptor reg)
Erase register from container.
RegisterParts()
Default construct an object with no register parts.
RegisterParts & operator|=(const RegisterParts &other)
Add some register parts.
bool existsAny(RegisterDescriptor reg) const
Predicate checking if part of a register is present.
RegisterParts operator|(const RegisterParts &other) const
Compute the union.
bool isEmpty() const
Predicate checking whether this container is empty.
RegisterParts operator&(const RegisterParts &other) const
Compute the intersection.
std::vector< RegisterDescriptor > extract(const RegisterDictionaryPtr &regDict, bool extractAll=false)
Extract individual registers.
void insert(RegisterDescriptor reg)
Insert register into container.
RegisterParts & operator&=(const RegisterParts &other)
Erase some register parts.
RegisterParts operator-(const RegisterParts &other) const
Compute difference.
std::vector< RegisterDescriptor > listAll(const RegisterDictionaryPtr &) const
List registers present.
std::vector< RegisterDescriptor > listNamed(const RegisterDictionaryPtr &) const
List registers present.
RegisterParts & operator-=(const RegisterParts &other)
Erase some register parts.
A container holding a set of values.
Definition IntervalSet.h:53
Range of values delimited by endpoints.
Definition Interval.h:31
static Interval baseSize(size_t lo, size_t size)
Construct an interval from one endpoint and a size.
Definition Interval.h:173
Container associating values with keys.
Definition Sawyer/Map.h:72
bool exists(const Key &key) const
Determine if a key exists.
Definition Sawyer/Map.h:493
bool isEmpty() const
Determines whether this container is empty.
Definition Sawyer/Map.h:431
Value & insertMaybeDefault(const Key &key)
Conditionally insert a new key with default value.
Definition Sawyer/Map.h:711
Map & clear()
Remove all nodes.
Definition Sawyer/Map.h:732
The ROSE library.