More doxygen docu
[libfirm] / ir / ir / irmode.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2  * All rights reserved.
3  */
4 /* $Id$ */
5
6 /**
7  * @file irmode.h
8  *    irmode -- Modes for ir operators
9  *
10  * @author Christian Schaefer, Matthias Heil
11  *
12  * This module specifies the modes that type the firm nodes.  It defines
13  * a datasturcture that describes a mode and implements constructors and
14  * access routines to this datastructure. Further it defines a set of
15  * predefined modes.
16  *
17  * SEE ALSO:
18  *    UKA tech report 1999-44 for more information about modes.
19  *
20  */
21 #ifndef _IRMODE_H_
22 #define _IRMODE_H_
23
24 #include "ident.h"
25
26 #ifndef _TARVAL_TYPEDEF_
27 #define _TARVAL_TYPEDEF_
28   typedef struct tarval tarval;
29 #endif
30
31 /**
32  * Contains relevant information about a mode.
33  *
34  * Neccessary information about a mode is stored in this struct
35  * which is used by the tarval module to perform calculations
36  * and comparisons of values of a such described mode.
37  *
38  * ATTRIBUTES:
39  *  -  modecode code:           An unambigous int (enum) for the mode
40  *  -  ident *name:             Name of this mode. Two modes are different if the name is different.
41  *  -  mode_sort sort:          sort of mode specifying possible usage kategories
42  *  -  int    size:             size of the mode in Bits.
43  *  -  int    align:            byte alignment
44  *  -  unsigned sign:1:         signedness of this mode
45  *  -  ... more to come
46  *
47  * SEE ALSO:
48  *    The tech report 1999-44 describing FIRM and predefined modes
49  *    tarval.h
50  */
51 typedef struct ir_mode ir_mode;
52
53 /* ********** Predefined modes ********** */
54
55 /**
56  * Predefined mode according to tech report 1999-14.
57  */
58 typedef enum { /* irm is short for `ir mode' */
59   irm_BB,                       /**< basic block */
60   irm_X,                        /**< execution */
61   irm_F,                        /**< float(32) */
62   irm_D,                        /**< double(64) */
63   irm_E,                        /**< extended(80) */
64   irm_Bs,                       /**< signed byte(8) */
65   irm_Bu,                       /**< unsigned byte(8) */
66   irm_Hs,                       /**< signed short(16) */
67   irm_Hu,                       /**< unsigned short(16) */
68   irm_Is,                       /**< signed int(32) */
69   irm_Iu,                       /**< unsigned int(32) */
70   irm_Ls,                       /**< signed long(64) */
71   irm_Lu,                       /**< unsigned long(64) */
72   irm_C,                        /**< character */
73   irm_P,                        /**< pointer */
74   irm_b,                        /**< internal boolean */
75   irm_M,                        /**< memory */
76   irm_T,                        /**< tuple */
77   irm_U,                        /**< unicode character */
78   irm_max                       /**< maximum value for modecode */
79 } modecode;
80
81 /** These values represent the different mode classes of value representations.
82  */
83 typedef enum {
84   /* Predefined sorts of modes */
85   irms_auxiliary,         /**< Only for Firm use, predefined. (irm_BB, irm_X, irm_T, irm_M) */
86   irms_internal_boolean,  /**< Internal boolean representation.
87                                Storing to memory impossible, convert first. */
88   /** user-extensible sorts of modes **/
89   irms_int_number,        /**< A mode to represent int numbers.
90                                Integer computations can be performed. */
91   irms_float_number,      /**< A mode to represent float numbers.
92                                Floating point computations can be performed. */
93   irms_reference,         /**< A mode to represent entities.
94                                Restricted int computations can be performed */
95   irms_character          /**< A mode to represent characters/symbols
96                                ?? Are computations allowed? as int?? */
97 } mode_sort;
98
99 /** These values represent the different arithmetic operations possible with a mode.
100     Further arithmetics can be defined, e.g., for @@@ modes.
101  */
102 typedef enum {
103   irma_uninitialized = 0,
104   irma_none = 1,              /**< For modes for which no representation is specified.
105                                    These are modes of sort auxiliary, internal_boolean and
106                                    character. */
107   irma_twos_complement = 2,   /**< Values of the mode are represented as two's complement.
108                                    Only legal for modes of sort int_number and reference. */
109   irma_ones_complement,       /**< Values of the mode are represented  as one's complement.
110                                    Only legal for modes of sort int_number and reference. */
111   irma_int_BCD,               /**< Values of the mode are represented as binary coded decimals.
112                                    Only legal for modes of sort int_number and reference. */
113   irma_ieee754 = 256,         /**< Values of the mode are represented according to ieee754
114                                    floatingpoint standard.  Only legal for modes of sort float_number. */
115   irma_float_BCD,             /**< Values of the mode are represented  as binary coded decimals
116                                    according to @@@ which standars??? Only legal for modes of
117                                    sort float_number. */
118   irma_max
119 } mode_arithmetic;
120
121
122 /* ********** Constructor for user defined modes **************** */
123 /**
124  * Creates a new mode.
125  *
126  * @param name          the name of the mode to be created
127  * @param sort          the mode_sort of the mode to be created
128  * @param bit_size      number of bits this mode allocate
129  * @param align         the byte alignment for an entity of this mode (in bits)
130  * @param sign          non-zero if this is a signed mode
131  *
132  * This function constructs a new mode given by the parameters.
133  * If the parameters match an already defined mode, this mode is returned
134  * (including the default modes).
135  * If the mode is newly allocated, a new unique mode_code is choosen.
136  * Also, special value tarvals will be calculated such as null,
137  * min, max and can be retrieved using the get_mode_* fuctions
138  *
139  * @return
140  *      The new mode or NULL on error.
141  *
142  * @note
143  *      It is allowed to construct the default modes. So, a call
144  *      new_ir_mode("Is", irms_int_number, 32, 4, 1) will return mode_Is.
145  */
146 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int align, int sign);
147
148 /* ********** Access methods to read mode information *********** */
149
150 /** Returns the classification of the mode */
151 modecode get_mode_modecode(ir_mode *mode);
152
153 /** Returns the ident* of the mode */
154 ident *get_mode_ident(ir_mode *mode);
155
156 /** Returns the null-terminated name of this mode. */
157 const char *get_mode_name(ir_mode *mode);
158
159 /** Returns a coarse classification of the mode. */
160 mode_sort get_mode_sort(ir_mode *mode);
161
162 /** Returns the size of values of the mode in bits. */
163 int get_mode_size_bits(ir_mode *mode);
164
165 /** Returns the size of values of the mode in bytes.  If the size is not
166     dividable by 8 returns -1. */
167 int get_mode_size_bytes(ir_mode *mode);
168
169 /** Returns the alignment of values of the mode in bytes. */
170 int get_mode_align(ir_mode *mode);
171
172 /** Returns the signess of a mode */
173 int get_mode_sign (ir_mode *mode);
174
175 /**
176  * Returns the smallest representable value of a given mode.
177  *
178  * For modes of the sort float_number this is the most negative value
179  * bigger than -infinit.
180  */
181 tarval *get_mode_min(ir_mode *mode);
182
183 /**
184  * Returns the biggest representable value o f a given mode.
185  *
186  * For modes of the sort float_number this is the largest value lower
187  * than infinit.
188  */
189 tarval *get_mode_max(ir_mode *mode);
190
191 /**
192  * Returns the value Zero represented in this mode.
193  *
194  * Zero is the additive neutral element and as such
195  * is defined only for modes allowing addition, i.e.
196  * floats and ints, and references (NULL-Pointer)
197  * else returns tarval_bad.
198  */
199 tarval *get_mode_null(ir_mode *mode);
200
201 /**
202  * Returns the value One, represented in this mode.
203  *
204  * One, being the multiplicative neutral element,
205  * is defined only for modes allowing multiplication,
206  * i.e. ints and floats.
207  */
208 tarval *get_mode_one(ir_mode *mode);
209
210 /**
211  * Returns the positive infinite value of a mode.
212  *
213  * This is only valid for float_numbers, other modes
214  * will result in tarval_bad.
215  */
216 tarval *get_mode_infinite(ir_mode *mode);
217
218 /**
219  * Returns the NAN value of a given mode.
220  *
221  * This is only valid for float_numbers, other modes
222  * will result in tarval_bad.
223  */
224 tarval *get_mode_NAN(ir_mode *mode);
225
226 /* -- Auxiliary modes necessary for the Firm representation -- */
227 extern ir_mode *mode_T;  /**< tuple (none) */
228 extern ir_mode *mode_X;  /**< execution */
229 extern ir_mode *mode_M;  /**< memory */
230 extern ir_mode *mode_BB; /**< block */
231
232 /* -- A set of predifined, numerical modes according to Techreport 1999-44 -- */
233 extern ir_mode *mode_F;  /**< signed float(32) */
234 extern ir_mode *mode_D;  /**< signed double(64) */
235 extern ir_mode *mode_E;  /**< signed extended(80) */
236 extern ir_mode *mode_Bs; /**< signed byte (former char) */
237 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
238 extern ir_mode *mode_Hs; /**< signed short integer */
239 extern ir_mode *mode_Hu; /**< unsigened short integer */
240 extern ir_mode *mode_Is; /**< signed integer */
241 extern ir_mode *mode_Iu; /**< unsigned integer */
242 extern ir_mode *mode_Ls; /**< signed long integer */
243 extern ir_mode *mode_Lu; /**< unsigned long integer */
244
245 extern ir_mode *mode_b;  /**< internal boolean */
246 extern ir_mode *mode_C;  /**< 8 bit char */
247 extern ir_mode *mode_U;  /**< 16 bit unicode char */
248 extern ir_mode *mode_P;  /**< pointer */
249
250 /*@{*/
251 /** Access routines for JNI Interface */
252 ir_mode *get_modeT(void);
253 ir_mode *get_modeF(void);
254 ir_mode *get_modeD(void);
255 ir_mode *get_modeE(void);
256 ir_mode *get_modeBs(void);
257 ir_mode *get_modeBu(void);
258 ir_mode *get_modeHs(void);
259 ir_mode *get_modeHu(void);
260 ir_mode *get_modeIs(void);
261 ir_mode *get_modeIu(void);
262 ir_mode *get_modeLs(void);
263 ir_mode *get_modeLu(void);
264 ir_mode *get_modeC(void);
265 ir_mode *get_modeU(void);
266 ir_mode *get_modeP(void);
267 ir_mode *get_modeb(void);
268 ir_mode *get_modeX(void);
269 ir_mode *get_modeM(void);
270 ir_mode *get_modeBB(void);
271
272 /**
273    Functions to check, whether a modecode is signed, float, int, num, data,
274    datab or dataM.
275
276    For more exact definitions read the corresponding pages
277    in the firm documentation or the following enumeration
278
279    The set of "float" is defined as:
280    float = {irm_F, irm_D, irm_E}
281
282    The set of "int" is defined as:
283    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
284
285    The set of "num" is defined as:
286    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
287             irm_Is, irm_Iu, irm_Ls, irm_Lu}
288             = {float || int}
289
290    The set of "data" is defined as:
291    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
292             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
293             = {num || irm_C || irm_P}
294
295    The set of "datab" is defined as:
296    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
297             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
298             = {data || irm_b }
299
300    The set of "dataM" is defined as:
301    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
302             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
303             = {data || irm_M}
304 */
305 /*@}*/
306 /* Test for a certain class of modes. */
307 int mode_is_signed (ir_mode *mode);
308 int mode_is_float (ir_mode *mode);
309 int mode_is_int (ir_mode *mode);
310 int mode_is_character (ir_mode *mode);
311 int mode_is_reference (ir_mode *mode);
312 int mode_is_num (ir_mode *mode);
313 int mode_is_data (ir_mode *mode);
314 int mode_is_datab (ir_mode *mode);
315 int mode_is_dataM (ir_mode *mode);
316 /** Returns true if sm can be converted to lm without loss
317    according to firm definiton */
318 int smaller_mode(ir_mode *sm, ir_mode *lm);
319
320 /** mode module initialization, call once before use of any other function **/
321 void init_mode (void);
322
323 #endif /* _IRMODE_H_ */