fcml  1.2.2
Classes | Public Member Functions | Static Public Member Functions | List of all members
fcml::StatefulAssembler Class Reference

It's a stateful assembler which can be used to assemble instructions one by one on the fly. More...

#include <fcml_stateful_assembler.hpp>

Classes

class  SAFlush
 Used only to indicate the need of the flush operation. More...
 

Public Member Functions

 StatefulAssembler (Assembler &assembler, AssemblerContext &context, bool enableParser=false)
 Creates a stateful assembler for the given assembler and assembler context. More...
 
virtual ~StatefulAssembler ()
 Destructor. More...
 
StatefulAssembleroperator<< (const IB &ib)
 Adds instruction builder to the stateful assembler. More...
 
StatefulAssembleradd (const IB &ib)
 Adds instruction builder to the stateful assembler. More...
 
StatefulAssembleroperator<< (const fcml_cstring &mnemonic)
 Creates an instruction builder for the given mnemonic. More...
 
StatefulAssemblerinst (const fcml_cstring &mnemonic)
 Creates an instruction builder for the given mnemonic. More...
 
StatefulAssembleroperator<< (const Register &reg)
 Adds the new register operand to the instruction builder associated with the buffer. More...
 
StatefulAssembleroperator<< (const Integer &imm)
 Adds the new immediate operand to the instruction builder associated with the buffer. More...
 
StatefulAssembleroperator<< (const Address &address)
 Adds the new address operand to the instruction builder associated with the buffer. More...
 
StatefulAssembleroperator<< (const FarPointer &pointer)
 Adds the new far pointer operand to the instruction builder associated with the buffer. More...
 
StatefulAssembleroperator<< (const Operand &operand)
 Adds an operand to the instruction builder associated with the buffer. More...
 
StatefulAssemblerop (const Operand &operand)
 Adds an operand to the instruction builder associated with the buffer. More...
 
StatefulAssemblerop (const Register &reg)
 Adds the new register operand to the instruction builder associated with the buffer. More...
 
StatefulAssemblerop (const Integer &imm)
 Adds the new immediate operand to the instruction builder associated with the buffer. More...
 
StatefulAssemblerop (const Address &address)
 Adds the new address operand to the instruction builder associated with the buffer. More...
 
StatefulAssemblerop (const FarPointer &pointer)
 Adds the new far pointer operand to the instruction builder associated with the buffer. More...
 
StatefulAssembleroperator<< (const SAFlush &indic)
 Flushes the instruction builder. More...
 
StatefulAssembleroperator<< (const Instruction &instruction)
 Assembles an instruction in the given instruction builder. More...
 
StatefulAssembleroperator<< (const InstructionPrefix &prefix)
 Adds a prefix to the instruction being built. More...
 
StatefulAssembleroperator<< (const InstructionHint &hint)
 Adds an instruction level hint to the instruction being built. More...
 
StatefulAssembleroperator<< (const OperandHint &hint)
 Adds an operand level hint to the instruction being built. More...
 
StatefulAssemblerset (const InstructionPrefix &prefix)
 Adds a prefix to the instruction being built. More...
 
StatefulAssemblerset (const InstructionHint &hint)
 Adds an instruction level hint to the instruction being built. More...
 
StatefulAssemblerset (const OperandHint &hint)
 Adds an operand level hint to the instruction being built. More...
 
StatefulAssemblerinst (const Instruction &instruction)
 Assembles an instruction in the given instruction builder. More...
 
CodeIterator getCodeIterator ()
 Gets iterator which allows to iterate through the whole machine code byte by byte. More...
 
std::vector< AssembledInstruction > & getAssembledInstructions ()
 Gets all chosen assembled instructions. More...
 
fcml_usize getCodeLength ()
 Gets the code length of all assembled instructions available. More...
 
void flush ()
 Assembles all pending instructions. More...
 
const ParserConfiggetParserConfig () const
 Gets configuration used by parser if parsing is supported. More...
 
ParserConfiggetParserConfig ()
 Gets configuration used by parser if parsing is supported. More...
 
const SymbolTablegetSymbolTable () const
 Gets symbol table used together with the parser. More...
 
SymbolTablegetSymbolTable ()
 Gets symbol table used together with the parser. More...
 
void setSymbolTable (SymbolTable *symbolTable)
 Sets a new symbol table for the parser. More...
 

Static Public Member Functions

static SAFlush FLUSH ()
 Creates flush indicated for "shift" operators. More...
 

Detailed Description

It's a stateful assembler which can be used to assemble instructions one by one on the fly.

By default is works with the general instruction models as well as with instruction builders, but it can be also configured to parse whole statements using internally managed parser. It holds it's own state, so it's not necessary to update instruction pointer etc while it's working. Assembled instructions are placed inside a dedicated vector, but generated machine code is accessing directly by the dedicated CodeIterator.

Since
1.1.0
Remarks
This class isn't thread-safe.

Constructor & Destructor Documentation

◆ StatefulAssembler()

fcml::StatefulAssembler::StatefulAssembler ( Assembler assembler,
AssemblerContext context,
bool  enableParser = false 
)
inline

Creates a stateful assembler for the given assembler and assembler context.

Bear in mind that assembler and context are not copied in any way and have to be valid as long as the stateful assembler in in use. Parsing support can be enabled optionally using the third parameter.

Parameters
assemblerThe assembled that will be used to assemble the code.
contextThe assembler context.
enableParserEnables parsing support.
Since
1.1.0

◆ ~StatefulAssembler()

virtual fcml::StatefulAssembler::~StatefulAssembler ( )
inlinevirtual

Destructor.

Since
1.1.0

Member Function Documentation

◆ add()

StatefulAssembler& fcml::StatefulAssembler::add ( const IB ib)
inline

Adds instruction builder to the stateful assembler.

Such a instruction builder will be used then to assemble an instruction it represents. Before any operation is performed, pending instruction is flushed if there is any available.

Parameters
ibThe instruction builder to be flushed.
Returns
The stateful assembler itself.
Exceptions
AssemblingFailedException
Since
1.1.0

◆ flush()

void fcml::StatefulAssembler::flush ( )
inline

Assembles all pending instructions.

Since
1.1.0
Exceptions
AssemblingFailedException

◆ FLUSH()

static SAFlush fcml::StatefulAssembler::FLUSH ( )
inlinestatic

Creates flush indicated for "shift" operators.

Returns
Flush indicator.
Since
1.1.0

◆ getAssembledInstructions()

std::vector<AssembledInstruction>& fcml::StatefulAssembler::getAssembledInstructions ( )
inline

Gets all chosen assembled instructions.

Returns
All assembled instructions available in the buffer.
Since
1.1.0

◆ getCodeIterator()

CodeIterator fcml::StatefulAssembler::getCodeIterator ( )
inline

Gets iterator which allows to iterate through the whole machine code byte by byte.

Returns
Iterator instance.
Since
1.1.0

◆ getCodeLength()

fcml_usize fcml::StatefulAssembler::getCodeLength ( )
inline

Gets the code length of all assembled instructions available.

Returns
The code length.
Since
1.1.0

◆ getParserConfig() [1/2]

const ParserConfig& fcml::StatefulAssembler::getParserConfig ( ) const
inline

Gets configuration used by parser if parsing is supported.

Returns
Parser configuration.

◆ getParserConfig() [2/2]

ParserConfig& fcml::StatefulAssembler::getParserConfig ( )
inline

Gets configuration used by parser if parsing is supported.

Returns
Parser configuration.
Since
1.1.0

◆ getSymbolTable() [1/2]

const SymbolTable* fcml::StatefulAssembler::getSymbolTable ( ) const
inline

Gets symbol table used together with the parser.

Returns
The symbol table used by the parser.
Since
1.1.0

◆ getSymbolTable() [2/2]

SymbolTable* fcml::StatefulAssembler::getSymbolTable ( )
inline

Gets symbol table used together with the parser.

Returns
The symbol table used by the parser.
Since
1.1.0

◆ inst() [1/2]

StatefulAssembler& fcml::StatefulAssembler::inst ( const fcml_cstring mnemonic)
inline

Creates an instruction builder for the given mnemonic.

Parameters
mnemonicThe instruction mnemonic.
Returns
The stateful assembler itself.
Exceptions
AssemblingFailedException,ParsingFailedException
Since
1.1.0

◆ inst() [2/2]

StatefulAssembler& fcml::StatefulAssembler::inst ( const Instruction instruction)
inline

Assembles an instruction in the given instruction builder.

Parameters
instructionInstruction to be assembled.
Returns
Stateful assembler.
Exceptions
AssemblingFailedException
Since
1.1.0

◆ op() [1/5]

StatefulAssembler& fcml::StatefulAssembler::op ( const Operand operand)
inline

Adds an operand to the instruction builder associated with the buffer.

Parameters
operandThe operand to be added..
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ op() [2/5]

StatefulAssembler& fcml::StatefulAssembler::op ( const Register reg)
inline

Adds the new register operand to the instruction builder associated with the buffer.

Parameters
regThe register.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ op() [3/5]

StatefulAssembler& fcml::StatefulAssembler::op ( const Integer imm)
inline

Adds the new immediate operand to the instruction builder associated with the buffer.

Parameters
immThe immediate value.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ op() [4/5]

StatefulAssembler& fcml::StatefulAssembler::op ( const Address address)
inline

Adds the new address operand to the instruction builder associated with the buffer.

Parameters
addressThe address.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ op() [5/5]

StatefulAssembler& fcml::StatefulAssembler::op ( const FarPointer pointer)
inline

Adds the new far pointer operand to the instruction builder associated with the buffer.

Parameters
pointerThe far pointer.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ operator<<() [1/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const IB ib)
inline

Adds instruction builder to the stateful assembler.

Such a instruction builder will be used then to assemble an instruction it represents. Before any operation is performed, pending instruction is flushed if there is any available.

Parameters
ibThe instruction builder to be flushed.
Returns
The stateful assembler itself.
Exceptions
AssemblingFailedException
Since
1.1.0

◆ operator<<() [2/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const fcml_cstring mnemonic)
inline

Creates an instruction builder for the given mnemonic.

Parameters
mnemonicThe instruction mnemonic.
Returns
The stateful assembler itself.
Exceptions
AssemblingFailedException,ParsingFailedException
Since
1.1.0

◆ operator<<() [3/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const Register reg)
inline

Adds the new register operand to the instruction builder associated with the buffer.

Parameters
regThe register.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ operator<<() [4/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const Integer imm)
inline

Adds the new immediate operand to the instruction builder associated with the buffer.

Parameters
immThe immediate value.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ operator<<() [5/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const Address address)
inline

Adds the new address operand to the instruction builder associated with the buffer.

Parameters
addressThe address.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ operator<<() [6/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const FarPointer pointer)
inline

Adds the new far pointer operand to the instruction builder associated with the buffer.

Parameters
pointerThe far pointer.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ operator<<() [7/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const Operand operand)
inline

Adds an operand to the instruction builder associated with the buffer.

Parameters
operandThe operand to be added.
Returns
The stateful assembler itself.
Exceptions
IllegalStateException
Since
1.1.0

◆ operator<<() [8/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const SAFlush indic)
inline

Flushes the instruction builder.

Parameters
indicFlush indicator.
Returns
The stateful assembler itself.
Exceptions
AssemblingFailedException
Since
1.1.0

◆ operator<<() [9/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const Instruction instruction)
inline

Assembles an instruction in the given instruction builder.

Parameters
instructionInstruction to be assembled.
Returns
Stateful assembler.
Exceptions
AssemblingFailedException
Since
1.1.0

◆ operator<<() [10/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const InstructionPrefix prefix)
inline

Adds a prefix to the instruction being built.

Parameters
prefixThe prefix to be added.
Returns
The instruction builder with the new prefix set for it.
Since
1.1.0

◆ operator<<() [11/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const InstructionHint hint)
inline

Adds an instruction level hint to the instruction being built.

Parameters
hintThe hint to be added.
Returns
The instruction builder with the new hint added to it.
Since
1.1.0

◆ operator<<() [12/12]

StatefulAssembler& fcml::StatefulAssembler::operator<< ( const OperandHint hint)
inline

Adds an operand level hint to the instruction being built.

Parameters
hintThe hint to be added.
Returns
The instruction builder with the new hint added to it.
Since
1.1.0

◆ set() [1/3]

StatefulAssembler& fcml::StatefulAssembler::set ( const InstructionPrefix prefix)
inline

Adds a prefix to the instruction being built.

Parameters
prefixThe prefix to be added.
Returns
The instruction builder with the new prefix set for it.
Since
1.1.0

◆ set() [2/3]

StatefulAssembler& fcml::StatefulAssembler::set ( const InstructionHint hint)
inline

Adds an instruction level hint to the instruction being built.

Parameters
hintThe hint to be added.
Returns
The instruction builder with the new hint added to it.
Since
1.1.0

◆ set() [3/3]

StatefulAssembler& fcml::StatefulAssembler::set ( const OperandHint hint)
inline

Adds an operand level hint to the instruction being built.

Parameters
hintThe hint to be added.
Returns
The instruction builder with the new hint added to it.
Since
1.1.0

◆ setSymbolTable()

void fcml::StatefulAssembler::setSymbolTable ( SymbolTable symbolTable)
inline

Sets a new symbol table for the parser.

Parameters
symbolTableThe new symbol table.
Since
1.1.0

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