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