ROSE 0.11.145.192
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#include <boost/serialization/access.hpp>
12
13namespace Rose {
14namespace BinaryAnalysis {
15
31
32private:
35
36 // DQ (2/13/2017): Testing a simpler case.
37 // BitSet XXX;
38
39private:
40 class MajorMinor {
41 unsigned majr_, minr_;
42
43#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
44 private:
45 friend class boost::serialization::access;
46
47 template<class S>
48 void serialize(S &s, const unsigned /*version*/) {
49 s & BOOST_SERIALIZATION_NVP(majr_);
50 s & BOOST_SERIALIZATION_NVP(minr_);
51 }
52#endif
53
54 public:
55 MajorMinor(): majr_(0), minr_(0) {}
56
57 MajorMinor(RegisterDescriptor reg) /*implicit*/
58 : majr_(reg.majorNumber()), minr_(reg.minorNumber()) {}
59
60 bool operator<(const MajorMinor &other) const {
61 return majr_ < other.majr_ || (majr_ == other.majr_ && minr_ < other.minr_);
62 }
63
64 unsigned get_major() const { return majr_; } // "get_" works around Windows #define pollution
65 unsigned get_minor() const { return minr_; } // "get_" works around Windows #define pollution
66 };
67
68private:
69 // DQ (2/13/2017): Test alternative formulation.
71
72 // DQ (2/13/2017): Testing a simpler case.
73 // typedef Sawyer::Container::Map<MajorMinor, BitSet > MapXXX;
74 // MapXXX Map_YYY;
75
76 // DQ (2/13/2017): Both of these work fine.
77 // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< Sawyer::Container::Interval<size_t> > > Map;
78 // typedef Sawyer::Container::Map<MajorMinor, Sawyer::Container::IntervalSet< BitRange > > Map;
79 Map map_;
80
81
82#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
83private:
84 friend class boost::serialization::access;
85
86 template<class S>
87 void serialize(S &s, const unsigned /*version*/) {
88 s & BOOST_SERIALIZATION_NVP(map_);
89 }
90#endif
91
92public:
95
100 insert(reg);
101 }
102
106 bool isEmpty() const {
107 return map_.isEmpty();
108 }
109
115 return map_.exists(reg) && map_[reg].overlaps(bitRange(reg));
116 }
117
123 return map_.exists(reg) && map_[reg].contains(bitRange(reg));
124 }
125
131 map_.insertMaybeDefault(reg).insert(bitRange(reg));
132 }
133
139
143 void clear() {
144 map_.clear();
145 }
146
151
156
161
166
171
176
186 std::vector<RegisterDescriptor> extract(const RegisterDictionaryPtr &regDict, bool extractAll = false);
187
198 std::vector<RegisterDescriptor> listAll(const RegisterDictionaryPtr&) const;
199 std::vector<RegisterDescriptor> listNamed(const RegisterDictionaryPtr&) const;
203private:
204 static BitRange bitRange(RegisterDescriptor reg) {
205 ASSERT_forbid(reg.isEmpty());
206 return BitRange::baseSize(reg.offset(), reg.nBits());
207 }
208
209};
210
211} // namespace
212} // namespace
213
214#endif
215#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.