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>
8#include <rose_extent.h>
11#include <Sawyer/SharedPointer.h>
12#include <Sawyer/SharedObject.h>
14#include <boost/serialization/access.hpp>
15#include <boost/serialization/map.hpp>
16#include <boost/serialization/string.hpp>
24namespace BinaryAnalysis {
63 using Reverse = std::map<RegisterDescriptor, std::vector<std::string>>;
81#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
83 friend class boost::serialization::access;
86 void serialize(S &s,
const unsigned ) {
87 s & BOOST_SERIALIZATION_NVP(name_);
88 s & BOOST_SERIALIZATION_NVP(forward_);
89 s & BOOST_SERIALIZATION_NVP(reverse_);
118 const std::string &
name()
const;
143 void insert(
const std::string &
name,
unsigned majr,
unsigned minr,
unsigned offset,
unsigned nbits);
314 enum Direction { ASCENDING, DESCENDING };
315 explicit SortBySize(Direction d=DESCENDING): direction(d) {}
317 return ASCENDING==direction ?
351 template<
class Compare>
354 bool reconsiderParts =
true);
406template<
class Compare>
413 std::priority_queue<RegisterDescriptor, RegisterDescriptors, Compare> heap(order, desc);
414 while (!heap.empty()) {
419 ExtentMap &have_extents = have_bits[cur_majmin];
420 if (have_extents.
distinct(cur_extent)) {
422 retval.push_back(cur_desc);
423 have_extents.
insert(cur_extent);
424 }
else if (reconsiderParts) {
430 for (ExtentMap::iterator pi = parts.
begin(); pi != parts.
end(); ++pi) {
433 heap.push(part_desc);
Extends std::map with methods that return optional values.
bool distinct(const Range &r) const
Determines if a range map does not contain any part of the specified range.
iterator begin()
First-item iterator.
void erase_ranges(const OtherMap &other)
Erase ranges from this map.
iterator end()
End-item iterator.
iterator insert(Range new_range, Value new_value=Value(), bool make_hole=true)
Insert a range/value pair into the map.
A contiguous range of values.
void first(const Value &first)
Accessor for the first value of a range.
Value size() const
Returns the number of values represented by the range.
Describes (part of) a physical CPU register.
size_t offset() const
Property: Offset to least-significant bit.
unsigned minorNumber() const
Property: Minor number.
unsigned majorNumber() const
Property: Major number.
size_t nBits() const
Property: Size in bits.
Compares number of bits in register descriptors.
Defines registers available for a particular architecture.
RegisterDescriptor stackFrameRegister() const
Property: The register that ponts to the stack frame.
RegisterDescriptors getSmallestRegisters() const
Returns a list of the smallest non-overlapping registers.
void name(const std::string &)
Property: Architecture name.
void stackPointerRegister(RegisterDescriptor)
Property: The register that points to the stack.
Rose::BinaryAnalysis::RegisterParts getAllParts() const
Returns all register parts.
void stackFrameRegister(RegisterDescriptor)
Property: The register that ponts to the stack frame.
void stackSegmentRegister(RegisterDescriptor)
Property: The segment register for accessing the stack.
const std::string & name() const
Property: Architecture name.
static Ptr instance(const std::string &name)
Allocating constructor for an empty dictionary.
void insert(const std::string &name, RegisterDescriptor)
Insert a definition into the dictionary.
bool exists(RegisterDescriptor) const
Determine if a register descriptor exists.
void instructionPointerRegister(RegisterDescriptor)
Property: The register that points to instructions.
static Ptr instanceNull()
Mostly empty dictionary for the null ISA.
RegisterDescriptor findOrThrow(const std::string &name) const
Find a register by name.
void stackSegmentRegister(const std::string &)
Property: The segment register for accessing the stack.
Rose::BinaryAnalysis::RegisterDescriptors RegisterDescriptors
List of register descriptors in dictionary.
std::string quadAndName(RegisterDescriptor) const
Quad and name.
void callReturnRegister(const std::string &)
Property: The register that holds the return address for a function.
unsigned firstUnusedMajor() const
Returns the first unused major register number.
Sawyer::Optional< std::string > name(RegisterDescriptor) const
Name of the register or nothing.
RegisterDescriptors getDescriptors() const
Returns the list of all register descriptors.
void stackFrameRegister(const std::string &)
Property: The register that ponts to the stack frame.
std::string nameAndQuad(RegisterDescriptor) const
Name and quad.
void instructionPointerRegister(const std::string &)
Property: The register that points to instructions.
void callReturnRegister(RegisterDescriptor)
Property: The register that holds the return address for a function.
void print(std::ostream &) const
Prints the contents of this register dictionary.
const std::string & lookup(RegisterDescriptor) const
Returns a register name for a given descriptor.
void insert(const std::string &name, unsigned majr, unsigned minr, unsigned offset, unsigned nbits)
Insert a definition into the dictionary.
std::map< std::string, RegisterDescriptor > Entries
List of registers in dictionary.
RegisterDescriptor instructionPointerRegister() const
Property: The register that points to instructions.
static RegisterDescriptors filterNonoverlapping(RegisterDescriptors reglist, Compare order=SortBySize(), bool reconsiderParts=true)
Returns the list of non-overlapping registers or register parts.
RegisterDescriptor callReturnRegister() const
Property: The register that holds the return address for a function.
void resize(const std::string &name, unsigned new_nbits)
Changes the size of a register.
void stackPointerRegister(const std::string &)
Property: The register that points to the stack.
const Entries & registers() const
Returns the list of all register definitions in the dictionary.
size_t size() const
Return the number of entries in the dictionary.
friend std::ostream & operator<<(std::ostream &, const RegisterDictionary &)
Prints the contents of this register dictionary.
RegisterDescriptor findLargestRegister(unsigned major, unsigned minor, size_t maxWidth=0) const
Finds the first largest register with specified major and minor number.
RegisterDescriptor stackPointerRegister() const
Property: The register that points to the stack.
unsigned firstUnusedMinor(unsigned majr) const
Returns the first unused minor register number.
RegisterDescriptor stackSegmentRegister() const
Property: The segment register for accessing the stack.
RegisterDescriptors getLargestRegisters() const
Returns a list of the largest non-overlapping registers.
void insert(const Ptr &)
Inserts definitions from another dictionary into this dictionary.
RegisterDescriptor find(const std::string &name) const
Find a register by name.
std::string nameOrQuad(RegisterDescriptor) const
Name or quad.
Holds a set of registers without regard for register boundaries.
Holds a value or nothing.
Base class for reference counted objects.
Sawyer::SharedPointer< RegisterDictionary > RegisterDictionaryPtr
Reference counting pointer.
std::vector< RegisterDescriptor > RegisterDescriptors
List of register descriptors in dictionary.