27#ifndef FCML_LAG_ASSEMBLER_HPP_
28#define FCML_LAG_ASSEMBLER_HPP_
64 return _errorContainer;
73 return static_cast<fcml_usize
>(_assembledInstructions.size());
85 if (index > _assembledInstructions.size()) {
89 return _assembledInstructions[index];
99 return _assembledInstructions;
119 _errorContainer.
clean();
120 _assembledInstructions.clear();
135 return _assembledInstructions;
145 _errorContainer = errorContainer;
153 std::vector<AssembledInstruction> _assembledInstructions;
169 _symbolTable( NULL) {
180 _entryPoint(operatingMode, ip), _symbolTable( NULL) {
242 _entryPoint = entryPoint;
252 _entryPoint.
setIP(ip);
323 _symbolTable = symbolTable;
414 ErrorTypeConverter::convert(res.
errors, errorContainer);
424 FCML_TEXT(
"Assembling failed")), errorContainer,
430 std::vector<AssembledInstruction> &assembledInstructions =
433 assembledInstructions.clear();
438 while (next_instruction) {
441 ErrorTypeConverter::convert(instruction_warnings,
442 instructionWarnings);
444 next_instruction->
code,
445 next_instruction->
code_length, instructionWarnings);
446 assembledInstructions.push_back(assembledInstruction);
447 next_instruction = next_instruction->
next;
459 }
catch (std::exception &exc) {
Describes an assembled instruction.
Definition fcml_assembler.hpp:57
Assembler configuration.
Definition fcml_assembler.hpp:321
bool isThrowExceptionOnError() const
Returns true if exception should be thrown when assembling fails.
Definition fcml_assembler.hpp:476
Assembling failed.
Definition fcml_assembler.hpp:45
Bad arguments.
Definition fcml_common.hpp:242
Iterates over machine code bytes from assembled instructions.
Definition fcml_assembler.hpp:872
Inherit from this class in order to get access to the native FCML dialect structure.
Definition fcml_dialect.hpp:98
fcml_st_dialect * extractDialect(const Dialect &dialect) const
Extracts the native FCML dialect from the dialect object.
Definition fcml_dialect.hpp:122
An abstract dialect.
Definition fcml_dialect.hpp:41
Holds instruction pointer, processor operating mode and memory segment flags.
Definition fcml_common.hpp:524
void setIP(fcml_ip ip)
Sets a new instruction pointer for the entry point.
Definition fcml_common.hpp:651
void setAddressSizeAttribute(fcml_usize addressSizeAttribute)
Sets a new address size attribute for the entry point.
Definition fcml_common.hpp:611
void setOpMode(OperatingMode opMode)
Sets a new processor operating mode for the entry point.
Definition fcml_common.hpp:671
OperatingMode
Supported operating modes.
Definition fcml_common.hpp:531
void incrementIP(fcml_ip ip)
Increments the instruction pointer by given number of bytes.
Definition fcml_common.hpp:681
void setOperandSizeAttribute(fcml_usize operandSizeAttribute)
Sets a new operand size attribute for the entry point.
Definition fcml_common.hpp:631
Wraps multiple errors into one component.
Definition fcml_errors.hpp:148
fcml_cstring prepareErrorMessage(const fcml_cstring &message) const
Prepares an error message basing on the first error in the container.
Definition fcml_errors.hpp:283
void clean()
Cleans all errors and warnings.
Definition fcml_errors.hpp:296
Component can not be initialized correctly.
Definition fcml_common.hpp:231
Assembler context.
Definition fcml_lag_assembler.hpp:160
const SymbolTable * getSymbolTable() const
Gets a pointer to the constant symbol table stored in the context.
Definition fcml_lag_assembler.hpp:302
const EntryPoint & getEntryPoint() const
Gets constant reference to the entry point.
Definition fcml_lag_assembler.hpp:221
void setAddressSizeAttribute(fcml_usize addressSizeAttribute)
Sets a new address size attribute for the entry point.
Definition fcml_lag_assembler.hpp:282
void setOperandSizeAttribute(fcml_usize operandSizeAttribute)
Sets a new operand size attribute for the entry point.
Definition fcml_lag_assembler.hpp:292
void setOperatingMode(EntryPoint::OperatingMode operatingMode)
Sets a new processor operating mode for the entry point.
Definition fcml_lag_assembler.hpp:272
AssemblerConf & getConfig()
Gets reference to the assembler configuration.
Definition fcml_lag_assembler.hpp:201
void setIP(fcml_ip ip)
Sets a new instruction pointer.
Definition fcml_lag_assembler.hpp:251
void setSymbolTable(SymbolTable *symbolTable)
Sets a new symbol table for the context.
Definition fcml_lag_assembler.hpp:322
const AssemblerConf & getConfig() const
Gets constant reference to assembler configuration.
Definition fcml_lag_assembler.hpp:191
EntryPoint & getEntryPoint()
Gets reference to the entry point.
Definition fcml_lag_assembler.hpp:231
void incrementIP(fcml_ip ip)
Increments the instruction pointer by given number of bytes.
Definition fcml_lag_assembler.hpp:262
MultiPassAssemblerContext()
Default constructor.
Definition fcml_lag_assembler.hpp:168
void setEntryPoint(const EntryPoint &entryPoint)
Sets a new entry point.
Definition fcml_lag_assembler.hpp:241
MultiPassAssemblerContext(EntryPoint::OperatingMode operatingMode, fcml_ip ip=0)
Creates assembler context for given operating mode and instruction pointer.
Definition fcml_lag_assembler.hpp:178
void setConfig(const AssemblerConf &config)
Sets a new assembler configuration.
Definition fcml_lag_assembler.hpp:211
SymbolTable * getSymbolTable()
Gets a pointer to the symbol table stored in the context.
Definition fcml_lag_assembler.hpp:312
Assembler result which contains all assembled instructions.
Definition fcml_lag_assembler.hpp:38
void setErrorContainer(const ErrorContainer &errorContainer)
Sets new error container for the result.
Definition fcml_lag_assembler.hpp:144
void clear()
Clears the result.
Definition fcml_lag_assembler.hpp:118
const std::vector< AssembledInstruction > & getAssembledInstructions() const
Gets constant vector of all assembled instructions.
Definition fcml_lag_assembler.hpp:98
MultiPassAssemblerResult()
Default constructor.
Definition fcml_lag_assembler.hpp:45
const ErrorContainer & getErrorContainer() const
Gets error container.
Definition fcml_lag_assembler.hpp:63
CodeIterator getCodeIterator()
Gets iterator which allows to iterate through the whole machine code byte by byte.
Definition fcml_lag_assembler.hpp:109
const AssembledInstruction & operator[](fcml_usize index) const
Gets one assembled instruction by its index.
Definition fcml_lag_assembler.hpp:84
virtual ~MultiPassAssemblerResult()
Virtual destructor.
Definition fcml_lag_assembler.hpp:52
fcml_usize getSize() const
Gets number of assembled instructions.
Definition fcml_lag_assembler.hpp:72
std::vector< AssembledInstruction > & getAssembledInstructions()
Gets vector of all assembled instructions.
Definition fcml_lag_assembler.hpp:134
An assembler wrapper, as you can see the assembler context is managed internally and is not exposed o...
Definition fcml_lag_assembler.hpp:342
MultiPassAssembler(Dialect &dialect)
Creates multi-pass assembler for a dialect.
Definition fcml_lag_assembler.hpp:351
fcml_ceh_error assemble(MultiPassAssemblerContext &ctx, const fcml_string *instructions, MultiPassAssemblerResult &result)
Assembles given instruction model.
Definition fcml_lag_assembler.hpp:385
virtual ~MultiPassAssembler()
Virtual destructor.
Definition fcml_lag_assembler.hpp:365
Object which shouldn't be copied can inherit from this class.
Definition fcml_common.hpp:288
Derive from this class if you really need access to the native symbol table.
Definition fcml_symbols.hpp:251
fcml_st_symbol_table & extractSymbolTable(SymbolTable &symbolTable)
Extracts the native symbol table for the given symbol table wrapper.
Definition fcml_symbols.hpp:259
Definition fcml_symbols.hpp:143
struct fcml_st_assembler fcml_st_assembler
Abstract assembler representation.
Definition fcml_assembler.h:43
LIB_EXPORT void LIB_CALL fcml_fn_assembler_free(fcml_st_assembler *assembler)
Frees assembler instance.
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assembler_init(const fcml_st_dialect *dialect, fcml_st_assembler **assembler)
Initializes assembler for given dialect.
C++ wrapper for FCML assembler.
fcml_int64_t fcml_ip
General instruction pointer holder.
Definition fcml_common.h:96
fcml_uint16_t fcml_ceh_error
All error codes should be held in variables of this type.
Definition fcml_errors.h:156
Experimental multiline load-and-go assembler implementation.
LIB_EXPORT void LIB_CALL fcml_fn_lag_assembler_result_prepare(fcml_st_lag_assembler_result *result)
Prepares reusable result holder for assembler.
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_lag_assemble(fcml_st_lag_assembler_context *context, const fcml_string *source_code, fcml_st_lag_assembler_result *result)
Multipass load-and-go assembler.
LIB_EXPORT void LIB_CALL fcml_fn_lag_assembler_result_free(fcml_st_lag_assembler_result *result)
Cleans result holder.
C++ API for symbols handling.
#define FCML_TEXT(x)
Used to code literal strings.
Definition fcml_types.h:61
@ FCML_CEH_GEC_NO_ERROR
Operation succeed.
Definition fcml_errors.h:42
@ FCML_CEH_GEC_VALUE_OUT_OF_RANGE
Used mainly in case of integers and offsets.
Definition fcml_errors.h:55
This structure represents an encoded instruction.
Definition fcml_assembler.h:87
struct fcml_st_assembled_instruction * next
The next assembled instruction in the chain, if there is any.
Definition fcml_assembler.h:89
fcml_usize code_length
The instruction code length in bytes.
Definition fcml_assembler.h:95
fcml_st_ceh_error_container warnings
Optional warning messages related to the assembled instruction.
Definition fcml_assembler.h:91
fcml_uint8_t * code
The instruction's machine code.
Definition fcml_assembler.h:93
Container for all collected errors and warnings.
Definition fcml_errors.h:180
Load-and-go assembler runtime context.
Definition fcml_lag_assembler.h:47
fcml_st_symbol_table symbol_table
Symbols table.
Definition fcml_lag_assembler.h:55
fcml_st_assembler_conf configuration
Assembler behavior can be configured here.
Definition fcml_lag_assembler.h:51
fcml_st_entry_point entry_point
Instruction entry point configuration.
Definition fcml_lag_assembler.h:53
fcml_st_assembler * assembler
Assembler instance that should be used to assemble instructions.
Definition fcml_lag_assembler.h:49
Result holder for load-and-go assembler.
Definition fcml_lag_assembler.h:37
fcml_st_ceh_error_container errors
Error and warning messages from one-line assembler.
Definition fcml_lag_assembler.h:39
fcml_st_assembled_instruction * instructions
Chain of assembled instructions.
Definition fcml_lag_assembler.h:43