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