Debian Codegraph @

src/fcml_dialect_int.h

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 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 #ifndef FCML_ASM_DIALECT_INT_H_
21 #define FCML_ASM_DIALECT_INT_H_
22
23 #include <fcml_dialect.h>
24 #include <fcml_common.h>
25 #include <fcml_parser.h>
26 #include <fcml_renderer.h>
27 #include <fcml_assembler.h>
28 #include <fcml_disassembler.h>
29
30 #include "fcml_parser_int.h"
31 #include "fcml_def.h"
32 #include "fcml_stream.h"
33 #include "fcml_mnemonic_parser.h"
34
35 #define FCML_ASM_DIALECT_MAX_MNEMONIC_COUNT 50
36
37 #define FCML_ASM_DIALECT_INSTRUCTION(x,y) (((x) << 16) | (y))
38 #define FCML_ASM_DIALECT_GET_INSTRUCTION(x) ((x) >> 16)
39 #define FCML_ASM_DIALECT_GET_ADDR_MODE(x) ((x) & 0x0000FFFF)
40
41 typedef struct fcml_st_dialect_mnemonic {
42 fcml_string mnemonic;
43 fcml_uint32_t instruction;
44 fcml_uint32_t flags;
45 } fcml_st_dialect_mnemonic;
46
47 typedef struct fcml_st_dialect_pseudo_op_mnemonic {
48 fcml_string mnemonic;
49 fcml_en_pseudo_operations pseudo_operation;
50 } fcml_st_dialect_pseudo_op_mnemonic;
51
52 typedef void (*fcml_fnp_free_mnemonic)(fcml_st_mp_mnemonic *mnemonics);
53
54 /* Returns all mnemonics registered for given instruction. */
55 typedef fcml_ceh_error (*fcml_fnp_get_mnemonic)(const fcml_st_dialect *dialect,
56 const fcml_st_def_instruction_desc *instruction,
57 const fcml_st_def_addr_mode_desc *addr_mode,
58 const fcml_st_condition *condition, fcml_st_mp_mnemonic **mnemonics,
59 int *mnemonic_counter);
60
61 typedef fcml_ceh_error (*fcml_fnp_get_parsed_mnemonics)(
62 const fcml_st_dialect *dialect,
63 const fcml_st_def_instruction_desc *instruction,
64 const fcml_st_def_addr_mode_desc *addr_mode,
65 fcml_st_mp_mnemonic_set **mnemonics);
66
67 typedef fcml_string (*fcml_fnp_render_mnemonic)(
68 fcml_string mnemonic, fcml_st_condition *condition,
69 fcml_uint8_t conditional_group, fcml_bool show_carry);
70
71 typedef fcml_string (*fcml_fnp_get_pseudo_operation_mnemonic)(
72 fcml_en_pseudo_operations pseudo_operation);
73
74 typedef fcml_ceh_error (*fcml_fnp_get_register)(const fcml_st_register *reg,
75 fcml_string buffer, fcml_int buffer_length, fcml_bool is_rex);
76
77 typedef fcml_ceh_error (*fcml_fnp_asm_preprocessor)(const fcml_st_dialect*,
78 const fcml_st_def_addr_mode_desc*, const fcml_st_mp_mnemonic*,
79 fcml_en_instruction, fcml_st_instruction*, fcml_bool *inst_changed);
80
81 typedef fcml_ceh_error (*fcml_fnp_disasm_postprocessor)(
82 const fcml_st_mp_mnemonic*, fcml_st_disassembler_result*);
83
84 typedef fcml_ceh_error (*fcml_fnp_parse_instruction)(fcml_ip ip,
85 const fcml_string asm_mnemonic, fcml_st_parser_ast *ast);
86
87 typedef fcml_ceh_error (*fcml_fnp_render_instruction)(
88 const fcml_st_dialect *dialect, const fcml_st_render_config *config,
89 fcml_st_memory_stream *output_stream,
90 const fcml_st_disassembler_result *result);
91
92 typedef fcml_st_dialect_pseudo_op_mnemonic* (*fcml_fnp_get_pseudo_operation_mnemonics)();
93
94 typedef void (*fcml_fnp_dialect_free)(fcml_st_dialect *dialect);
95
96 /* Internal representation of dialect context.*/
97 typedef struct fcml_st_dialect_context_int {
98 fcml_coll_map dialect_mnemonics_lookup;
99 /**
100 * Gets mnemonics for given instruction addressing mode.
101 */
102 fcml_fnp_get_mnemonic get_mnemonic;
103 /**
104 * Gets mnemonics for pseudo operation.
105 */
106 fcml_fnp_get_pseudo_operation_mnemonics get_pseudo_op_mnemonics;
107 fcml_fnp_get_parsed_mnemonics get_parsed_mnemonics;
108 fcml_fnp_get_pseudo_operation_mnemonic get_pseudo_op_mnemonic;
109 /**
110 * Used to free mnemonics when assembler is disposed. Some dialect may
111 * use static mnemonic while other may generate them like AT&Tdialect
112 * does. This function givens a way to free them in a proper way.
113 */
114 fcml_fnp_free_mnemonic free_mnemonic;
115 fcml_fnp_render_mnemonic render_mnemonic;
116 fcml_fnp_get_register get_register;
117 fcml_fnp_asm_preprocessor asm_preprocessor;
118 fcml_fnp_disasm_postprocessor disasm_postprocessor;
119 fcml_fnp_dialect_free free_dialect;
120 fcml_fnp_render_instruction instruction_renderer;
121 fcml_fnp_parse_instruction instruction_parser;
122 fcml_uint32_t config_flags;
123 } fcml_st_dialect_context_int;
124
125 fcml_st_mp_mnemonic* fcml_fn_asm_dialect_alloc_mnemonic_with_suffix(
126 fcml_st_mp_mnemonic *mnemonic, fcml_string suffix);
127
128 fcml_st_mp_mnemonic* fcml_fn_asm_dialect_alloc_mnemonic(
129 fcml_st_mp_mnemonic *mnemonic);
130
131 void fcml_fn_asm_dialect_free_mnemonic(fcml_st_mp_mnemonic *mnemonic);
132
133 fcml_ceh_error fcml_fn_asm_dialect_alloc_mnemonic_lookup(
134 fcml_st_dialect_context_int **dialect_context,
135 fcml_st_dialect_mnemonic *mnemonic, fcml_usize capacity);
136
137 void fcml_fn_asm_dialect_free_mnemonic_lookup(
138 fcml_st_dialect_context_int *dialect_context);
139
140 #endif /* FCML_ASM_DIALECT_INT_H_ */