Added be arch reflection/backend support infrastructure.
[libfirm] / ir / be / bearch.h
1
2 #ifndef _FIRM_BEARCH_H
3 #define _FIRM_BEARCH_H
4
5 #include "bitset.h"
6
7 /*
8  * Define the types of the arch facility.
9  * All arch object names are stored in bearch_obj.def
10  */
11 #define ARCH_OBJ(x,list) typedef struct _arch_ ## x ## _t arch_ ## x ## _t;
12 #include "bearch_obj.def"
13 #undef ARCH_OBJ
14
15 /**
16  * A callback to determine the set of valid registers.
17  *
18  * @param irn                           The node which represents an instance of the instruction.
19  * @param pos                           The number of the insn's operand to consider.
20  * @param valid_regs    A bitset where all valid registers are put.
21  */
22 typedef void (arch_register_callback_t)(ir_node *irn, int pos, bitset_t *valid_regs);
23
24
25 /**
26  * Add a new instruction set architecture.
27  * @param name The name of the isa.
28  * @return The isa object.
29  */
30 arch_isa_t *arch_add_isa(const char *name);
31
32 /**
33  * Add a register class to the isa.
34  * @param isa The isa to add the reg class to.
35  * @param name The name of the register class.
36  * @param n_regs The number of registers in that class.
37  * @param mode The mode of the registers in that class.
38  */
39 arch_register_class_t *arch_add_register_class(arch_isa_t *isa, const char *name, int n_regs);
40
41 /**
42  * Add a register to a register class.
43  * @param cls The register class.
44  * @param index The index of the register (its number within the
45  * class).
46  * @param name The name of the register.
47  * @return The register.
48  */
49 arch_register_t *arch_add_register(arch_register_class_t *cls, int index, const char *name);
50
51 /**
52  * Add an immediate to the instruction set architecture.
53  * @param isa The isa.
54  * @param name The name of the immediate.
55  * @param mode The mode of the immediate.
56  * @return The immediate.
57  */
58 arch_immediate_t *arch_add_immediate(arch_isa_t *isa, const char *name, ir_mode *mode);
59
60 /**
61  * Add an instruction format to an isa.
62  * @param isa The isa.
63  * @param name The name of the instruction format.
64  * @param n_in The number of in operands.
65  * @param n_out The number of out operands.
66  * @return The format.
67  */
68 arch_insn_format_t *arch_add_insn_format(arch_isa_t *isa, const char *name, int n_in, int n_out);
69
70 /**
71  * Add a register set as an operand type.
72  * @param fmt The instruction format whose operand is to be set.
73  * @param pos The position of the operand. Note that input operands are
74  * numbered from 0 to n and output operands from -1 to -m.
75  * @param set The register set.
76  * @return The corresponding operand type.
77  */
78 arch_operand_t *arch_add_operand_register_set(arch_insn_format_t *fmt,
79                 int pos, const arch_register_set_t *set);
80
81 arch_operand_t *arch_add_operand_callback(arch_insn_format_t *fmt,
82                 int pos, arch_register_callback_t *cb);
83
84 arch_operand_t *arch_add_operand_immediate(arch_insn_format_t *fmt,
85                 int pos, const arch_immediate_t *imm);
86
87 /**
88  * Add an instruction to the isa.
89  * @param fmt The instructon format.
90  * @param name The name of the instruction.
91  */
92 arch_insn_t *arch_add_insn(arch_insn_format_t *fmt, const char *name);
93
94
95 /**
96  * Find an instruction format.
97  * @param isa The isa.
98  * @param name The name of the instruction format.
99  * @return The instruction format, if it was added before, or NULL if it
100  * is unknown.
101  */
102 arch_insn_format_t *arch_find_insn_format(arch_isa_t *isa, const char *name);
103
104 /**
105  * Find an isa.
106  * @param name The name of the isa.
107  * @return The isa if it has been added, or NULl if it is unknwon.
108  */
109 arch_isa_t *arch_find_isa(const char *name);
110
111 /**
112  * Find a register class of an isa.
113  * @param isa The isa.
114  * @param name The name of the register class.
115  * @return The register class, if it has been added, NULL if it is
116  * unknown.
117  */
118 arch_register_class_t *arch_find_register_class(arch_isa_t *isa, const char *name);
119
120 /**
121  * Get the register set for a register class.
122  * Each register class possesses a set containing all registers known in
123  * the class.
124  * @param cls The class.
125  * @return The register set for the register class.
126  */
127 arch_register_set_t *arch_get_register_set_for_class(arch_register_class_t *cls);
128
129
130 #endif