27 #ifndef FCML_STATEFUL_ASSEMBLER_HPP_ 28 #define FCML_STATEFUL_ASSEMBLER_HPP_ 69 bool enableParser =
false) :
71 _assembler(assembler),
115 _instructionBuilder.setNotNull(
true);
116 _instructionBuilder.setValue(ib);
129 return inst(mnemonic);
144 _parserContext.setIp(_context.getEntryPoint().getIP());
147 _parser->parse(_parserContext, mnemonic, _parserResult);
148 *
this << _parserResult.getInstruction();
152 _instructionBuilder.setNotNull(
true);
153 _instructionBuilder.setValue(
IB(mnemonic));
231 if (!_instructionBuilder.isNotNull()) {
233 FCML_TEXT(
"No instruction builder available."));
235 IB &ib = _instructionBuilder.getValue();
313 return inst(instruction);
353 if (!_instructionBuilder.isNotNull()) {
355 FCML_TEXT(
"No instruction builder available."));
357 _instructionBuilder.getValue() << prefix;
368 if (!_instructionBuilder.isNotNull()) {
370 FCML_TEXT(
"No instruction builder available."));
372 _instructionBuilder.getValue() << hint;
383 if (!_instructionBuilder.isNotNull()) {
385 FCML_TEXT(
"No instruction builder available."));
387 _instructionBuilder.getValue() << hint;
410 _assembler.assemble(_context, instruction, _result);
414 _result.getChosenInstruction();
415 if (assembledInstruction) {
416 _assembledInstructions.push_back(*assembledInstruction);
420 FCML_TEXT(
"Chosen instruction hasn't been set. It seems " 421 "that the instruction chooser isn't working " 448 return _assembledInstructions;
468 if (_instructionBuilder.isNotNull()) {
470 Instruction instruction = _instructionBuilder.getValue().build();
472 _instructionBuilder.setNotNull(
false);
474 *
this << instruction;
491 return _parserContext.getConfig();
499 return _parserContext.getConfig();
526 _parserContext.setSymbolTable(symbolTable);
546 std::vector<AssembledInstruction> _assembledInstructions;
548 fcml_usize _codeLength;
An instruction builder.
Definition: fcml_common.hpp:7602
C++ wrapper for FCML assembler.
fcml_usize getCodeLength() const
Gets number of bytes in the buffer.
Definition: fcml_assembler.hpp:128
Parser wrapper.
Definition: fcml_parser.hpp:387
static SAFlush FLUSH()
Creates flush indicated for "shift" operators.
Definition: fcml_stateful_assembler.hpp:483
void setThrowExceptionOnError(bool throwExceptionOnError)
Sets the way how the error handling is done.
Definition: fcml_assembler.hpp:487
fcml_usize getCodeLength()
Gets the code length of all assembled instructions available.
Definition: fcml_stateful_assembler.hpp:457
Assembler result.
Definition: fcml_assembler.hpp:182
Illegal state exception.
Definition: fcml_common.hpp:253
StatefulAssembler & op(const Address &address)
Adds the new address operand to the instruction builder associated with the buffer.
Definition: fcml_stateful_assembler.hpp:275
Assembling failed.
Definition: fcml_assembler.hpp:45
std::vector< AssembledInstruction > & getAssembledInstructions()
Gets all chosen assembled instructions.
Definition: fcml_stateful_assembler.hpp:446
std::basic_string< fcml_char > fcml_cstring
By using this type definition here, it will be definitely much easier to support UNICODE in future re...
Definition: fcml_common.hpp:53
Address operand.
Definition: fcml_common.hpp:4601
x86 - 64 register representation.
Definition: fcml_common.hpp:1601
Wraps operand hint and exposes factory methods for instruction hints.
Definition: fcml_common.hpp:461
void flush()
Assembles all pending instructions.
Definition: fcml_stateful_assembler.hpp:467
Assembler context.
Definition: fcml_assembler.hpp:510
Wrapper for nullable value types.
Definition: fcml_common.hpp:120
ParserConfig & getParserConfig()
Gets configuration used by parser if parsing is supported.
Definition: fcml_stateful_assembler.hpp:498
#define FCML_TEXT(x)
Used to code literal strings.
Definition: fcml_types.h:61
StatefulAssembler & op(const Operand &operand)
Adds an operand to the instruction builder associated with the buffer.
Definition: fcml_stateful_assembler.hpp:230
void setSymbolTable(SymbolTable *symbolTable)
Sets a new symbol table for the parser.
Definition: fcml_stateful_assembler.hpp:525
Describes far pointer.
Definition: fcml_common.hpp:3902
Definition: fcml_assembler.hpp:39
Wraps instruction hint and exposes factory methods for instruction hints.
Definition: fcml_common.hpp:402
virtual ~StatefulAssembler()
Destructor.
Definition: fcml_stateful_assembler.hpp:81
Parser configuration.
Definition: fcml_parser.hpp:55
Parser result.
Definition: fcml_parser.hpp:275
Instruction operand.
Definition: fcml_common.hpp:5184
Represents integer value.
Definition: fcml_common.hpp:700
void setIncrementIp(bool incrementIp)
Definition: fcml_assembler.hpp:437
An assembler wrapper.
Definition: fcml_assembler.hpp:717
void op(const Operand &operand)
Sets a next operand for the instruction.
Definition: fcml_common.hpp:7694
Describes an assembled instruction.
Definition: fcml_assembler.hpp:57
StatefulAssembler & inst(const Instruction &instruction)
Assembles an instruction in the given instruction builder.
Definition: fcml_stateful_assembler.hpp:399
StatefulAssembler(Assembler &assembler, AssemblerContext &context, bool enableParser=false)
Creates a stateful assembler for the given assembler and assembler context.
Definition: fcml_stateful_assembler.hpp:68
SymbolTable * getSymbolTable()
Gets symbol table used together with the parser.
Definition: fcml_stateful_assembler.hpp:516
fcml_st_symbol_table & getSymbolTable()
Gets native FCML symbol table.
Definition: fcml_symbols.hpp:181
StatefulAssembler & op(const Register ®)
Adds the new register operand to the instruction builder associated with the buffer.
Definition: fcml_stateful_assembler.hpp:249
StatefulAssembler & op(const FarPointer &pointer)
Adds the new far pointer operand to the instruction builder associated with the buffer.
Definition: fcml_stateful_assembler.hpp:288
StatefulAssembler & operator<<(const IB &ib)
Adds instruction builder to the stateful assembler.
Definition: fcml_stateful_assembler.hpp:98
StatefulAssembler & inst(const fcml_cstring &mnemonic)
Creates an instruction builder for the given mnemonic.
Definition: fcml_stateful_assembler.hpp:140
CodeIterator getCodeIterator()
Gets iterator which allows to iterate through the whole machine code byte by byte.
Definition: fcml_stateful_assembler.hpp:435
void setThrowExceptionOnError(bool throwExceptionOnError)
Sets exception on error flag.
Definition: fcml_parser.hpp:137
Describes an instruction.
Definition: fcml_common.hpp:7185
Wraps instruction prefix and prepares factory methods for the hints.
Definition: fcml_common.hpp:312
const ParserConfig & getParserConfig() const
Gets configuration used by parser if parsing is supported.
Definition: fcml_stateful_assembler.hpp:490
Assembler configuration.
Definition: fcml_assembler.hpp:321
Parser context.
Definition: fcml_parser.hpp:153
Definition: fcml_symbols.hpp:143
StatefulAssembler & op(const Integer &imm)
Adds the new immediate operand to the instruction builder associated with the buffer.
Definition: fcml_stateful_assembler.hpp:262
Dialect & getDialect() const
Gets dialect associated with the assembler.
Definition: fcml_assembler.hpp:855
const SymbolTable * getSymbolTable() const
Gets symbol table used together with the parser.
Definition: fcml_stateful_assembler.hpp:507
Used only to indicate the need of the flush operation.
Definition: fcml_stateful_assembler.hpp:54
Iterates over machine code bytes from assembled instructions.
Definition: fcml_assembler.hpp:872
It's a stateful assembler which can be used to assemble instructions one by one on the fly...
Definition: fcml_stateful_assembler.hpp:50
C++ wrapper for instruction parser.
StatefulAssembler & add(const IB &ib)
Adds instruction builder to the stateful assembler.
Definition: fcml_stateful_assembler.hpp:113