1 #ifndef ROSE_BinaryAnalysis_RegisterDictionary_H
2 #define ROSE_BinaryAnalysis_RegisterDictionary_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/RegisterDescriptor.h>
7 #include <Rose/BinaryAnalysis/RegisterParts.h>
9 #include <Sawyer/SharedPointer.h>
10 #include <Sawyer/SharedObject.h>
12 #include <boost/serialization/access.hpp>
13 #include <boost/serialization/map.hpp>
14 #include <boost/serialization/string.hpp>
22 namespace BinaryAnalysis {
61 using Reverse = std::map<RegisterDescriptor, std::vector<std::string>>;
74 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
76 friend class boost::serialization::access;
79 void serialize(S &s,
const unsigned ) {
80 s & BOOST_SERIALIZATION_NVP(name_);
81 s & BOOST_SERIALIZATION_NVP(forward_);
82 s & BOOST_SERIALIZATION_NVP(reverse_);
167 #ifdef ROSE_ENABLE_ASM_AARCH64
173 static Ptr instanceAarch64();
176 #ifdef ROSE_ENABLE_ASM_AARCH32
180 static Ptr instanceAarch32();
236 const std::string &
name()
const;
237 void name(
const std::string&);
252 void insert(
const std::string &
name, RegisterDescriptor);
258 void insert(
const std::string &
name,
unsigned majr,
unsigned minr,
unsigned offset,
unsigned nbits);
271 void resize(
const std::string &
name,
unsigned new_nbits);
281 RegisterDescriptor
find(
const std::string &
name)
const;
294 const std::string&
lookup(RegisterDescriptor)
const;
300 bool exists(RegisterDescriptor)
const;
309 RegisterDescriptor
findLargestRegister(
unsigned major,
unsigned minor,
size_t maxWidth=0)
const;
345 enum Direction { ASCENDING, DESCENDING };
346 explicit SortBySize(Direction d=DESCENDING): direction(d) {}
347 bool operator()(RegisterDescriptor a, RegisterDescriptor b)
const {
348 return ASCENDING==direction ?
382 template<
class Compare>
385 bool reconsiderParts =
true);
425 void print(std::ostream&)
const;
436 template<
class Compare>
443 std::priority_queue<RegisterDescriptor, RegisterDescriptors, Compare> heap(order, desc);
444 while (!heap.empty()) {
445 const RegisterDescriptor cur_desc = heap.top();
449 ExtentMap &have_extents = have_bits[cur_majmin];
450 if (have_extents.distinct(cur_extent)) {
452 retval.push_back(cur_desc);
453 have_extents.
insert(cur_extent);
454 }
else if (reconsiderParts) {
460 for (ExtentMap::iterator pi = parts.
begin(); pi != parts.
end(); ++pi) {
463 heap.push(part_desc);
static Ptr instance(const std::string &name)
Allocating constructor for an empty dictionary.
unsigned majorNumber() const
Property: Major number.
static Ptr instanceI486()
Intel 80486 registers.
const Entries & registers() const
Returns the list of all register definitions in the dictionary.
size_t nBits() const
Property: Size in bits.
Rose::BinaryAnalysis::RegisterParts getAllParts() const
Returns all register parts.
static Ptr instanceColdfire()
FreeScale ColdFire generic hardware registers.
const std::string & lookup(RegisterDescriptor) const
Returns a register name for a given descriptor.
A contiguous range of values.
RegisterDescriptor findOrThrow(const std::string &name) const
Find a register by name.
Sawyer::SharedPointer< RegisterDictionary > RegisterDictionaryPtr
Reference counting pointer.
static Ptr instanceMips32AlternateNames()
MIPS32 Release 1 with special registers.
static Ptr instanceI386()
Intel 80386 registers.
Main namespace for the ROSE library.
Holds a set of registers without regard for register boundaries.
void print(std::ostream &) const
Prints the contents of this register dictionary.
size_t size() const
Return the number of entries in the dictionary.
Compares number of bits in register descriptors.
const std::string & name() const
Property: Architecture name.
iterator insert(Range new_range, Value new_value=Value(), bool make_hole=true)
Insert a range/value pair into the map.
Rose::BinaryAnalysis::RegisterDescriptors RegisterDescriptors
List of register descriptors in dictionary.
void insert(const std::string &name, RegisterDescriptor)
Insert a definition into the dictionary.
static Ptr instancePentium()
Intel Pentium registers.
static Ptr instanceI8088()
Intel 8088 registers.
std::vector< RegisterDescriptor > RegisterDescriptors
List of register descriptors in dictionary.
static Ptr instanceM68000()
Motorola M68330 register names.
void erase_ranges(const OtherMap &other)
Erase ranges from this map.
unsigned firstUnusedMajor() const
Returns the first unused major register number.
static Ptr instanceAmd64()
Amd64 registers.
Describes (part of) a physical CPU register.
RegisterDescriptor find(const std::string &name) const
Find a register by name.
static Ptr instancePentiumiii()
Intel Pentium III registers.
static Ptr instanceNull()
Mostly empty dictionary for the null ISA.
iterator begin()
First-item iterator.
size_t offset() const
Property: Offset to least-significant bit.
Value size() const
Returns the number of values represented by the range.
RegisterDescriptors getLargestRegisters() const
Returns a list of the largest non-overlapping registers.
static Ptr instancePowerpc32()
PowerPC-32 registers.
RegisterDescriptors getDescriptors() const
Returns the list of all register descriptors.
Extends std::map with methods that return optional values.
static RegisterDescriptors filterNonoverlapping(RegisterDescriptors reglist, Compare order=SortBySize(), bool reconsiderParts=true)
Returns the list of non-overlapping registers or register parts.
unsigned firstUnusedMinor(unsigned majr) const
Returns the first unused minor register number.
static Ptr instanceI286()
Intel 80286 registers.
iterator end()
End-item iterator.
static Ptr instanceMips32()
MIPS32 Release 1.
RegisterDescriptors getSmallestRegisters() const
Returns a list of the smallest non-overlapping registers.
bool exists(RegisterDescriptor) const
Determine if a register descriptor exists.
RegisterDictionaryPtr Ptr
Reference counting pointer.
std::map< std::string, RegisterDescriptor > Entries
List of registers in dictionary.
Base class for reference counted objects.
static Ptr instanceCil()
CIL register names.
static Ptr instanceM68000AlternateNames()
Motorola M68330 alternate registers.
static Ptr instanceI386Math()
Intel 80386 with 80387 math co-processor.
static Ptr instanceForIsa(SgAsmExecutableFileFormat::InsSetArchitecture)
Class method to choose an appropriate register dictionary for an instruction set architecture.
void first(const Value &first)
Accessor for the first value of a range.
Defines registers available for a particular architecture.
void resize(const std::string &name, unsigned new_nbits)
Changes the size of a register.
unsigned minorNumber() const
Property: Minor number.
static Ptr instancePentium4()
Intel Pentium 4 registers.
friend std::ostream & operator<<(std::ostream &, const RegisterDictionary &)
Prints the contents of this register dictionary.
Represents an interpretation of a binary container.
static Ptr instancePowerpc64()
PowerPC-64 registers.
static Ptr instanceColdfireEmac()
Registers for FreeScale ColdFire CPUs with EMAC (extended multiply-accumulate) unit.
static Ptr instanceI8086()
Intel 8086 registers.
RegisterDescriptor findLargestRegister(unsigned major, unsigned minor, size_t maxWidth=0) const
Finds the first largest register with specified major and minor number.