Debian Codegraph @

src/fcml_encoding.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_ENCODING_H_
21 #define FCML_ASM_ENCODING_H_
22
23 #include "fcml_assembler.h"
24 #include "fcml_ceh.h"
25 #include "fcml_coll.h"
26 #include "fcml_common.h"
27 #include "fcml_dialect_int.h"
28 #include "fcml_types.h"
29
30 /**
31 * Holds the result of instruction encoding.
32 * The result consists of all assembled instructions and the one chosen
33 * as the one expected by the caller.
34 */
35 typedef struct fcml_st_asm_encoder_result {
36 /** Potential encoding errors end up here. */
37 fcml_st_ceh_error_container errors;
38 /** All possible assembled instructions goes here. */
39 fcml_st_assembled_instruction *instructions;
40 /** The instruction that most likely is the expected one goes here. */
41 fcml_st_assembled_instruction *chosen_instruction;
42 /** Number of instructions assembled by the encoder. */
43 fcml_usize number_of_instructions;
44 } fcml_st_asm_encoder_result;
45
46 struct fcml_st_instruction_addr_modes;
47
48 /** Instruction encoders have to be compatible with this pointer. */
49 typedef fcml_ceh_error (*fcml_fp_instruction_encoder)(
50 fcml_st_assembler_context*, fcml_st_dialect_context_int*,
51 struct fcml_st_instruction_addr_modes*, fcml_st_instruction*,
52 fcml_st_asm_encoder_result*);
53
54 /** Supported addressing modes of one particular instruction.
55 * Most of the instructions support more than one addressing mode.
56 * Every addressing mode is described by a dedicated model which is
57 * then interpreted by the encoder during assembling process.
58 */
59 typedef struct fcml_st_instruction_addr_modes {
60 /* All addressing modes for given mnemonic are available in this list. */
61 fcml_st_coll_list *addr_modes_encodings;
62 /* An instruction mnemonic shared by all the addressing modes. */
63 const fcml_string mnemonic;
64 /* Predefined instruction encoder responsible for encoding the instruction. */
65 fcml_fp_instruction_encoder encoder;
66 } fcml_st_instruction_addr_modes;
67
68 /** Prepares static instruction address modes map. */
69 fcml_ceh_error fcml_fn_init_instructions_addr_modes(
70 fcml_st_dialect_context_int *context,
71 fcml_coll_map *instructions_map);
72
73 /** Gets addressing modes for given mnemonic. */
74 fcml_ceh_error fcml_fn_get_instruction_addr_modes(
75 fcml_coll_map instructions_map,
76 fcml_string mnemonic,
77 fcml_st_instruction_addr_modes **);
78
79 /** Frees all the addressing modes. */
80 void fcml_fn_free_instructions_addr_modes(fcml_coll_map instructions_map);
81
82 #endif /* FCML_ASM_ENCODING_H_ */