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. It defines
13 * a datasturcture that describes a mode and implements constructors and
14 * access routines to this datastructure. Further it defines a set of
18 * UKA tech report 1999-44 for more information about modes.
26 #ifndef _TARVAL_TYPEDEF_
27 #define _TARVAL_TYPEDEF_
28 typedef struct tarval tarval;
32 * Contains relevant information about a mode.
34 * Neccessary information about a mode is stored in this struct
35 * which is used by the tarval module to perform calculations
36 * and comparisons of values of a such described mode.
39 * - modecode code: An unambigous int (enum) for the mode
40 * - ident *name: Name of this mode. Two modes are different if the name is different.
41 * - mode_sort sort: sort of mode specifying possible usage kategories
42 * - int size: size of the mode in Bits.
43 * - int align: byte alignment
44 * - unsigned sign:1: signedness of this mode
48 * The tech report 1999-44 describing FIRM and predefined modes
51 typedef struct ir_mode ir_mode;
53 /* ********** Predefined modes ********** */
56 * Predefined mode according to tech report 1999-14.
58 typedef enum { /* irm is short for `ir mode' */
59 irm_BB, /**< basic block */
60 irm_X, /**< execution */
61 irm_F, /**< float(32) */
62 irm_D, /**< double(64) */
63 irm_E, /**< extended(80) */
64 irm_Bs, /**< signed byte(8) */
65 irm_Bu, /**< unsigned byte(8) */
66 irm_Hs, /**< signed short(16) */
67 irm_Hu, /**< unsigned short(16) */
68 irm_Is, /**< signed int(32) */
69 irm_Iu, /**< unsigned int(32) */
70 irm_Ls, /**< signed long(64) */
71 irm_Lu, /**< unsigned long(64) */
72 irm_C, /**< character */
73 irm_P, /**< pointer */
74 irm_b, /**< internal boolean */
77 irm_U, /**< unicode character */
78 irm_max /**< maximum value for modecode */
81 /** These values represent the different mode classes of value representations.
84 /* Predefined sorts of modes */
85 irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T) */
86 /* irms_control_flow **< Marks all control flow modes. Not extensible. (irm_BB, irm_X) */
87 /* irms_memory **< Marks the memory mode. Not extensible. (irm_M) */
88 irms_internal_boolean, /**< Internal boolean representation.
89 Storing to memory impossible, convert first. (irm_b) */
90 /** user-extensible sorts of modes **/
91 irms_int_number, /**< A mode to represent int numbers.
92 Integer computations can be performed. */
93 irms_float_number, /**< A mode to represent float numbers.
94 Floating point computations can be performed. */
95 irms_reference, /**< A mode to represent entities.
96 Restricted int computations can be performed */
97 irms_character /**< A mode to represent characters/symbols
98 ?? Are computations allowed? as int?? */
101 /** These values represent the different arithmetic operations possible with a mode.
102 Further arithmetics can be defined, e.g., for @@@ modes.
105 irma_uninitialized = 0,
106 irma_none = 1, /**< For modes for which no representation is specified.
107 These are modes of sort auxiliary, internal_boolean and
109 irma_twos_complement = 2, /**< Values of the mode are represented as two's complement.
110 Only legal for modes of sort int_number and reference. */
111 irma_ones_complement, /**< Values of the mode are represented as one's complement.
112 Only legal for modes of sort int_number and reference. */
113 irma_int_BCD, /**< Values of the mode are represented as binary coded decimals.
114 Only legal for modes of sort int_number and reference. */
115 irma_ieee754 = 256, /**< Values of the mode are represented according to ieee754
116 floatingpoint standard. Only legal for modes of sort float_number. */
117 irma_float_BCD, /**< Values of the mode are represented as binary coded decimals
118 according to @@@ which standars??? Only legal for modes of
119 sort float_number. */
124 /* ********** Constructor for user defined modes **************** */
126 * Creates a new mode.
128 * @param name the name of the mode to be created
129 * @param sort the mode_sort of the mode to be created
130 * @param bit_size number of bits this mode allocate
131 * @param align the byte alignment for an entity of this mode (in bits)
132 * @param sign non-zero if this is a signed mode
134 * This function constructs a new mode given by the parameters.
135 * If the parameters match an already defined mode, this mode is returned
136 * (including the default modes).
137 * If the mode is newly allocated, a new unique mode_code is choosen.
138 * Also, special value tarvals will be calculated such as null,
139 * min, max and can be retrieved using the get_mode_* fuctions
142 * The new mode or NULL on error.
145 * It is allowed to construct the default modes. So, a call
146 * new_ir_mode("Is", irms_int_number, 32, 4, 1) will return mode_Is.
148 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int align, int sign);
150 /* ********** Access methods to read mode information *********** */
152 /** Returns the classification of the mode */
153 modecode get_mode_modecode(const ir_mode *mode);
155 /** Returns the ident* of the mode */
156 ident *get_mode_ident(const ir_mode *mode);
158 /** Returns the null-terminated name of this mode. */
159 const char *get_mode_name(const ir_mode *mode);
161 /** Returns a coarse classification of the mode. */
162 mode_sort get_mode_sort(const ir_mode *mode);
164 /** Returns the size of values of the mode in bits. */
165 int get_mode_size_bits(const ir_mode *mode);
167 /** Returns the size of values of the mode in bytes. If the size is not
168 dividable by 8 returns -1. */
169 int get_mode_size_bytes(const ir_mode *mode);
171 /** Returns the alignment of values of the mode in bytes. */
172 int get_mode_align(const ir_mode *mode);
174 /** Returns the signess of a mode */
175 int get_mode_sign (const ir_mode *mode);
178 * Returns the smallest representable value of a given mode.
180 * For modes of the sort float_number this is the most negative value
181 * bigger than -infinit.
183 tarval *get_mode_min(ir_mode *mode);
186 * Returns the biggest representable value o f a given mode.
188 * For modes of the sort float_number this is the largest value lower
191 tarval *get_mode_max(ir_mode *mode);
194 * Returns the value Zero represented in this mode.
196 * Zero is the additive neutral element and as such
197 * is defined only for modes allowing addition, i.e.
198 * floats and ints, and references (NULL-Pointer)
199 * else returns tarval_bad.
201 tarval *get_mode_null(ir_mode *mode);
204 * Returns the value One, represented in this mode.
206 * One, being the multiplicative neutral element,
207 * is defined only for modes allowing multiplication,
208 * i.e. ints and floats.
210 tarval *get_mode_one(ir_mode *mode);
213 * Returns the positive infinite value of a mode.
215 * This is only valid for float_numbers, other modes
216 * will result in tarval_bad.
218 tarval *get_mode_infinite(ir_mode *mode);
221 * Returns the NAN value of a given mode.
223 * This is only valid for float_numbers, other modes
224 * will result in tarval_bad.
226 tarval *get_mode_NAN(ir_mode *mode);
228 /* -- Auxiliary modes necessary for the Firm representation -- */
229 extern ir_mode *mode_T; /**< tuple (none) */
230 extern ir_mode *mode_X; /**< execution */
231 extern ir_mode *mode_M; /**< memory */
232 extern ir_mode *mode_BB; /**< block */
234 /* -- A set of predifined, numerical modes according to Techreport 1999-44 -- */
235 extern ir_mode *mode_F; /**< signed float(32) */
236 extern ir_mode *mode_D; /**< signed double(64) */
237 extern ir_mode *mode_E; /**< signed extended(80) */
238 extern ir_mode *mode_Bs; /**< signed byte (former char) */
239 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
240 extern ir_mode *mode_Hs; /**< signed short integer */
241 extern ir_mode *mode_Hu; /**< unsigened short integer */
242 extern ir_mode *mode_Is; /**< signed integer */
243 extern ir_mode *mode_Iu; /**< unsigned integer */
244 extern ir_mode *mode_Ls; /**< signed long integer */
245 extern ir_mode *mode_Lu; /**< unsigned long integer */
247 extern ir_mode *mode_b; /**< internal boolean */
248 extern ir_mode *mode_C; /**< 8 bit char */
249 extern ir_mode *mode_U; /**< 16 bit unicode char */
250 extern ir_mode *mode_P; /**< pointer */
253 /** Access routines for JNI Interface */
254 ir_mode *get_modeT(void);
255 ir_mode *get_modeF(void);
256 ir_mode *get_modeD(void);
257 ir_mode *get_modeE(void);
258 ir_mode *get_modeBs(void);
259 ir_mode *get_modeBu(void);
260 ir_mode *get_modeHs(void);
261 ir_mode *get_modeHu(void);
262 ir_mode *get_modeIs(void);
263 ir_mode *get_modeIu(void);
264 ir_mode *get_modeLs(void);
265 ir_mode *get_modeLu(void);
266 ir_mode *get_modeC(void);
267 ir_mode *get_modeU(void);
268 ir_mode *get_modeP(void);
269 ir_mode *get_modeb(void);
270 ir_mode *get_modeX(void);
271 ir_mode *get_modeM(void);
272 ir_mode *get_modeBB(void);
275 Functions to check, whether a modecode is signed, float, int, num, data,
278 For more exact definitions read the corresponding pages
279 in the firm documentation or the following enumeration
281 The set of "float" is defined as:
282 float = {irm_F, irm_D, irm_E}
284 The set of "int" is defined as:
285 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
287 The set of "num" is defined as:
288 num = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
289 irm_Is, irm_Iu, irm_Ls, irm_Lu}
292 The set of "data" is defined as:
293 data = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
294 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
295 = {num || irm_C || irm_P}
297 The set of "datab" is defined as:
298 datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
299 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
302 The set of "dataM" is defined as:
303 dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
304 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
308 /* Test for a certain class of modes. */
309 int mode_is_signed (const ir_mode *mode);
310 int mode_is_float (const ir_mode *mode);
311 int mode_is_int (const ir_mode *mode);
312 int mode_is_character (const ir_mode *mode);
313 int mode_is_reference (const ir_mode *mode);
314 int mode_is_num (const ir_mode *mode);
315 int mode_is_data (const ir_mode *mode);
316 int mode_is_datab (const ir_mode *mode);
317 int mode_is_dataM (const ir_mode *mode);
318 /** Returns true if sm can be converted to lm without loss
319 according to firm definiton */
320 int smaller_mode(const ir_mode *sm, const ir_mode *lm);
322 /** mode module initialization, call once before use of any other function **/
323 void init_mode (void);
325 #endif /* _IRMODE_H_ */