ROSE  0.9.10.2
Classes | Public Member Functions | List of all members
AssemblerX86 Class Reference

Description

This class contains methods for assembling x86 instructions (SgAsmX86Instruction).

End users will generally not need to use the AssemblerX86 class directly. Instead, they will call Assembler::create() to create an assembler that's appropriate for a particular binary file header or interpretation and then use that assembler to assemble instructions.

The assembler itself is quite small compared to the disassembler (about one third the size) and doesn't actually know about any instructions; it only knows how to encode various prefixes and operand addressing modes. For each instruction to be assembled, the assembler consults a dictionary of assembly definitions. The instruction is looked up in this dictionary and the chosen definition then drives the assembly. If the instruction being assembled matches multiple definitions then each valid definition is tried and the "best" one (see Assembler::set_encoding_type()) is returned.

The dictionary is generated directly from the Intel "Instruction Set Reference" PDF documentation as augmented by a small text file in this directory. The IntelAssemblyBuilder perl script generates AssemblerX86Init.h and AssemblerX86Init.C, which contain the X86InstructionKind enumeration, a function to initialize the dictionary (AssemblerX86::initAssemblyRules()), and a function for converting an X86InstructionKind constant to a string (AssemblerX86::to_str()).

Definition at line 26 of file AssemblerX86.h.

#include <AssemblerX86.h>

Inheritance diagram for AssemblerX86:
Inheritance graph
[legend]
Collaboration diagram for AssemblerX86:
Collaboration graph
[legend]

Public Member Functions

virtual SgUnsignedCharList assembleOne (SgAsmInstruction *)
 Assemble an instruction (SgAsmInstruction) into byte code. More...
 
void set_honor_operand_types (bool b)
 Causes the assembler to honor (if true) or disregard (if false) the data types of operands when assembling. More...
 
bool get_honor_operand_types () const
 Returns true if the assembler is honoring operand data types, or false if the assembler is using the smallest possible encoding. More...
 
virtual SgUnsignedCharList assembleProgram (const std::string &source)
 Assemble an x86 program from assembly source code using the nasm assembler. More...
 
- Public Member Functions inherited from Assembler
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...
 
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...
 

Additional Inherited Members

- Public Types inherited from Assembler
enum  EncodingType {
  ET_SHORTEST,
  ET_LONGEST,
  ET_MATCHES
}
 Assemblers can often assemble a single instruction various ways. More...
 
- Static Public Member Functions inherited from Assembler
static Assemblercreate (SgAsmInterpretation *interp)
 Creates an assembler that is appropriate for assembling instructions in the specified interpretation. More...
 
static Assemblercreate (SgAsmGenericHeader *)
 Creates an assembler that is appropriate for assembling instructions in the specified header. More...
 
- Protected Attributes inherited from Assembler
FILE * p_debug
 Set to non-null to get debugging info. More...
 
EncodingType p_encoding_type
 Which encoding should be returned by assembleOne. More...
 

Member Function Documentation

virtual SgUnsignedCharList AssemblerX86::assembleOne ( SgAsmInstruction )
virtual

Assemble an instruction (SgAsmInstruction) into byte code.

The new bytes are added to the end of the vector.

Implements Assembler.

void AssemblerX86::set_honor_operand_types ( bool  b)
inline

Causes the assembler to honor (if true) or disregard (if false) the data types of operands when assembling.

For instance, when honoring operand data types, if an operand is a 32-bit SgAsmIntegerValueExpression then the assembler will attempt to encode it as four bytes even if its value could be encoded as a single byte. This is turned on automatically if the Assembler::set_encoding_type() is set to Assembler::ET_MATCHES, but can also be turned on independently.

Definition at line 44 of file AssemblerX86.h.

bool AssemblerX86::get_honor_operand_types ( ) const
inline

Returns true if the assembler is honoring operand data types, or false if the assembler is using the smallest possible encoding.

Definition at line 50 of file AssemblerX86.h.

virtual SgUnsignedCharList AssemblerX86::assembleProgram ( const std::string &  source)
virtual

Assemble an x86 program from assembly source code using the nasm assembler.

Implements Assembler.


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