fcml 1.3.0
Loading...
Searching...
No Matches
fcml_assembler.h
Go to the documentation of this file.
1/*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2024 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
26#ifndef FCML_ASSEMBLER_H_
27#define FCML_ASSEMBLER_H_
28
29#include "fcml_lib_export.h"
30
31#include "fcml_types.h"
32#include "fcml_errors.h"
33#include "fcml_common.h"
34#include "fcml_dialect.h"
35#include "fcml_optimizers.h"
36#include "fcml_choosers.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
44
80
103
115
125
139 const fcml_st_dialect *dialect, fcml_st_assembler **assembler);
140
161 const fcml_st_instruction *instruction,
163
177LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_prepare(
179
189LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_free(
191
198LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_free(
199 fcml_st_assembled_instruction *instruction);
200
218 fcml_st_assembled_instruction *instruction);
219
226LIB_EXPORT void LIB_CALL fcml_fn_assembler_free(fcml_st_assembler *assembler);
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif /* FCML_ASSEMBLER_H_ */
struct fcml_st_assembler fcml_st_assembler
Abstract assembler representation.
Definition fcml_assembler.h:43
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assemble(fcml_st_assembler_context *context, const fcml_st_instruction *instruction, fcml_st_assembler_result *result)
Assembles one instruction encoded in the generic instruction model.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_prepare(fcml_st_assembler_result *result)
Prepares reusable result holder for assembler.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_free(fcml_st_assembler *assembler)
Frees assembler instance.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_detach(fcml_st_assembled_instruction **chain, fcml_st_assembled_instruction *instruction)
Detaches given instruction from the instructions chain.
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.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_free(fcml_st_assembled_instruction *instruction)
Frees assembled instruction.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_free(fcml_st_assembler_result *result)
Cleans result holder.
API for instruction choosers.
fcml_ptr(LIB_CALL * fcml_fnp_asm_instruction_chooser)(fcml_st_chooser_context *chooser_context)
Instruction chooser function pointer declaration.
Definition fcml_choosers.h:68
Definitions of common structures used by FCML components.
Structures and functions related to dialects.
struct fcml_st_dialect fcml_st_dialect
Assembler dialect.
Definition fcml_dialect.h:36
Global error handling related declarations.
fcml_uint16_t fcml_ceh_error
All error codes should be held in variables of this type.
Definition fcml_errors.h:156
Handles Win32 DLL symbols importing/exporting.
API for assembler optimizers.
fcml_ceh_error(LIB_CALL * fcml_fnp_asm_optimizer)(fcml_st_asm_optimizer_context *context, fcml_st_asm_optimizer_processing_details *ds_flags, fcml_fnp_asm_optimizer_callback callback, fcml_ptr args)
Function pointer declaration for optimizers.
Definition fcml_optimizers.h:102
Types declarations.
Details describing an assembled instruction.
Definition fcml_common.h:809
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
fcml_st_assembled_instruction_details details
Instruction flags, which can be helpful while choosing the final instruction.
Definition fcml_assembler.h:98
Assembler runtime configuration.
Definition fcml_assembler.h:48
fcml_fnp_asm_optimizer optimizer
The optimizer implementation that should be used by the assembler.
Definition fcml_assembler.h:70
fcml_bool choose_sib_encoding
If there are SIB and "ModR/M only" encodings available, choose the SIB based one.
Definition fcml_assembler.h:57
fcml_bool force_rex_prefix
Sometimes REX prefix is useless so it is just omitted in the final machine code.
Definition fcml_assembler.h:64
fcml_bool force_three_byte_VEX
Every 2-byte VEX/XOP prefix can be encoded using three byte form.
Definition fcml_assembler.h:67
fcml_fnp_asm_instruction_chooser chooser
The instruction chooser implementation that should be used by the assembler to choose the most approp...
Definition fcml_assembler.h:78
fcml_bool increment_ip
Set to true in order to force assembler to increment IP address by length of the assembled instructio...
Definition fcml_assembler.h:51
fcml_bool enable_error_messages
True if optional error and warning messages should be collected during processing.
Definition fcml_assembler.h:54
fcml_uint16_t optimizer_flags
This field is passed to the chosen optimizer.
Definition fcml_assembler.h:73
fcml_bool choose_abs_encoding
If memory address can be encoded as relative or absolute value choose the absolute addressing.
Definition fcml_assembler.h:60
Representation of the assembler runtime context.
Definition fcml_assembler.h:117
fcml_st_entry_point entry_point
Instruction entry point configuration.
Definition fcml_assembler.h:123
fcml_st_assembler * assembler
The assembler instance that should be used to assemble instructions.
Definition fcml_assembler.h:119
fcml_st_assembler_conf configuration
Assembler behavior can be configured here.
Definition fcml_assembler.h:121
This structure represents the assembler result.
Definition fcml_assembler.h:105
fcml_st_assembled_instruction * chosen_instruction
Instruction chosen by the used instruction chooser.
Definition fcml_assembler.h:111
fcml_st_ceh_error_container errors
Error and warning messages generated by the assembler.
Definition fcml_assembler.h:107
fcml_usize number_of_instructions
Number of encoded instruction forms.
Definition fcml_assembler.h:113
fcml_st_assembled_instruction * instructions
Chain of assembled instructions.
Definition fcml_assembler.h:109
Container for all collected errors and warnings.
Definition fcml_errors.h:180
Describes the execution context for the instruction being assembled.
Definition fcml_common.h:838
Represents an instruction as a generic model.
Definition fcml_common.h:781