Converted documentation to doxygen.
[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   auxiliary,         /**< Only for Firm use, predefined. */
84   internal_boolean,  /**< Internal boolean representation.
85                         Storing to memory impossible, convert first. */
86   /** user-extensible sorts of modes **/
87   int_number,        /**< A mode to represent int numbers.
88                         Integer computations can be performed. */
89   float_number,      /**< A mode to represent float numbers.
90                         Floating point computations can be performed. */
91   reference,         /**< A mode to represent entities.
92                         Restricted int computations can be performed */
93   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  * Registers a new mode.
100  * Must be called BEFORE init_mode2() !!!
101  *
102  * The information for new mode is retrieved from the mode
103  * struct passed as parameter, the code field is ignored.
104  * The struct is copied into the internal mode array and the code
105  * field will be set to a unique integer.
106  * Also, special value tarvals will be calculated such as null,
107  * min, max and can be retrieved using the get_mode_* fuctions
108  *
109  * If a mode with the given characteristics already exists,
110  * it will be returned instead of creating a new one.
111  *
112  * The passed struct can be safely deallocated after the function
113  * returns.
114  * To access the new mode the returned mode pointer must be used!
115  */
116 ir_mode *register_mode(ir_mode* new_mode);
117
118 /* ********** Access methods to read mode information *********** */
119
120 #ifdef MODE_ACCESS_DEFINES
121 #  include "irmode_t.h"
122 #  define get_mode_modecode(mode) (mode)->code
123 #  define get_mode_ident(mode) (mode)->name
124 #  define get_mode_name(mode) id_to_str((mode)->name)
125 #  define get_mode_sort(mode) (mode)->sort
126 #  define get_mode_size_bits(mode) (mode)->size
127 #  define get_mode_align(mode) (mode)->align
128 #else
129 /** Returns the classification of the mode */
130 modecode get_mode_modecode(ir_mode *mode);
131
132 /** Returns the ident* of the mode */
133 ident *get_mode_ident(ir_mode *mode);
134
135 /** Returns the null-terminated name of this mode. */
136 const char *get_mode_name(ir_mode *mode);
137
138 /** Returns a coarse classification of the mode. */
139 mode_sort get_mode_sort(ir_mode *mode);
140
141 /** Returns the size of values of the mode in bits. */
142 int get_mode_size_bits(ir_mode *mode);
143
144 /** Returns the size of values of the mode in bytes.  If the size is not
145     dividable by 8 returns -1. */
146 int get_mode_size_bytes(ir_mode *mode);
147
148 /** Returns the alignment of values of the mode in bytes. */
149 int get_mode_align(ir_mode *mode);
150 #endif
151
152 /**
153  * Returns the smallest representable value of a given mode.
154  *
155  * For modes of the sort float_number this is the most negative value
156  * bigger than -infinit.
157  */
158 tarval *get_mode_min(ir_mode *mode);
159
160 /**
161  * Returns the biggest representable value o f a given mode.
162  *
163  * For modes of the sort float_number this is the largest value lower
164  * than infinit.
165  */
166 tarval *get_mode_max(ir_mode *mode);
167
168 /**
169  * Returns the value Zero represented in this mode.
170  *
171  * Zero is the additive neutral element and as such
172  * is defined only for modes allowing addition, i.e.
173  * floats and ints, and references (NULL-Pointer)
174  * else returns tarval_bad.
175  */
176 tarval *get_mode_null(ir_mode *mode);
177
178 /**
179  * Returns the value One, represented in this mode.
180  *
181  * One, being the multiplicative neutral element,
182  * is defined only for modes allowing multiplication,
183  * i.e. ints and floats.
184  */
185 tarval *get_mode_one(ir_mode *mode);
186
187 /**
188  * Returns the positive infinite value of a mode.
189  *
190  * This is only valid for float_numbers, other modes
191  * will result in tarval_bad.
192  */
193 tarval *get_mode_infinite(ir_mode *mode);
194
195 /**
196  * Returns the NAN value of a given mode.
197  *
198  * This is only valid for float_numbers, other modes
199  * will result in tarval_bad.
200  */
201 tarval *get_mode_NAN(ir_mode *mode);
202
203 /* -- Auxiliary modes necessary for the Firm representation -- */
204 extern ir_mode *mode_T;  /**< tuple (none) */
205 extern ir_mode *mode_X;  /**< execution */
206 extern ir_mode *mode_M;  /**< memory */
207 extern ir_mode *mode_BB; /**< block */
208
209 /* -- A set of predifined, numerical modes according to Techreport 1999-44 -- */
210 extern ir_mode *mode_F;  /**< signed float(32) */
211 extern ir_mode *mode_D;  /**< signed double(64) */
212 extern ir_mode *mode_E;  /**< signed extended(80) */
213 extern ir_mode *mode_Bs; /**< signed byte (former char) */
214 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
215 extern ir_mode *mode_Hs; /**< signed short integer */
216 extern ir_mode *mode_Hu; /**< unsigened short integer */
217 extern ir_mode *mode_Is; /**< signed integer */
218 extern ir_mode *mode_Iu; /**< unsigned integer */
219 extern ir_mode *mode_Ls; /**< signed long integer */
220 extern ir_mode *mode_Lu; /**< unsigned long integer */
221
222 extern ir_mode *mode_b;  /**< internal boolean */
223 extern ir_mode *mode_C;  /**< 8 bit char */
224 extern ir_mode *mode_U;  /**< 16 bit unicode char */
225 extern ir_mode *mode_P;  /**< pointer */
226
227 /*@{*/
228 /** Access routines for JNI Interface */
229 ir_mode *get_modeT(void);
230 ir_mode *get_modeF(void);
231 ir_mode *get_modeD(void);
232 ir_mode *get_modeE(void);
233 ir_mode *get_modeBs(void);
234 ir_mode *get_modeBu(void);
235 ir_mode *get_modeHs(void);
236 ir_mode *get_modeHu(void);
237 ir_mode *get_modeIs(void);
238 ir_mode *get_modeIu(void);
239 ir_mode *get_modeLs(void);
240 ir_mode *get_modeLu(void);
241 ir_mode *get_modeC(void);
242 ir_mode *get_modeU(void);
243 ir_mode *get_modeP(void);
244 ir_mode *get_modeb(void);
245 ir_mode *get_modeX(void);
246 ir_mode *get_modeM(void);
247 ir_mode *get_modeBB(void);
248
249 /**
250    Functions to check, whether a modecode is signed, float, int, num, data,
251    datab or dataM.
252
253    For more exact definitions read the corresponding pages
254    in the firm documentation or the followingenumeration
255
256    The set of "float" is defined as:
257    float = {irm_F, irm_D, irm_E}
258
259    The set of "int" is defined as:
260    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
261
262    The set of "num" is defined as:
263    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
264             irm_Is, irm_Iu, irm_Ls, irm_Lu}
265             = {float || int}
266
267    The set of "data" is defined as:
268    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
269             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
270             = {num || irm_C || irm_P}
271
272    The set of "datab" is defined as:
273    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
274             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
275             = {data || irm_b }
276
277    The set of "dataM" is defined as:
278    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
279             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
280             = {data || irm_M}
281 */
282 /*@}*/
283 /* Test for a certain class of modes. */
284 #ifdef MODE_ACCESS_DEFINES
285 #  define mode_is_signed(mode) (mode)->sign
286 #  define mode_is_float(mode) ((mode)->sort == float_number)
287 #  define mode_is_int(mode) ((mode)->sort == int_number)
288 #  define mode_is_num(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number))
289 #  define mode_is_data(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference))
290 #  define mode_is_datab(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->sort == internal_boolean))
291 #  define mode_is_dataM(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->code == irm_M))
292 #else
293 int mode_is_signed (ir_mode *mode);
294 int mode_is_float (ir_mode *mode);
295 int mode_is_int (ir_mode *mode);
296 int mode_is_num (ir_mode *mode);
297 int mode_is_data (ir_mode *mode);
298 int mode_is_datab (ir_mode *mode);
299 int mode_is_dataM (ir_mode *mode);
300 #endif
301 /** Returns true if sm can be converted to lm without loss
302    according to firm definiton */
303 int smaller_mode(ir_mode *sm, ir_mode *lm);
304
305 /** mode module initialization, call once before use of any other function **/
306 void init_mode (void);
307
308 #endif /* _IRMODE_H_ */