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 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?? */
97 /* ********** Constructor for user defined modes **************** */
99 * Registers a new mode.
101 * The information for new mode is retrieved from the mode
102 * struct passed as parameter, the code field is ignored.
103 * The struct is copied into the internal mode array and the code
104 * field will be set to a unique integer.
105 * Also, special value tarvals will be calculated such as null,
106 * min, max and can be retrieved using the get_mode_* fuctions
108 * If a mode with the given characteristics already exists,
109 * it will be returned instead of creating a new one.
111 * The passed struct can be safely deallocated after the function
113 * To access the new mode the returned mode pointer must be used!
115 ir_mode *register_mode(ir_mode* new_mode);
117 /* ********** Access methods to read mode information *********** */
119 /** Returns the classification of the mode */
120 modecode get_mode_modecode(ir_mode *mode);
122 /** Returns the ident* of the mode */
123 ident *get_mode_ident(ir_mode *mode);
125 /** Returns the null-terminated name of this mode. */
126 const char *get_mode_name(ir_mode *mode);
128 /** Returns a coarse classification of the mode. */
129 mode_sort get_mode_sort(ir_mode *mode);
131 /** Returns the size of values of the mode in bits. */
132 int get_mode_size_bits(ir_mode *mode);
134 /** Returns the size of values of the mode in bytes. If the size is not
135 dividable by 8 returns -1. */
136 int get_mode_size_bytes(ir_mode *mode);
138 /** Returns the alignment of values of the mode in bytes. */
139 int get_mode_align(ir_mode *mode);
141 /** Returns the signess of a mode */
142 int get_mode_sign (ir_mode *mode);
145 * Returns the smallest representable value of a given mode.
147 * For modes of the sort float_number this is the most negative value
148 * bigger than -infinit.
150 tarval *get_mode_min(ir_mode *mode);
153 * Returns the biggest representable value o f a given mode.
155 * For modes of the sort float_number this is the largest value lower
158 tarval *get_mode_max(ir_mode *mode);
161 * Returns the value Zero represented in this mode.
163 * Zero is the additive neutral element and as such
164 * is defined only for modes allowing addition, i.e.
165 * floats and ints, and references (NULL-Pointer)
166 * else returns tarval_bad.
168 tarval *get_mode_null(ir_mode *mode);
171 * Returns the value One, represented in this mode.
173 * One, being the multiplicative neutral element,
174 * is defined only for modes allowing multiplication,
175 * i.e. ints and floats.
177 tarval *get_mode_one(ir_mode *mode);
180 * Returns the positive infinite value of a mode.
182 * This is only valid for float_numbers, other modes
183 * will result in tarval_bad.
185 tarval *get_mode_infinite(ir_mode *mode);
188 * Returns the NAN value of a given mode.
190 * This is only valid for float_numbers, other modes
191 * will result in tarval_bad.
193 tarval *get_mode_NAN(ir_mode *mode);
195 /* -- Auxiliary modes necessary for the Firm representation -- */
196 extern ir_mode *mode_T; /**< tuple (none) */
197 extern ir_mode *mode_X; /**< execution */
198 extern ir_mode *mode_M; /**< memory */
199 extern ir_mode *mode_BB; /**< block */
201 /* -- A set of predifined, numerical modes according to Techreport 1999-44 -- */
202 extern ir_mode *mode_F; /**< signed float(32) */
203 extern ir_mode *mode_D; /**< signed double(64) */
204 extern ir_mode *mode_E; /**< signed extended(80) */
205 extern ir_mode *mode_Bs; /**< signed byte (former char) */
206 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
207 extern ir_mode *mode_Hs; /**< signed short integer */
208 extern ir_mode *mode_Hu; /**< unsigened short integer */
209 extern ir_mode *mode_Is; /**< signed integer */
210 extern ir_mode *mode_Iu; /**< unsigned integer */
211 extern ir_mode *mode_Ls; /**< signed long integer */
212 extern ir_mode *mode_Lu; /**< unsigned long integer */
214 extern ir_mode *mode_b; /**< internal boolean */
215 extern ir_mode *mode_C; /**< 8 bit char */
216 extern ir_mode *mode_U; /**< 16 bit unicode char */
217 extern ir_mode *mode_P; /**< pointer */
220 /** Access routines for JNI Interface */
221 ir_mode *get_modeT(void);
222 ir_mode *get_modeF(void);
223 ir_mode *get_modeD(void);
224 ir_mode *get_modeE(void);
225 ir_mode *get_modeBs(void);
226 ir_mode *get_modeBu(void);
227 ir_mode *get_modeHs(void);
228 ir_mode *get_modeHu(void);
229 ir_mode *get_modeIs(void);
230 ir_mode *get_modeIu(void);
231 ir_mode *get_modeLs(void);
232 ir_mode *get_modeLu(void);
233 ir_mode *get_modeC(void);
234 ir_mode *get_modeU(void);
235 ir_mode *get_modeP(void);
236 ir_mode *get_modeb(void);
237 ir_mode *get_modeX(void);
238 ir_mode *get_modeM(void);
239 ir_mode *get_modeBB(void);
242 Functions to check, whether a modecode is signed, float, int, num, data,
245 For more exact definitions read the corresponding pages
246 in the firm documentation or the followingenumeration
248 The set of "float" is defined as:
249 float = {irm_F, irm_D, irm_E}
251 The set of "int" is defined as:
252 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
254 The set of "num" is defined as:
255 num = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
256 irm_Is, irm_Iu, irm_Ls, irm_Lu}
259 The set of "data" is defined as:
260 data = {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}
262 = {num || irm_C || irm_P}
264 The set of "datab" is defined as:
265 datab = {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_b}
269 The set of "dataM" is defined as:
270 dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
271 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
275 /* Test for a certain class of modes. */
276 int mode_is_signed (ir_mode *mode);
277 int mode_is_float (ir_mode *mode);
278 int mode_is_int (ir_mode *mode);
279 int mode_is_num (ir_mode *mode);
280 int mode_is_data (ir_mode *mode);
281 int mode_is_datab (ir_mode *mode);
282 int mode_is_dataM (ir_mode *mode);
283 /** Returns true if sm can be converted to lm without loss
284 according to firm definiton */
285 int smaller_mode(ir_mode *sm, ir_mode *lm);
287 /** mode module initialization, call once before use of any other function **/
288 void init_mode (void);
290 #endif /* _IRMODE_H_ */