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