ROSE
0.9.6a
|
Virtual base class for instruction assemblers. More...
#include <Assembler.h>
Classes | |
class | Exception |
Exception thrown by the assemblers. More... | |
Public Types | |
enum | EncodingType { ET_SHORTEST, ET_LONGEST, ET_MATCHES } |
Assemblers can often assemble a single instruction various ways. More... | |
Public Member Functions | |
Assembler () | |
virtual | ~Assembler () |
virtual SgUnsignedCharList | assembleOne (SgAsmInstruction *insn)=0 |
This is the lowest level architecture-independent assembly function and is implemented in the architecture-specific subclasses (there may be other architecture-dependent assembly methods also). More... | |
SgUnsignedCharList | assembleBlock (SgAsmBlock *) |
Assembles a single basic block of instructions, packing them together and adjusting their virtual addresses. More... | |
SgUnsignedCharList | assembleBlock (const std::vector< SgAsmInstruction * > &insns, rose_addr_t starting_rva) |
Assembles a single basic block of instructions like the version that takes an SgAsmBlock pointer. More... | |
virtual SgUnsignedCharList | assembleProgram (const std::string &source)=0 |
Assembles a program from an assembly listing. More... | |
void | set_encoding_type (EncodingType et) |
Controls how the assembleOne() method determines which encoding to return. More... | |
EncodingType | get_encoding_type () const |
Returns the encoding type employed by this assembler. More... | |
void | set_debug (FILE *f) |
Sends assembler diagnostics to the specified output stream. More... | |
FILE * | get_debug () const |
Returns the file currently used for debugging; null implies no debugging. More... | |
Static Public Member Functions | |
static Assembler * | create (SgAsmInterpretation *interp) |
Creates an assembler that is appropriate for assembling instructions in the specified interpretation. More... | |
static Assembler * | create (SgAsmGenericHeader *) |
Creates an assembler that is appropriate for assembling instructions in the specified header. More... | |
Protected Attributes | |
FILE * | p_debug |
Set to non-null to get debugging info. More... | |
EncodingType | p_encoding_type |
Which encoding should be returned by assembleOne. More... | |
Virtual base class for instruction assemblers.
The Assembler class is a virtual class providing all non-architecture-specific functionality for the assembly of instructions; architecture-specific components are in subclasses such as AssemblerArm, AssemblerPowerpc, and AssemblerX86.
This example shows how to test the disassembler against the assembler by disassembling and then reassembling all instructions. Generate debugging output for instructions that cannot be reassembled into an encoding identical to the original bytes:
Definition at line 49 of file Assembler.h.
Assemblers can often assemble a single instruction various ways.
For instance, on x86 the immediate value -53 can be assembled into a single byte, or sign extended into 2, 4, or 8 bytes. These enumeration constants control how the assembleOne() method determines which encoding to return.
Enumerator | |
---|---|
ET_SHORTEST |
Returns the shortest possible encoding. This is the default. |
ET_LONGEST |
Returns the longest encoding. |
ET_MATCHES |
Returns an encoding that matches the SgAsmInstruction::p_raw_bytes. This is used mainly for testing that the assembler can produce the same encoding that was originally used by the disassembler when the instruction was created. |
Definition at line 71 of file Assembler.h.
|
inline |
Definition at line 80 of file Assembler.h.
|
inlinevirtual |
Definition at line 84 of file Assembler.h.
|
static |
Creates an assembler that is appropriate for assembling instructions in the specified interpretation.
|
static |
Creates an assembler that is appropriate for assembling instructions in the specified header.
|
pure virtual |
This is the lowest level architecture-independent assembly function and is implemented in the architecture-specific subclasses (there may be other architecture-dependent assembly methods also).
It assembles one instruction and returns the encoding, throwing an exception if anything goes wrong.
Implemented in AssemblerX86.
SgUnsignedCharList Assembler::assembleBlock | ( | SgAsmBlock * | ) |
Assembles a single basic block of instructions, packing them together and adjusting their virtual addresses.
The virtual address of the first instruction of the block determines the starting address. An exception is thrown if any of the instructions cannot be assembled.
SgUnsignedCharList Assembler::assembleBlock | ( | const std::vector< SgAsmInstruction * > & | insns, |
rose_addr_t | starting_rva | ||
) |
Assembles a single basic block of instructions like the version that takes an SgAsmBlock pointer.
In this case, the instructions are stored in a vector instead. The will be treated like a single basic block: no control flow adjustments will be made. An exception is thrown if any of the instructions cannot be disassembled.
|
pure virtual |
Assembles a program from an assembly listing.
This method may call an external assembler to do its work.
Implemented in AssemblerX86.
|
inline |
Controls how the assembleOne() method determines which encoding to return.
Definition at line 121 of file Assembler.h.
References p_encoding_type.
|
inline |
Returns the encoding type employed by this assembler.
See set_encoding_type().
Definition at line 126 of file Assembler.h.
References p_encoding_type.
|
inline |
Sends assembler diagnostics to the specified output stream.
Null (the default) turns off debugging.
Definition at line 131 of file Assembler.h.
References p_debug.
|
inline |
Returns the file currently used for debugging; null implies no debugging.
Definition at line 136 of file Assembler.h.
References p_debug.
|
protected |
Set to non-null to get debugging info.
Definition at line 144 of file Assembler.h.
Referenced by get_debug(), and set_debug().
|
protected |
Which encoding should be returned by assembleOne.
Definition at line 145 of file Assembler.h.
Referenced by get_encoding_type(), and set_encoding_type().