ROSE 0.11.145.147
Public Member Functions | Static Public Member Functions | 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 28 of file RegisterDescriptor.h.

#include <Rose/BinaryAnalysis/RegisterDescriptor.h>

Public Member Functions

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

Constructor & Destructor Documentation

◆ RegisterDescriptor() [1/2]

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 68 of file RegisterDescriptor.h.

◆ RegisterDescriptor() [2/2]

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 75 of file RegisterDescriptor.h.

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

Member Function Documentation

◆ fromRaw()

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

Construct a descriptor from a raw value.

Definition at line 83 of file RegisterDescriptor.h.

References raw().

◆ majorNumber() [1/2]

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 94 of file RegisterDescriptor.h.

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

◆ majorNumber() [2/2]

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.

◆ minorNumber() [1/2]

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 106 of file RegisterDescriptor.h.

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

◆ minorNumber() [2/2]

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.

◆ offset() [1/2]

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 122 of file RegisterDescriptor.h.

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

◆ offset() [2/2]

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.

◆ nBits() [1/2]

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 141 of file RegisterDescriptor.h.

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

◆ nBits() [2/2]

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).

◆ bits()

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 157 of file RegisterDescriptor.h.

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

◆ setOffsetWidth()

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().

◆ isEmpty()

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 178 of file RegisterDescriptor.h.

References nBits().

◆ isValid()

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 185 of file RegisterDescriptor.h.

References nBits().

◆ raw() [1/2]

uint32_t Rose::BinaryAnalysis::RegisterDescriptor::raw ( ) const
inline

The raw value of the descriptor.

Definition at line 192 of file RegisterDescriptor.h.

Referenced by fromRaw().

◆ raw() [2/2]

void Rose::BinaryAnalysis::RegisterDescriptor::raw ( uint32_t  r)
inline

The raw value of the descriptor.

Definition at line 195 of file RegisterDescriptor.h.

◆ operator unspecified_bool()

Rose::BinaryAnalysis::RegisterDescriptor::operator unspecified_bool ( ) const
inline

Definition at line 205 of file RegisterDescriptor.h.

◆ operator<()

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 214 of file RegisterDescriptor.h.

◆ operator==()

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 222 of file RegisterDescriptor.h.

◆ operator!=()

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 230 of file RegisterDescriptor.h.

◆ operator&()

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.

◆ hash()

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 247 of file RegisterDescriptor.h.

◆ print()

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

Print all properties.

Definition at line 252 of file RegisterDescriptor.h.

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

◆ get_major()

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

Definition at line 265 of file RegisterDescriptor.h.

◆ is_valid()

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

Definition at line 268 of file RegisterDescriptor.h.

◆ set_major()

RegisterDescriptor & Rose::BinaryAnalysis::RegisterDescriptor::set_major ( unsigned  majr)
inline

Definition at line 271 of file RegisterDescriptor.h.

◆ get_minor()

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

Definition at line 275 of file RegisterDescriptor.h.

◆ set_minor()

RegisterDescriptor & Rose::BinaryAnalysis::RegisterDescriptor::set_minor ( unsigned  minr)
inline

Definition at line 278 of file RegisterDescriptor.h.

◆ get_offset()

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

Definition at line 282 of file RegisterDescriptor.h.

◆ set_offset()

RegisterDescriptor & Rose::BinaryAnalysis::RegisterDescriptor::set_offset ( unsigned  offset)
inline

Definition at line 285 of file RegisterDescriptor.h.

◆ get_nbits()

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

Definition at line 289 of file RegisterDescriptor.h.

◆ set_nbits()

RegisterDescriptor & Rose::BinaryAnalysis::RegisterDescriptor::set_nbits ( unsigned  nbits)
inline

Definition at line 292 of file RegisterDescriptor.h.


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