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);
147 _parser->
parse(_parserContext, mnemonic, _parserResult);
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);
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;
546 std::vector<AssembledInstruction> _assembledInstructions;
548 fcml_usize _codeLength;
Address operand.
Definition fcml_common.hpp:4601
Describes an assembled instruction.
Definition fcml_assembler.hpp:57
fcml_usize getCodeLength() const
Gets number of bytes in the buffer.
Definition fcml_assembler.hpp:128
Assembler configuration.
Definition fcml_assembler.hpp:321
void setIncrementIp(bool incrementIp)
Definition fcml_assembler.hpp:437
void setThrowExceptionOnError(bool throwExceptionOnError)
Sets the way how the error handling is done.
Definition fcml_assembler.hpp:487
Assembler context.
Definition fcml_assembler.hpp:510
const EntryPoint & getEntryPoint() const
Gets reference to the constant entry point instance associated with the context.
Definition fcml_assembler.hpp:573
const AssemblerConf & getConfig() const
Gets constant assembler configuration associated with the context.
Definition fcml_assembler.hpp:540
Assembler result.
Definition fcml_assembler.hpp:182
const AssembledInstruction * getChosenInstruction() const
Gets instruction chosen by the assembler as the preferred one.
Definition fcml_assembler.hpp:200
An assembler wrapper.
Definition fcml_assembler.hpp:717
Dialect & getDialect() const
Gets dialect associated with the assembler.
Definition fcml_assembler.hpp:855
fcml_ceh_error assemble(AssemblerContext &ctx, const Instruction &instruction, AssemblerResult &result)
Assembles given generic instruction model.
Definition fcml_assembler.hpp:760
Assembling failed.
Definition fcml_assembler.hpp:45
Iterates over machine code bytes from assembled instructions.
Definition fcml_assembler.hpp:872
fcml_ip getIP() const
Gets instruction pointer held by the entry point.
Definition fcml_common.hpp:641
Describes far pointer.
Definition fcml_common.hpp:3902
An instruction builder.
Definition fcml_common.hpp:7602
void op(const Operand &operand)
Sets a next operand for the instruction.
Definition fcml_common.hpp:7694
Illegal state exception.
Definition fcml_common.hpp:253
Wraps instruction prefix and prepares factory methods for the hints.
Definition fcml_common.hpp:312
Describes an instruction.
Definition fcml_common.hpp:7185
Represents integer value.
Definition fcml_common.hpp:700
Wrapper for nullable value types.
Definition fcml_common.hpp:120
Instruction operand.
Definition fcml_common.hpp:5184
Parser configuration.
Definition fcml_parser.hpp:55
void setThrowExceptionOnError(bool throwExceptionOnError)
Sets exception on error flag.
Definition fcml_parser.hpp:137
Parser context.
Definition fcml_parser.hpp:153
void setSymbolTable(SymbolTable *symbolTable)
Sets a symbol table for the instruction.
Definition fcml_parser.hpp:257
const ParserConfig & getConfig() const
Gets the parser configuration associated with the context.
Definition fcml_parser.hpp:186
void setIp(fcml_ip ip)
Gets a new instruction pointer.
Definition fcml_parser.hpp:216
const SymbolTable * getSymbolTable() const
Gets the symbol table associated with the context.
Definition fcml_parser.hpp:237
Parser result.
Definition fcml_parser.hpp:275
const Instruction & getInstruction() const
Gets the parsed instruction.
Definition fcml_parser.hpp:301
Parser wrapper.
Definition fcml_parser.hpp:387
fcml_ceh_error parse(ParserContext &ctx, const fcml_cstring &instruction, ParserResult &parserResult)
Parses instruction given in the parameters.
Definition fcml_parser.hpp:410
x86 - 64 register representation.
Definition fcml_common.hpp:1601
Used only to indicate the need of the flush operation.
Definition fcml_stateful_assembler.hpp:54
It's a stateful assembler which can be used to assemble instructions one by one on the fly.
Definition fcml_stateful_assembler.hpp:50
SymbolTable * getSymbolTable()
Gets symbol table used together with the parser.
Definition fcml_stateful_assembler.hpp:516
StatefulAssembler & set(const OperandHint &hint)
Adds an operand level hint to the instruction being built.
Definition fcml_stateful_assembler.hpp:382
const SymbolTable * getSymbolTable() const
Gets symbol table used together with the parser.
Definition fcml_stateful_assembler.hpp:507
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(Assembler &assembler, AssemblerContext &context, bool enableParser=false)
Creates a stateful assembler for the given assembler and assembler context.
Definition fcml_stateful_assembler.hpp:68
fcml_usize getCodeLength()
Gets the code length of all assembled instructions available.
Definition fcml_stateful_assembler.hpp:457
StatefulAssembler & inst(const fcml_cstring &mnemonic)
Creates an instruction builder for the given mnemonic.
Definition fcml_stateful_assembler.hpp:140
ParserConfig & getParserConfig()
Gets configuration used by parser if parsing is supported.
Definition fcml_stateful_assembler.hpp:498
StatefulAssembler & op(const Register ®)
Adds the new register operand to the instruction builder associated with the buffer.
Definition fcml_stateful_assembler.hpp:249
std::vector< AssembledInstruction > & getAssembledInstructions()
Gets all chosen assembled instructions.
Definition fcml_stateful_assembler.hpp:446
StatefulAssembler & set(const InstructionPrefix &prefix)
Adds a prefix to the instruction being built.
Definition fcml_stateful_assembler.hpp:352
StatefulAssembler & op(const Operand &operand)
Adds an operand to the instruction builder associated with the buffer.
Definition fcml_stateful_assembler.hpp:230
virtual ~StatefulAssembler()
Destructor.
Definition fcml_stateful_assembler.hpp:81
StatefulAssembler & op(const Integer &imm)
Adds the new immediate operand to the instruction builder associated with the buffer.
Definition fcml_stateful_assembler.hpp:262
StatefulAssembler & add(const IB &ib)
Adds instruction builder to the stateful assembler.
Definition fcml_stateful_assembler.hpp:113
void setSymbolTable(SymbolTable *symbolTable)
Sets a new symbol table for the parser.
Definition fcml_stateful_assembler.hpp:525
StatefulAssembler & operator<<(const IB &ib)
Adds instruction builder to the stateful assembler.
Definition fcml_stateful_assembler.hpp:98
StatefulAssembler & op(const Address &address)
Adds the new address operand to the instruction builder associated with the buffer.
Definition fcml_stateful_assembler.hpp:275
const ParserConfig & getParserConfig() const
Gets configuration used by parser if parsing is supported.
Definition fcml_stateful_assembler.hpp:490
StatefulAssembler & set(const InstructionHint &hint)
Adds an instruction level hint to the instruction being built.
Definition fcml_stateful_assembler.hpp:367
StatefulAssembler & inst(const Instruction &instruction)
Assembles an instruction in the given instruction builder.
Definition fcml_stateful_assembler.hpp:399
static SAFlush FLUSH()
Creates flush indicated for "shift" operators.
Definition fcml_stateful_assembler.hpp:483
CodeIterator getCodeIterator()
Gets iterator which allows to iterate through the whole machine code byte by byte.
Definition fcml_stateful_assembler.hpp:435
void flush()
Assembles all pending instructions.
Definition fcml_stateful_assembler.hpp:467
Definition fcml_symbols.hpp:143
C++ wrapper for FCML assembler.
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
C++ wrapper for instruction parser.
#define FCML_TEXT(x)
Used to code literal strings.
Definition fcml_types.h:61
Wraps instruction hint and exposes factory methods for instruction hints.
Definition fcml_common.hpp:402
Wraps operand hint and exposes factory methods for instruction hints.
Definition fcml_common.hpp:461