4 * @author Sebastian Hack
5 * @brief Reflection for Firm operations.
10 #ifndef _FIRM_REFLECT_H
11 #define _FIRM_REFLECT_H
18 #define RFLCT_MC(m) rflct_ms_ ## m
30 RFLCT_MC(Cf) = RFLCT_MC(X) | RFLCT_MC(BB),
32 RFLCT_MC(Int) = RFLCT_MC(IntS) | RFLCT_MC(IntU),
33 RFLCT_MC(Intb) = RFLCT_MC(Int) | RFLCT_MC(Bool),
34 RFLCT_MC(Num) = RFLCT_MC(Int) | RFLCT_MC(Float),
35 RFLCT_MC(NumP) = RFLCT_MC(Num) | RFLCT_MC(Ref),
36 RFLCT_MC(Data) = RFLCT_MC(NumP) | RFLCT_MC(Char),
37 RFLCT_MC(Datab) = RFLCT_MC(Data) | RFLCT_MC(Bool),
38 RFLCT_MC(DataM) = RFLCT_MC(Data) | RFLCT_MC(Mem),
39 RFLCT_MC(DataMX) = RFLCT_MC(Data) | RFLCT_MC(Mem) | RFLCT_MC(X),
40 RFLCT_MC(Lh) = RFLCT_MC(Mem) | RFLCT_MC(BB),
46 typedef struct _rflct_arg_t {
47 const char *name; /**< The name of the argument (just a description). */
49 int is_variadic; /**< non-zero, if this argument can have multiple parameters. */
50 rflct_mode_class_t accepted_modes; /**< The set of accepted modes. */
52 int mode_equals; /**< If not variadic: You can specify the index of
53 another argument meaning, that the mode of the
54 operand binding at this argument must be the same
55 as the mode of the operand binding to the argument
56 at index. If you don't want to express such a
57 dependency, just give -1 here.
59 If variadic: If true, the modes of all
60 variadic operands binding to this argument
61 must be the same. If false, they can differ. */
64 typedef struct _rflct_sig_t {
65 int defs; /**< The number of defined arguments in the signature. */
66 int uses; /**< The number of used arguments in the signature. */
68 rflct_arg_t *args; /**< The arguments array. */
71 #define RFLCT_ARG_IS_A(arg,modes) (((arg)->accepted_modes & modes) != 0)
72 #define RFLCT_ARG_VALID(arg) ((arg)->name != NULL)
73 #define RFLCT_SIG_VALID(sig) ((sig) != INT_MAX)
76 * Get the mode class for an IR mode.
77 * @param mode An IR mode.
78 * @return The corresponding smallest reflection mode class.
80 rflct_mode_class_t rflct_get_mode_class(const ir_mode *mode);
83 * Get the number of signatures for a Firm opcode.
84 * @param opc The opcode.
85 * @return The number of signatures for this opcode.
87 int rflct_get_signature_count(opcode opc);
90 * Try to get the signature, that matches to a given instance
92 * @param irn The node.
93 * @return The first matching signature or -1, if no signature matches.
95 int rflct_get_signature(const ir_node *irn);
98 * Get the number of in arguments.
99 * An in argument is a use of a value.
100 * @param opc The opcode.
101 * @param sig The signature you are refering to.
102 * @return The number of arguments.
104 int rflct_get_in_args_count(opcode opc, int sig);
107 * Get the number of out arguments.
108 * An out argument is a def of a value.
109 * @param opc The opcode.
110 * @param sig The signature you are refering to.
111 * @return The number of arguments.
113 int rflct_get_out_args_count(opcode opc, int sig);
115 #define rflct_get_args_count(opc, sig, use) \
116 ((use) ? rflct_get_in_args_count(opc, sig) : rflct_get_out_args_count(opc, sig))
119 * Get the array of use args.
120 * The array is terminated with an entry for which
121 * <code>RFLCT_ARG_VALID</code> is 0.
122 * @param opc The opcode.
123 * @param sig The signature you are referring to (Must be between
124 * 0 and the signature count).
127 const rflct_arg_t *rflct_get_in_args(opcode opc, int sig);
130 * Get the array of def args.
131 * The array is terminated with an entry for which
132 * <code>RFLCT_ARG_VALID</code> is 0.
133 * @param opc The opcode.
134 * @param sig The signature you are referring to (Must be between
135 * 0 and the signature count).
138 const rflct_arg_t *rflct_get_out_args(opcode opc, int sig);
140 #define rflct_get_args(opc, sig, use) \
141 ((use) ? rflct_get_in_args(opc, sig) : rflct_get_out_args(opc, sig))
144 * Make a string representation of a signature of an opcode.
145 * @param buf The buffer to put the string to.
146 * @param n The size of buf.
147 * @param opc The opcode.
148 * @param sig The signature.
151 char *rflct_to_string(char *buf, int n, opcode opc, int sig);
154 * Get a string representation of a mode class.
155 * @param str The buffer to put the string to.
156 * @param n The size of the buffer.
157 * @param mc The mode class.
160 char *rflct_mode_class_name(char *str, int n, rflct_mode_class_t mc);
163 * Create a new opcode.
164 * @param opc The Firm opcode.
165 * @param name A name.
166 * @param commutative non-zero, if the opcode is commutative.
168 void rflct_new_opcode(opcode opc, const char *name, int commutative);
171 * Add a signature to the opcode.
172 * @param opc The opcode.
173 * @param sig The signature.
174 * @return non-zero, if the signature was added successfully, false if no
175 * more signatures can be added to the opcode.
177 int rflct_opcode_add_signature(opcode opc, rflct_sig_t *sig);
180 * Allocate a new signature.
181 * @param defs Number of def arguments.
182 * @param uses Number of use arguments.
183 * @return An allocated signature.
185 rflct_sig_t *rflct_signature_allocate(int defs, int uses);
188 * Set an argument in a signature.
190 * @param sig The signature.
191 * @param is_use non-zero, if the argument is a use, else it is
193 * @param num The index of the argument.
194 * @param name The name of the argument.
195 * @param mc The mode class of the argument.
196 * @param is_variadic non-zero, if the argument is variadic.
197 * @param mode_equals This variable has following meaning: If the
198 * argument is variadic, a 1 indicates that all operands binding to this
199 * argument must have the same mode. A 0 indicates, that their mode must
200 * be of the specified mode class but can differ. If the argument is non
201 * variadic, a positive number indicates, that the mode of the operand
202 * binding to this argument must be the same as the one binding to
203 * argument indexed by mode_equals. If the mode should not be dependent
204 * to another mode, set -1 here.
205 * @return The index of the argument. Only use this index in mode_equals
206 * parameters of other arguments.
208 int rflct_signature_set_arg(rflct_sig_t *sig, int is_use, int num,
209 const char *name, rflct_mode_class_t mc, int is_variadic, int mode_equals);
212 * Get the arguments array index for an argument.
213 * @param sig The signature.
214 * @param is_use non-zero, if the argument indicates a use or def argument.
215 * @param num The number of the argument.
216 * @return The index into the arguments array.
218 int rflct_signature_get_index(const rflct_sig_t *sig, int is_use, int num);
221 #endif /* _FIRM_REFLECT_H */