1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
8 * irmode -- Modes for ir operators
10 * @author Christian Schaefer, Matthias Heil
12 * This module specifies the modes that type the firm nodes.
15 * UKA tech report 1999-44 for more information about modes.
23 #ifndef _TARVAL_TYPEDEF_
24 #define _TARVAL_TYPEDEF_
25 typedef struct tarval tarval;
29 * Contains relevant information about a mode.
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.
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
45 * The tech report 1999-44 describing FIRM and predefined modes
48 typedef struct ir_mode ir_mode;
50 /* ********** Predefined modes ********** */
53 * Predefined mode according to tech report 1999-14.
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 */
74 irm_U, /**< unicode character */
75 irm_max /**< maximum value for modecode */
78 /** These values represent the different arithmetics used to
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?? */
97 /* ********** Constructor for user defined modes **************** */
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
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
115 * The new mode or NULL on error.
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.
121 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int align, int sign);
123 /* ********** Access methods to read mode information *********** */
125 /** Returns the classification of the mode */
126 modecode get_mode_modecode(ir_mode *mode);
128 /** Returns the ident* of the mode */
129 ident *get_mode_ident(ir_mode *mode);
131 /** Returns the null-terminated name of this mode. */
132 const char *get_mode_name(ir_mode *mode);
134 /** Returns a coarse classification of the mode. */
135 mode_sort get_mode_sort(ir_mode *mode);
137 /** Returns the size of values of the mode in bits. */
138 int get_mode_size_bits(ir_mode *mode);
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);
144 /** Returns the alignment of values of the mode in bytes. */
145 int get_mode_align(ir_mode *mode);
147 /** Returns the signess of a mode */
148 int get_mode_sign (ir_mode *mode);
151 * Returns the smallest representable value of a given mode.
153 * For modes of the sort float_number this is the most negative value
154 * bigger than -infinit.
156 tarval *get_mode_min(ir_mode *mode);
159 * Returns the biggest representable value o f a given mode.
161 * For modes of the sort float_number this is the largest value lower
164 tarval *get_mode_max(ir_mode *mode);
167 * Returns 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.
174 tarval *get_mode_null(ir_mode *mode);
177 * Returns 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.
183 tarval *get_mode_one(ir_mode *mode);
186 * Returns the positive infinite value of a mode.
188 * This is only valid for float_numbers, other modes
189 * will result in tarval_bad.
191 tarval *get_mode_infinite(ir_mode *mode);
194 * Returns the NAN value of a given mode.
196 * This is only valid for float_numbers, other modes
197 * will result in tarval_bad.
199 tarval *get_mode_NAN(ir_mode *mode);
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 */
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 */
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 */
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);
248 Functions to check, whether a modecode is signed, float, int, num, data,
251 For more exact definitions read the corresponding pages
252 in the firm documentation or the followingenumeration
254 The set of "float" is defined as:
255 float = {irm_F, irm_D, irm_E}
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}
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}
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}
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}
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}
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);
293 /** mode module initialization, call once before use of any other function **/
294 void init_mode (void);
296 #endif /* _IRMODE_H_ */