ROSE  0.9.10.86
Public Member Functions | Friends | List of all members
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 25 of file RegisterDescriptor.h.

#include <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...
 
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 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...
 
unsigned hash () const
 Hash value. More...
 
void print (std::ostream &o) const
 Print all properties. 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...
 

Friends

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

Constructor & Destructor Documentation

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

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

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

Member Function Documentation

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

Referenced by print(), and RegisterDescriptor().

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

Referenced by print(), and RegisterDescriptor().

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

Referenced by print().

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

Referenced by isEmpty(), and print().

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

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

References nBits().

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

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

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

unsigned RegisterDescriptor::hash ( ) const
inline

Hash value.

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

Definition at line 188 of file RegisterDescriptor.h.

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

Print all properties.

Definition at line 193 of file RegisterDescriptor.h.

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


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