| 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 |
|
| 20 |
/** @file fcml_choosers.h |
| 21 |
* |
| 22 |
* API for instruction choosers. |
| 23 |
* |
| 24 |
* @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. |
| 25 |
* This project is released under the GNU Lesser General Public License. |
| 26 |
*/ |
| 27 |
|
| 28 |
#ifndef FCML_CHOOSER_H_ |
| 29 |
#define FCML_CHOOSER_H_ |
| 30 |
|
| 31 |
#include "fcml_lib_export.h" |
| 32 |
|
| 33 |
#include "fcml_types.h" |
| 34 |
#include "fcml_common.h" |
| 35 |
|
| 36 |
#ifdef __cplusplus |
| 37 |
extern "C" { |
| 38 |
#endif |
| 39 |
|
| 40 |
/** Returns next instructions from the iterator. |
| 41 |
* Instruction chooser uses this function to get next instruction from the chain. |
| 42 |
* @param instruction Current instruction. |
| 43 |
*/ |
| 44 |
typedef fcml_ptr (*fcml_fnp_chooser_next)(fcml_ptr instruction); |
| 45 |
|
| 46 |
/** Gets instruction code from current abstract instruction pointer. |
| 47 |
* Gets instruction pointer and fills given instruction code |
| 48 |
* holder with the binary code of the instruction. |
| 49 |
* @param instruction Instruction pointer. |
| 50 |
* @param instruction_code Holder for the instruction code. |
| 51 |
*/ |
| 52 |
typedef void (*fcml_fnp_chooser_extract)(fcml_ptr instruction, |
| 53 |
fcml_st_instruction_code *instruction_code); |
| 54 |
|
| 55 |
/** Instruction chooser context used to communicate with environment. */ |
| 56 |
typedef struct fcml_st_chooser_context { |
| 57 |
/** First instruction in the chain. */ |
| 58 |
fcml_ptr instruction; |
| 59 |
/** Gets next instruction code from iterator. */ |
| 60 |
fcml_fnp_chooser_next next; |
| 61 |
/** Extracts instruction code from the opaque instruction pointer.*/ |
| 62 |
fcml_fnp_chooser_extract extract; |
| 63 |
} fcml_st_chooser_context; |
| 64 |
|
| 65 |
/** Instruction chooser function pointer declaration. |
| 66 |
* @param chooser_context Instruction chooser context. |
| 67 |
*/ |
| 68 |
typedef fcml_ptr (LIB_CALL *fcml_fnp_asm_instruction_chooser)( |
| 69 |
fcml_st_chooser_context *chooser_context); |
| 70 |
|
| 71 |
/** Default instruction chooser which chooses the shortest instruction available. |
| 72 |
* @param chooser_context Instruction chooser context. |
| 73 |
*/ |
| 74 |
fcml_ptr LIB_EXPORT LIB_CALL fcml_fn_asm_default_instruction_chooser( |
| 75 |
fcml_st_chooser_context *chooser_context); |
| 76 |
|
| 77 |
/** NULL chooser which do not chose anything. |
| 78 |
* @param chooser_context Instruction chooser context. |
| 79 |
*/ |
| 80 |
fcml_ptr LIB_EXPORT LIB_CALL fcml_fn_asm_no_instruction_chooser( |
| 81 |
fcml_st_chooser_context *chooser_context); |
| 82 |
|
| 83 |
#ifdef __cplusplus |
| 84 |
} |
| 85 |
#endif |
| 86 |
|
| 87 |
#endif /* FCML_CHOOSER_H_ */ |