1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
9 * irmode -- Modes for ir operators
16 * This module specifies the modes that type the firm nodes.
19 * UKA tech report 1999-44 for more information about modes.
27 #ifndef _TARVAL_TYPEDEF_
28 #define _TARVAL_TYPEDEF_
29 typedef struct tarval tarval;
36 * Contains relevant information about a mode
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
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
53 * The tech report 1999-44 describing FIRM and predefined modes
57 typedef struct ir_mode ir_mode;
59 /** ********** Predefined modes ********** **/
62 * according to tech report 1999-14:
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 */
83 irm_U, /**< unicode character */
84 irm_max /**< maximum value for modecode */
87 /** These values represent the different arithmetics used to
88 * manipulate values */
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?? */
105 /** ********** Constructor for user defined modes **************** **/
107 * register_mode(mode* new_mode)
109 * Registers a new mode.
110 * Must be called BEFORE init_mode2() !!!
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
119 * If a mode with the given characteristics already exists,
120 * it will be returned instead of creating a new one.
122 * The passed struct can be safely deallocated after the function
124 * To access the new mode the returned mode pointer must be used!
126 ir_mode *register_mode(ir_mode* new_mode);
128 /** ********** Access methods to read mode information *********** **/
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_bits(mode) (mode)->size
137 # define get_mode_align(mode) (mode)->align
139 /* The classification of the mode */
140 modecode get_mode_modecode(ir_mode *mode);
142 /* The ident* name of the mode */
143 ident *get_mode_ident(ir_mode *mode);
145 /* The null-terminated name of this mode */
146 const char *get_mode_name(ir_mode *mode);
148 /* A coarse classification of the mode */
149 mode_sort get_mode_sort(ir_mode *mode);
151 /** The size of values of the mode in bits. */
152 int get_mode_size_bits(ir_mode *mode);
153 /** The size of values of the mode in bytes. If the size is not
154 dividable by 8 returns -1. */
155 int get_mode_size_bytes(ir_mode *mode);
157 /* The alignment of values of the mode in bytes. */
158 int get_mode_align(ir_mode *mode);
161 /* The smallest representable value. For modes of the
162 * sort float_number this is the most negative value
163 * bigger than -infinit */
164 tarval *get_mode_min(ir_mode *mode);
166 /* The biggest representable value. For modes of the
167 * sort float_number this is the largest value lower
169 tarval *get_mode_max(ir_mode *mode);
171 /* The value Zero represented in this mode
172 Zero is the additive neutral element and as such
173 is defined only for modes allowing addition, i.e.
174 floats and ints, and references (NULL-Pointer)
175 else returns tarval_bad */
176 tarval *get_mode_null(ir_mode *mode);
178 /* The value One, represented in this mode
179 * One, being the multiplicative neutral element,
180 * is defined only for modes allowing multiplication,
181 * i.e. ints and floats */
182 tarval *get_mode_one(ir_mode *mode);
184 /* This is only valid for float_numbers, other modes
185 * will result in tarval_bad */
186 tarval *get_mode_infinite(ir_mode *mode);
188 /* This is only valid for float_numbers, other modes
189 * will result in tarval_bad */
190 tarval *get_mode_NAN(ir_mode *mode);
193 /** Auxiliary modes necessary for the Firm representation **/
194 extern ir_mode *mode_T; /* tuple (none) */
195 extern ir_mode *mode_X; /* execution */
196 extern ir_mode *mode_M; /* memory */
197 extern ir_mode *mode_BB; /* block */
199 /** A set of predifined, numerical modes according to Techreport 1999-44 **/
200 extern ir_mode *mode_F; /* signed float(32) */
201 extern ir_mode *mode_D; /* signed double(64) */
202 extern ir_mode *mode_E; /* signed extended(80) */
203 extern ir_mode *mode_Bs; /* signed byte (former char) */
204 extern ir_mode *mode_Bu; /* unsigned byte (former char) */
205 extern ir_mode *mode_Hs; /* signed short integer */
206 extern ir_mode *mode_Hu; /* unsigened short integer */
207 extern ir_mode *mode_Is; /* signed integer */
208 extern ir_mode *mode_Iu; /* unsigned integer */
209 extern ir_mode *mode_Ls; /* signed long integer */
210 extern ir_mode *mode_Lu; /* unsigned long integer */
212 extern ir_mode *mode_b; /* internal boolean */
213 extern ir_mode *mode_C; /* 8 bit char */
214 extern ir_mode *mode_U; /* 16 bit unicode char */
215 extern ir_mode *mode_P; /* pointer */
218 /** Access routines for JNI Interface */
219 ir_mode *get_modeT(void);
220 ir_mode *get_modeF(void);
221 ir_mode *get_modeD(void);
222 ir_mode *get_modeE(void);
223 ir_mode *get_modeBs(void);
224 ir_mode *get_modeBu(void);
225 ir_mode *get_modeHs(void);
226 ir_mode *get_modeHu(void);
227 ir_mode *get_modeIs(void);
228 ir_mode *get_modeIu(void);
229 ir_mode *get_modeLs(void);
230 ir_mode *get_modeLu(void);
231 ir_mode *get_modeC(void);
232 ir_mode *get_modeU(void);
233 ir_mode *get_modeP(void);
234 ir_mode *get_modeb(void);
235 ir_mode *get_modeX(void);
236 ir_mode *get_modeM(void);
237 ir_mode *get_modeBB(void);
240 Functions to check, whether a modecode is signed, float, int, num, data,
243 For more exact definitions read the corresponding pages
244 in the firm documentation or the followingenumeration
246 The set of "float" is defined as:
247 float = {irm_F, irm_D, irm_E}
249 The set of "int" is defined as:
250 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
252 The set of "num" is defined as:
253 num = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
254 irm_Is, irm_Iu, irm_Ls, irm_Lu}
257 The set of "data" is defined as:
258 data = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
259 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
260 = {num || irm_C || irm_P}
262 The set of "datab" is defined as:
263 datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
264 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
267 The set of "dataM" is defined as:
268 dataM = {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, irm_M}
273 /* Test for a certain class of modes. */
274 #ifdef MODE_ACCESS_DEFINES
275 # define mode_is_signed(mode) (mode)->sign
276 # define mode_is_float(mode) ((mode)->sort == float_number)
277 # define mode_is_int(mode) ((mode)->sort == int_number)
278 # define mode_is_num(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number))
279 # define mode_is_data(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference))
280 # define mode_is_datab(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->sort == internal_boolean))
281 # define mode_is_dataM(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->code == irm_M))
283 int mode_is_signed (ir_mode *mode);
284 int mode_is_float (ir_mode *mode);
285 int mode_is_int (ir_mode *mode);
286 int mode_is_num (ir_mode *mode);
287 int mode_is_data (ir_mode *mode);
288 int mode_is_datab (ir_mode *mode);
289 int mode_is_dataM (ir_mode *mode);
291 /** Returns true if sm can be converted to lm without loss
292 according to firm definiton */
293 int smaller_mode(ir_mode *sm, ir_mode *lm);
295 /** mode module initialization, call once before use of any other function **/
296 void init_mode (void);
298 # endif /* _IRMODE_H_ */