get_divop_resmod() added
[libfirm] / ir / ir / irreflect.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Reflection for Firm operations.
23  * @author  Sebastian Hack
24  * @date    9.9.2004
25  * @version $Id$
26  */
27 #ifndef FIRM_IR_REFLECT_H
28 #define FIRM_IR_REFLECT_H
29
30 #include <limits.h>
31
32 #include "firm_types.h"
33 #include "irop.h"
34
35 #define RFLCT_MC(m) rflct_ms_ ## m
36 typedef enum {
37   RFLCT_MC(None)  = 0,
38   RFLCT_MC(Mem)   = 2,
39   RFLCT_MC(Bool)  = 4,
40   RFLCT_MC(IntS)  = 8,
41   RFLCT_MC(IntU)  = 16,
42   RFLCT_MC(Float) = 32,
43   RFLCT_MC(Ref)   = 64,
44   RFLCT_MC(Char)  = 128,
45   RFLCT_MC(X)     = 256,
46   RFLCT_MC(BB)    = 512,
47   RFLCT_MC(Cf)    = RFLCT_MC(X) | RFLCT_MC(BB),
48
49   RFLCT_MC(Int) = RFLCT_MC(IntS) | RFLCT_MC(IntU),
50   RFLCT_MC(Intb) = RFLCT_MC(Int) | RFLCT_MC(Bool),
51   RFLCT_MC(Num) = RFLCT_MC(Int) | RFLCT_MC(Float),
52   RFLCT_MC(NumP) = RFLCT_MC(Num) | RFLCT_MC(Ref),
53   RFLCT_MC(Data) = RFLCT_MC(NumP) | RFLCT_MC(Char),
54   RFLCT_MC(Datab) = RFLCT_MC(Data) | RFLCT_MC(Bool),
55   RFLCT_MC(DataM) = RFLCT_MC(Data) | RFLCT_MC(Mem),
56   RFLCT_MC(DataMX) = RFLCT_MC(Data) | RFLCT_MC(Mem) | RFLCT_MC(X),
57   RFLCT_MC(Lh) = RFLCT_MC(Mem) | RFLCT_MC(BB),
58
59   RFLCT_MC(Any) = -1
60
61 } rflct_mode_class_t;
62
63 typedef struct _rflct_arg_t {
64   const char *name;  /**< The name of the argument (just a description). */
65
66   int is_variadic; /**< non-zero, if this argument can have multiple parameters. */
67   rflct_mode_class_t accepted_modes; /**< The set of accepted modes. */
68
69   int mode_equals; /**< If not variadic: You can specify the index of
70                         another argument meaning, that the mode of the
71                         operand binding at this argument must be the same
72                         as the mode of the operand binding to the argument
73                         at index. If you don't want to express such a
74                         dependency, just give -1 here.
75
76                         If variadic: If true, the modes of all
77                         variadic operands binding to this argument
78                         must be the same. If false, they can differ. */
79 } rflct_arg_t;
80
81 typedef struct _rflct_sig_t {
82         int defs; /**< The number of defined arguments in the signature. */
83         int uses; /**< The number of used arguments in the signature. */
84
85         rflct_arg_t *args; /**< The arguments array. */
86 } rflct_sig_t;
87
88 #define RFLCT_ARG_IS_A(arg,modes) (((arg)->accepted_modes & modes) != 0)
89 #define RFLCT_ARG_VALID(arg) ((arg)->name != NULL)
90 #define RFLCT_SIG_VALID(sig) ((sig) != INT_MAX)
91
92 /**
93  * Get the mode class for an IR mode.
94  * @param mode An IR mode.
95  * @return The corresponding smallest reflection mode class.
96  */
97 rflct_mode_class_t rflct_get_mode_class(const ir_mode *mode);
98
99 /**
100  * Get the number of signatures for a Firm opcode.
101  * @param opc The opcode.
102  * @return The number of signatures for this opcode.
103  */
104 int rflct_get_signature_count(ir_opcode opc);
105
106 /**
107  * Try to get the signature, that matches to a given instance
108  * of a Firm node.
109  * @param irn The node.
110  * @return The first matching signature or -1, if no signature matches.
111  */
112 int rflct_get_signature(const ir_node *irn);
113
114 /**
115  * Get the number of in arguments.
116  * An in argument is a use of a value.
117  * @param opc The opcode.
118  * @param sig The signature you are refering to.
119  * @return The number of arguments.
120  */
121 int rflct_get_in_args_count(ir_opcode opc, int sig);
122
123 /**
124  * Get the number of out arguments.
125  * An out argument is a def of a value.
126  * @param opc The opcode.
127  * @param sig The signature you are refering to.
128  * @return The number of arguments.
129  */
130 int rflct_get_out_args_count(ir_opcode opc, int sig);
131
132 #define rflct_get_args_count(opc, sig, use) \
133   ((use) ? rflct_get_in_args_count(opc, sig) : rflct_get_out_args_count(opc, sig))
134
135 /**
136  * Get the array of use args.
137  * The array is terminated with an entry for which
138  * <code>RFLCT_ARG_VALID</code> is 0.
139  * @param opc The opcode.
140  * @param sig The signature you are referring to (Must be between
141  * 0 and the signature count).
142  * @return The array.
143  */
144 const rflct_arg_t *rflct_get_in_args(ir_opcode opc, int sig);
145
146 /**
147  * Get the array of def args.
148  * The array is terminated with an entry for which
149  * <code>RFLCT_ARG_VALID</code> is 0.
150  * @param opc The opcode.
151  * @param sig The signature you are referring to (Must be between
152  * 0 and the signature count).
153  * @return The array.
154  */
155 const rflct_arg_t *rflct_get_out_args(ir_opcode opc, int sig);
156
157 #define rflct_get_args(opc, sig, use) \
158   ((use) ? rflct_get_in_args(opc, sig) : rflct_get_out_args(opc, sig))
159
160 /**
161  * Make a string representation of a signature of an opcode.
162  * @param buf The buffer to put the string to.
163  * @param n The size of buf.
164  * @param opc The opcode.
165  * @param sig The signature.
166  * @return buf.
167  */
168 char *rflct_to_string(char *buf, int n, ir_opcode opc, int sig);
169
170 /**
171  * Get a string representation of a mode class.
172  * @param str The buffer to put the string to.
173  * @param n The size of the buffer.
174  * @param mc The mode class.
175  * @return str.
176  */
177 char *rflct_mode_class_name(char *str, int n, rflct_mode_class_t mc);
178
179 /**
180  * Create a new opcode.
181  * @param opc         The Firm opcode.
182  * @param name        A name.
183  * @param commutative non-zero, if the opcode is commutative.
184  */
185 void rflct_new_opcode(ir_opcode opc, const char *name, int commutative);
186
187 /**
188  * Add a signature to the opcode.
189  * @param opc  The opcode.
190  * @param sig  The signature.
191  * @return non-zero, if the signature was added successfully, false if no
192  * more signatures can be added to the opcode.
193  */
194 int rflct_opcode_add_signature(ir_opcode opc, rflct_sig_t *sig);
195
196 /**
197  * Allocate a new signature.
198  * @param defs Number of def arguments.
199  * @param uses Number of use arguments.
200  * @return An allocated signature.
201  */
202 rflct_sig_t *rflct_signature_allocate(int defs, int uses);
203
204 /**
205  * Set an argument in a signature.
206  *
207  * @param sig         The signature.
208  * @param is_use      non-zero, if the argument is a use, else it is
209  *                    considered a def.
210  * @param num         The index of the argument.
211  * @param name        The name of the argument.
212  * @param mc          The mode class of the argument.
213  * @param is_variadic non-zero, if the argument is variadic.
214  * @param mode_equals This variable has following meaning: If the
215  * argument is variadic, a 1 indicates that all operands binding to this
216  * argument must have the same mode. A 0 indicates, that their mode must
217  * be of the specified mode class but can differ. If the argument is non
218  * variadic, a positive number indicates, that the mode of the operand
219  * binding to this argument must be the same as the one binding to
220  * argument indexed by mode_equals. If the mode should not be dependent
221  * to another mode, set -1 here.
222  * @return The index of the argument. Only use this index in mode_equals
223  * parameters of other arguments.
224  */
225 int rflct_signature_set_arg(rflct_sig_t *sig, int is_use, int num,
226                 const char *name, rflct_mode_class_t mc, int is_variadic, int mode_equals);
227
228 /**
229  * Get the arguments array index for an argument.
230  * @param sig    The signature.
231  * @param is_use non-zero, if the argument indicates a use or def argument.
232  * @param num    The number of the argument.
233  * @return The index into the arguments array.
234  */
235 int rflct_signature_get_index(const rflct_sig_t *sig, int is_use, int num);
236
237 #endif