1 #ifndef ROSE_BinaryAnalysis_Registers_H
2 #define ROSE_BinaryAnalysis_Registers_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/RegisterParts.h>
8 #include <boost/serialization/access.hpp>
9 #include <boost/serialization/map.hpp>
10 #include <boost/serialization/string.hpp>
15 namespace BinaryAnalysis {
40 typedef std::vector<RegisterDescriptor> RegisterDescriptors;
109 #ifdef ROSE_ENABLE_ASM_AARCH64
118 #ifdef ROSE_ENABLE_ASM_AARCH32
160 typedef std::map<RegisterDescriptor, std::vector<std::string> > Reverse;
165 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
167 friend class boost::serialization::access;
170 void serialize(S &s,
const unsigned ) {
171 s & BOOST_SERIALIZATION_NVP(name);
172 s & BOOST_SERIALIZATION_NVP(forward);
173 s & BOOST_SERIALIZATION_NVP(reverse);
212 void insert(
const std::string &name,
unsigned majr,
unsigned minr,
unsigned offset,
unsigned nbits);
225 void resize(
const std::string &name,
unsigned new_nbits);
298 enum Direction { ASCENDING, DESCENDING };
299 explicit SortBySize(Direction d=DESCENDING): direction(d) {}
301 return ASCENDING==direction ?
334 template<
class Compare>
337 bool reconsider_parts=
true);
368 void print(std::ostream&)
const;
372 size_t size()
const {
return forward.size(); }
404 template<
class Compare>
405 RegisterDictionary::RegisterDescriptors
408 RegisterDescriptors retval;
412 std::priority_queue<RegisterDescriptor, RegisterDescriptors, Compare> heap(order, desc);
413 while (!heap.empty()) {
418 ExtentMap &have_extents = have_bits[cur_majmin];
419 if (have_extents.distinct(cur_extent)) {
421 retval.push_back(cur_desc);
422 have_extents.
insert(cur_extent);
423 }
else if (reconsider_parts) {
429 for (ExtentMap::iterator pi=parts.
begin(); pi!=parts.
end(); ++pi) {
432 heap.push(part_desc);
int show_size
0=>never; positive=>always; negative=>when offset is non-zero
const RegisterDescriptor * exists(RegisterDescriptor) const
Determine if a register descriptor exists.
static const RegisterDictionary * dictionary_i8088()
Intel 8088 registers.
static const RegisterDictionary * dictionary_pentium()
Intel Pentium registers.
unsigned majorNumber() const
Property: Major number.
static const RegisterDictionary * dictionary_coldfire_emac()
Registers for FreeScale ColdFire CPUs with EMAC (extended multiply-accumulate) unit.
size_t nBits() const
Property: Size in bits.
RegisterDescriptors get_largest_registers() const
Returns a list of the largest non-overlapping registers.
RegisterDescriptors get_descriptors() const
Returns the list of all register descriptors.
std::string offset_prefix
String printed before the offset when the offset is shown.
Rose::BinaryAnalysis::RegisterParts getAllParts() const
Returns all register parts.
static const RegisterDictionary * dictionary_i386_387()
Intel 80386 with 80387 math co-processor.
static const RegisterDictionary * dictionary_powerpc32()
PowerPC-32 registers.
const Entries & get_registers() const
Returns the list of all register definitions in the dictionary.
const std::string & lookup(RegisterDescriptor) const
Returns a register name for a given descriptor.
A contiguous range of values.
std::string offset_suffix
String printed after the offset when the offset is shown.
static RegisterDescriptors filter_nonoverlapping(RegisterDescriptors reglist, Compare order=SortBySize(), bool reconsider_parts=true)
Returns the list of non-overlapping registers or register parts.
RegisterDescriptor findOrThrow(const std::string &name) const
Find a register by name.
static const RegisterDictionary * dictionary_m68000()
Motorola M68330 register names.
static const RegisterDictionary * dictionary_pentium4()
Intel Pentium 4 registers.
static const RegisterDictionary * dictionary_i386()
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.
RegisterNames(const RegisterDictionary *dict=NULL)
Constructor.
static const RegisterDictionary * dictionary_m68000_altnames()
Motorola M68330 alternate registers.
int show_offset
0=>never show offset; positive=>always show; negative=>show only when non-zero
iterator insert(Range new_range, Value new_value=Value(), bool make_hole=true)
Insert a range/value pair into the map.
std::string size_prefix
String printed prior to the size when the size is printed.
static const RegisterDictionary * dictionary_coldfire()
FreeScale ColdFire generic hardware registers.
const std::string & get_architecture_name() const
Obtain the name of the dictionary.
void insert(const std::string &name, RegisterDescriptor)
Insert a definition into the dictionary.
std::string operator()(RegisterDescriptor, const RegisterDictionary *dict=NULL) const
Obtain a name for a register descriptor.
static const RegisterDictionary * dictionary_Cil()
CIL register names.
void erase_ranges(const OtherMap &other)
Erase ranges from this map.
unsigned firstUnusedMajor() const
Returns the first unused major register number.
std::string suffix
String to print at the very end of the generated name.
Describes (part of) a physical CPU register.
static const RegisterDictionary * dictionary_for_isa(SgAsmExecutableFileFormat::InsSetArchitecture)
Class method to choose an appropriate register dictionary for an instruction set architecture.
std::string size_suffix
String printed after the size when the size is printed.
RegisterDescriptors get_smallest_registers() const
Returns a list of the smallest non-overlapping registers.
RegisterDescriptor find(const std::string &name) const
Find a register by name.
static const RegisterDictionary * dictionary_i486()
Intel 80486 registers.
Prints a register name even when no dictionary is available or when the dictionary doesn't contain an...
iterator begin()
First-item iterator.
void set_architecture_name(const std::string &name)
Set the name of the dictionary.
size_t offset() const
Property: Offset to least-significant bit.
Value size() const
Returns the number of values represented by the range.
std::string prefix
The leading part of a register name.
Extends std::map with methods that return optional values.
const RegisterDictionary * dflt_dict
Dictionary supplied to the constructor.
unsigned firstUnusedMinor(unsigned majr) const
Returns the first unused minor register number.
static const RegisterDictionary * dictionary_null()
Mostly empty dictionary for the null ISA.
iterator end()
End-item iterator.
static const RegisterDictionary * dictionary_powerpc64()
PowerPC-64 registers.
static const RegisterDictionary * dictionary_i8086()
Intel 8086 registers.
static const RegisterDictionary * dictionary_amd64()
Amd64 registers.
static const RegisterDictionary * dictionary_pentiumiii()
Intel Pentium III registers.
void first(const Value &first)
Accessor for the first value of a range.
Defines registers available for a particular architecture.
static const RegisterDictionary * dictionary_mips32()
MIPS32 Release 1.
void resize(const std::string &name, unsigned new_nbits)
Changes the size of a register.
static const RegisterDictionary * dictionary_i286()
Intel 80286 registers.
unsigned minorNumber() const
Property: Minor number.
Represents an interpretation of a binary container.
static const RegisterDictionary * dictionary_mips32_altnames()
MIPS32 Release 1 with special registers.
RegisterDescriptor findLargestRegister(unsigned major, unsigned minor, size_t maxWidth=0) const
Finds the first largest register with specified major and minor number.