ROSE  0.11.145.0
Public Member Functions | Static Public Member Functions | Friends | List of all members
Rose::BinaryAnalysis::RegisterDescriptor Class Reference

Description

Describes (part of) a physical CPU register.

Some architectures have multiple names for physical registers. For example, amd64 has a 64-bit integer register, parts of which are referred to as "rax", "eax", "ax", "al", and "ah". The purpose of a RegisterDescriptor is to describe what physical register (major and minor) is being referenced, and the part (offset and nbits) that's being referenced.

The reason for having a major and minor number to specify a register is to allow for different types of registers. For instance, an i686 has a set of 64-bit integer registers and a set of 80-bit floating point registers (among others). Having major and minor numbers allows the physical register set (such as defined by an instruction semantics policy) to be implemented as an array of 64-bit integers and an array of 80-bit floating points (among others). The array is selected by the major number while the element of the array is selected by the minor number.

The RegisterDescriptor type is part of a SgAsmRegisterReferenceExpression and also appears in the register dictionaries (RegisterDictionary) used in various places including the disassembler. RegisterDescriptor objects are small and are intended to be passed by value. Although these objects are currently four bytes, we reserve the right to make them larger (but probably never more than eight bytes).

Definition at line 27 of file RegisterDescriptor.h.

#include <Rose/BinaryAnalysis/RegisterDescriptor.h>

Public Member Functions

 RegisterDescriptor ()
 Create an empty register descriptor. More...
 
 RegisterDescriptor (unsigned majr, unsigned minr, size_t offset, size_t width)
 Construct a descriptor from its constituent parts. More...
 
Sawyer::Container::Interval< size_t > bits () const
 Bit range. More...
 
void setOffsetWidth (size_t offset, size_t nBits)
 Set offset and size at the same time. More...
 
bool isEmpty () const
 Predicate returns true if the width is zero. More...
 
bool isValid () const
 Predicate returns true if width is non-zero. More...
 
 operator unspecified_bool () const
 
bool operator< (RegisterDescriptor other) const
 Compare two descriptors. More...
 
bool operator== (RegisterDescriptor other) const
 Check descriptors for equality. More...
 
bool operator!= (RegisterDescriptor other) const
 Check descriptors for inequality. More...
 
RegisterDescriptor operator& (RegisterDescriptor other) const
 Compute the intersection of two regiter descriptors. More...
 
bool isSubsetOf (RegisterDescriptor other) const
 True if this descriptor is a subset of the specified descriptor. More...
 
unsigned hash () const
 Hash value. More...
 
void print (std::ostream &o) const
 Print all properties. More...
 
std::string toString () const
 Show the properties as a string. More...
 
unsigned get_major () const
 
bool is_valid () const
 
RegisterDescriptorset_major (unsigned majr)
 
unsigned get_minor () const
 
RegisterDescriptorset_minor (unsigned minr)
 
unsigned get_offset () const
 
RegisterDescriptorset_offset (unsigned offset)
 
unsigned get_nbits () const
 
RegisterDescriptorset_nbits (unsigned nbits)
 
unsigned majorNumber () const
 Property: Major number. More...
 
void majorNumber (unsigned)
 Property: Major number. More...
 
unsigned minorNumber () const
 Property: Minor number. More...
 
void minorNumber (unsigned)
 Property: Minor number. More...
 
size_t offset () const
 Property: Offset to least-significant bit. More...
 
void offset (size_t)
 Property: Offset to least-significant bit. More...
 
size_t nBits () const
 Property: Size in bits. More...
 
void nBits (size_t)
 Property: Size in bits. More...
 
uint32_t raw () const
 The raw value of the descriptor.
 
void raw (uint32_t r)
 The raw value of the descriptor.
 

Static Public Member Functions

static RegisterDescriptor fromRaw (uint32_t raw)
 Construct a descriptor from a raw value. More...
 

Friends

std::ostream & operator<< (std::ostream &, RegisterDescriptor)
 

Constructor & Destructor Documentation

Rose::BinaryAnalysis::RegisterDescriptor::RegisterDescriptor ( )
inline

Create an empty register descriptor.

A default constructed register descriptor has major number zero, minor number zero, offset zero, and size zero.

Definition at line 67 of file RegisterDescriptor.h.

Rose::BinaryAnalysis::RegisterDescriptor::RegisterDescriptor ( unsigned  majr,
unsigned  minr,
size_t  offset,
size_t  width 
)
inline

Construct a descriptor from its constituent parts.

The major number, minor number, offset, and width must satisfy the requirements described for those various properties.

Definition at line 74 of file RegisterDescriptor.h.

References majorNumber(), minorNumber(), and setOffsetWidth().

Member Function Documentation

static RegisterDescriptor Rose::BinaryAnalysis::RegisterDescriptor::fromRaw ( uint32_t  raw)
inlinestatic

Construct a descriptor from a raw value.

Definition at line 82 of file RegisterDescriptor.h.

References raw().

unsigned Rose::BinaryAnalysis::RegisterDescriptor::majorNumber ( ) const
inline

Property: Major number.

Each family of registers is identified by a major number. Major numbers are in the range 0 through 15, inclusive.

Definition at line 93 of file RegisterDescriptor.h.

Referenced by Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), print(), and RegisterDescriptor().

void Rose::BinaryAnalysis::RegisterDescriptor::majorNumber ( unsigned  )

Property: Major number.

Each family of registers is identified by a major number. Major numbers are in the range 0 through 15, inclusive.

unsigned Rose::BinaryAnalysis::RegisterDescriptor::minorNumber ( ) const
inline

Property: Minor number.

Within a family of registers related by their majorNumber, the minorNumber identifies individuals. Minor numbers are in the range 0 through 1023, inclusive.

Definition at line 105 of file RegisterDescriptor.h.

Referenced by Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), print(), and RegisterDescriptor().

void Rose::BinaryAnalysis::RegisterDescriptor::minorNumber ( unsigned  )

Property: Minor number.

Within a family of registers related by their majorNumber, the minorNumber identifies individuals. Minor numbers are in the range 0 through 1023, inclusive.

size_t Rose::BinaryAnalysis::RegisterDescriptor::offset ( ) const
inline

Property: Offset to least-significant bit.

Each member of a register family (member identified by major and minor number) is conceptually 512 bits wide. A RegisterDescriptor has an offset and width (nBits property) to describe a contiguous region of that space. The sum of the offset and width cannot exceed 512. Decreasing the offset preserves the width; increasing the offset may truncate the width. The offset can be set and queried even for descriptors that are empty (width==0).

See also, setOffsetWidth which sets both offset and size at once.

Definition at line 121 of file RegisterDescriptor.h.

Referenced by bits(), Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), and print().

void Rose::BinaryAnalysis::RegisterDescriptor::offset ( size_t  )

Property: Offset to least-significant bit.

Each member of a register family (member identified by major and minor number) is conceptually 512 bits wide. A RegisterDescriptor has an offset and width (nBits property) to describe a contiguous region of that space. The sum of the offset and width cannot exceed 512. Decreasing the offset preserves the width; increasing the offset may truncate the width. The offset can be set and queried even for descriptors that are empty (width==0).

See also, setOffsetWidth which sets both offset and size at once.

size_t Rose::BinaryAnalysis::RegisterDescriptor::nBits ( ) const
inline

Property: Size in bits.

Each member of a register family (member identified by major and minor number) is conceptually 512 bits wide. A RegisterDescriptor has an offset and this width-in-bits property to describe a contiguous region of that space. The sum of the offset and width cannot exceed 512 (the setOffsetWidth function sets both at once).

Definition at line 140 of file RegisterDescriptor.h.

Referenced by bits(), Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping(), isEmpty(), isValid(), Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::RegisterState::peekRegister(), Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::RiscOperators::peekRegister(), print(), Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::RegisterState::readRegister(), and Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::RiscOperators::readRegister().

void Rose::BinaryAnalysis::RegisterDescriptor::nBits ( size_t  )

Property: Size in bits.

Each member of a register family (member identified by major and minor number) is conceptually 512 bits wide. A RegisterDescriptor has an offset and this width-in-bits property to describe a contiguous region of that space. The sum of the offset and width cannot exceed 512 (the setOffsetWidth function sets both at once).

Sawyer::Container::Interval<size_t> Rose::BinaryAnalysis::RegisterDescriptor::bits ( ) const
inline

Bit range.

This is the range of bits to which this register descriptor refers. It is formed from the offset and nBits properties.

Definition at line 156 of file RegisterDescriptor.h.

References Sawyer::Container::Interval< T >::baseSize(), nBits(), and offset().

void Rose::BinaryAnalysis::RegisterDescriptor::setOffsetWidth ( size_t  offset,
size_t  nBits 
)

Set offset and size at the same time.

Adjusting the offset and width individually with the offset and nBits properties can be tricky because you need to always satisfy the invariant that offset + size <= 512. Setting the offset individually may change the width, and setting the width individually might cause an invariant to be violated. Therefore, the recommended way to adjust both is to use the setOffsetWidth method.

The offset and width are set as indicated. Their sum must not exceed 512.

Referenced by RegisterDescriptor().

bool Rose::BinaryAnalysis::RegisterDescriptor::isEmpty ( ) const
inline

Predicate returns true if the width is zero.

Default-constructed register descriptors have an initial width of zero.

Definition at line 177 of file RegisterDescriptor.h.

References nBits().

Referenced by Rose::BinaryAnalysis::Disassembler::Base::instructionPointerRegister(), and Rose::BinaryAnalysis::Disassembler::Base::stackPointerRegister().

bool Rose::BinaryAnalysis::RegisterDescriptor::isValid ( ) const
inline

Predicate returns true if width is non-zero.

Default-constructed register descriptors have an initial width of zero.

Definition at line 184 of file RegisterDescriptor.h.

References nBits().

bool Rose::BinaryAnalysis::RegisterDescriptor::operator< ( RegisterDescriptor  other) const
inline

Compare two descriptors.

Descriptors are sorted by major and minor numbers. If two descriptors have the same major and minor numbers then this less-than operation satisfies the requirements of a strict weak ordering although the exact details are not specified (it is not a simple comparison of offset and width).

Definition at line 213 of file RegisterDescriptor.h.

bool Rose::BinaryAnalysis::RegisterDescriptor::operator== ( RegisterDescriptor  other) const
inline

Check descriptors for equality.

Two descriptors are equal if and only if they have the same major numbers, minor numbers, offsets, and width. Note that all properties are significant even if the width is zero or isEmpty returns true.

Definition at line 221 of file RegisterDescriptor.h.

bool Rose::BinaryAnalysis::RegisterDescriptor::operator!= ( RegisterDescriptor  other) const
inline

Check descriptors for inequality.

Two descriptors are unequal if they differ in major numbers, minor numbers, offsets, or widths. Note that all properties are significant even if the width is zero or isEmpty returns true.

Definition at line 229 of file RegisterDescriptor.h.

RegisterDescriptor Rose::BinaryAnalysis::RegisterDescriptor::operator& ( RegisterDescriptor  other) const

Compute the intersection of two regiter descriptors.

If the registers have the same major numbers and the same minor numbers and the offset and size cause them to overlap, then the return value is a register descriptor with the same major and minor numbers and an offset and size that represents the overlapping portion. Otherwise the return value is a default constructed register descriptor.

bool Rose::BinaryAnalysis::RegisterDescriptor::isSubsetOf ( RegisterDescriptor  other) const

True if this descriptor is a subset of the specified descriptor.

unsigned Rose::BinaryAnalysis::RegisterDescriptor::hash ( ) const
inline

Hash value.

Hash a descriptor. This is a perfect hash: every descriptor hashes to a distinct value.

Definition at line 246 of file RegisterDescriptor.h.

void Rose::BinaryAnalysis::RegisterDescriptor::print ( std::ostream &  o) const
inline

Print all properties.

Definition at line 251 of file RegisterDescriptor.h.

References majorNumber(), minorNumber(), nBits(), and offset().

std::string Rose::BinaryAnalysis::RegisterDescriptor::toString ( ) const

Show the properties as a string.


The documentation for this class was generated from the following file: