removed include
[libfirm] / ir / ir / irmode_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irmode_t.h
4  * Purpose:     Data modes of operations -- private header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier, Mathias Heil
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 /**
15  * @file irmode_t.h
16  */
17
18 # ifndef _IRMODE_T_H_
19 # define _IRMODE_T_H_
20
21 # include "irmode.h"
22 # include "tv.h"
23
24 /** This struct is supposed to completely define a mode. **/
25 struct ir_mode {
26   firm_kind         kind;       /**< distinguishes this node from others */
27   modecode          code;       /**< unambiguous identifier of a mode */
28   ident             *name;      /**< Name ident of this mode */
29
30   /* ----------------------------------------------------------------------- */
31   /* On changing this struct you have to evaluate the mode_are_equal function!*/
32   mode_sort         sort;          /**< coarse classification of this mode:
33                                      int, float, reference ...
34                                      (see irmode.h) */
35   mode_arithmetic   arithmetic;    /**< different arithmetic operations possible with a mode */
36   int               size;          /**< size of the mode in Bits. */
37   int               align;         /**< mode alignment in Bits. */
38   unsigned          sign:1;        /**< signedness of this mode */
39   unsigned int      modulo_shift;  /**< number of bits a valus of this mode will be shifted */
40   unsigned          vector_elem;   /**< if this is not equal 1, this is a vector mode with
41                                         vector_elem number of elements, size contains the size
42                                         of all bits and must be dividable by vector_elem */
43
44   /* ----------------------------------------------------------------------- */
45   tarval            *min;
46   tarval            *max;
47   tarval            *null;
48   tarval            *one;
49   void              *link;      /**< To store some intermediate information */
50   const void        *tv_priv;   /**< tarval module will save private data here */
51 };
52
53
54 /* ------------------------------- *
55  * inline functions                *
56  * ------------------------------- */
57 extern ir_mode *mode_P_mach;
58
59 static INLINE ir_mode *
60 __get_modeP_mach(void) { return mode_P_mach; }
61
62 static INLINE void
63 __set_modeP_mach(ir_mode *p) {
64   assert(mode_is_reference(p));
65   mode_P_mach = p;
66 }
67
68 static INLINE modecode
69 __get_mode_modecode(const ir_mode *mode) { return mode->code; }
70
71 static INLINE ident *
72 __get_mode_ident(const ir_mode *mode) { return mode->name; }
73
74 static INLINE mode_sort
75 __get_mode_sort(const ir_mode* mode) { return mode->sort; }
76
77 static INLINE int
78 __get_mode_size_bits(const ir_mode *mode) { return mode->size; }
79
80 static INLINE int
81 __get_mode_size_bytes(const ir_mode *mode) {
82   int size = __get_mode_size_bits(mode);
83   if ((size & 7) != 0) return -1;
84   return size >> 3;
85 }
86
87 static INLINE int
88 __get_mode_align_bits(const ir_mode *mode) { return mode->align; }
89
90 static INLINE int
91 __get_mode_align_bytes(const ir_mode *mode) {
92   int align = __get_mode_align_bits(mode);
93   if ((align & 7) != 0) return -1;
94   return align >> 3;
95 }
96
97 static INLINE int
98 __get_mode_sign(const ir_mode *mode) { return mode->sign; }
99
100 static INLINE int
101 __get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
102
103 static INLINE unsigned int
104 __get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
105
106 static INLINE unsigned int
107 __get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
108
109 static INLINE void *
110 __get_mode_link(const ir_mode *mode) { return mode->link; }
111
112 static INLINE void
113 __set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
114
115 /* Functions to check, whether a modecode is signed, float, int, num, data,
116    datab or dataM. For more exact definitions read the corresponding pages
117    in the firm documentation or the followingenumeration
118
119    The set of "float" is defined as:
120    ---------------------------------
121    float = {irm_F, irm_D, irm_E}
122
123    The set of "int" is defined as:
124    -------------------------------
125    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
126
127    The set of "num" is defined as:
128    -------------------------------
129    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
130             irm_Is, irm_Iu, irm_Ls, irm_Lu}
131             = {float || int}
132
133    The set of "data" is defined as:
134    -------------------------------
135    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
136             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
137             = {num || irm_C || irm_U || irm_P}
138
139    The set of "datab" is defined as:
140    ---------------------------------
141    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
142             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
143             = {data || irm_b }
144
145    The set of "dataM" is defined as:
146    ---------------------------------
147    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
148             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
149             = {data || irm_M}
150 */
151
152 static INLINE int
153 __mode_is_signed(const ir_mode *mode) {
154   assert(mode);
155   return mode->sign;
156 }
157
158 static INLINE int
159 __mode_is_float(const ir_mode *mode) {
160   assert(mode);
161   return (__get_mode_sort(mode) == irms_float_number);
162 }
163
164 static INLINE int
165 __mode_is_int(const ir_mode *mode) {
166   assert(mode);
167   return (__get_mode_sort(mode) == irms_int_number);
168 }
169
170 static INLINE int
171 __mode_is_character(const ir_mode *mode) {
172   assert(mode);
173   return (__get_mode_sort(mode) == irms_character);
174 }
175
176 static INLINE int
177 __mode_is_reference(const ir_mode *mode) {
178   assert(mode);
179   return (__get_mode_sort(mode) == irms_reference);
180 }
181
182 static INLINE int
183 __mode_is_num(const ir_mode *mode) {
184   assert(mode);
185   return (__mode_is_int(mode) || __mode_is_float(mode));
186 }
187
188 static INLINE int
189 __mode_is_numP(const ir_mode *mode) {
190   assert(mode);
191   return (__mode_is_int(mode) || __mode_is_float(mode) || __mode_is_reference(mode));
192 }
193
194 static INLINE int
195 __mode_is_data(const ir_mode *mode) {
196   assert(mode);
197   return (__mode_is_num(mode) || __get_mode_sort(mode) == irms_character || __get_mode_sort(mode) == irms_reference);
198 }
199
200 static INLINE int
201 __mode_is_datab(const ir_mode *mode) {
202   assert(mode);
203   return (__mode_is_data(mode) || __get_mode_sort(mode) == irms_internal_boolean);
204 }
205
206 static INLINE int
207 __mode_is_dataM(const ir_mode *mode) {
208   assert(mode);
209   return (__mode_is_data(mode) || __get_mode_modecode(mode) == irm_M);
210 }
211
212 static INLINE int
213 __mode_is_float_vector(const ir_mode *mode) {
214   assert(mode);
215   return (__get_mode_sort(mode) == irms_float_number) && (__get_mode_vector_elems(mode) > 1);
216 }
217
218 static INLINE int
219 __mode_is_int_vector(const ir_mode *mode) {
220   assert(mode);
221   return (__get_mode_sort(mode) == irms_int_number) && (__get_mode_vector_elems(mode) > 1);
222 }
223
224 /** mode module initialization, call once before use of any other function **/
225 void init_mode(void);
226
227 /** mode module finalization. frees all memory.  */
228 void finish_mode(void);
229
230 #define get_modeP_mach()               __get_modeP_mach()
231 #define set_modeP_mach(p)              __set_modeP_mach(p)
232 #define get_mode_modecode(mode)        __get_mode_modecode(mode)
233 #define get_mode_ident(mode)           __get_mode_ident(mode)
234 #define get_mode_sort(mode)            __get_mode_sort(mode)
235 #define get_mode_size_bits(mode)       __get_mode_size_bits(mode)
236 #define get_mode_size_bytes(mode)      __get_mode_size_bytes(mode)
237 #define get_mode_align(mode)           __get_mode_align(mode)
238 #define get_mode_sign(mode)            __get_mode_sign(mode)
239 #define get_mode_arithmetic(mode)      __get_mode_arithmetic(mode)
240 #define get_mode_modulo_shift(mode)    __get_mode_modulo_shift(mode)
241 #define get_mode_n_vector_elems(mode)  __get_mode_vector_elems(mode)
242 #define get_mode_link(mode)            __get_mode_link(mode)
243 #define set_mode_link(mode, l)         __set_mode_link(mode, l)
244 #define mode_is_signed(mode)           __mode_is_signed(mode)
245 #define mode_is_float(mode)            __mode_is_float(mode)
246 #define mode_is_int(mode)              __mode_is_int(mode)
247 #define mode_is_character(mode)        __mode_is_character(mode)
248 #define mode_is_reference(mode)        __mode_is_reference(mode)
249 #define mode_is_num(mode)              __mode_is_num(mode)
250 #define mode_is_numP(mode)             __mode_is_numP(mode)
251 #define mode_is_data(mode)             __mode_is_data(mode)
252 #define mode_is_datab(mode)            __mode_is_datab(mode)
253 #define mode_is_dataM(mode)            __mode_is_dataM(mode)
254 #define mode_is_float_vector(mode)     __mode_is_float_vector(mode)
255 #define mode_is_int_vector(mode)       __mode_is_int_vector(mode)
256
257 #endif /* _IRMODE_T_H_ */