move backend into libfirm
[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, Michael Beck
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2007 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 #ifndef _IRMODE_T_H_
18 #define _IRMODE_T_H_
19
20 #include <assert.h>
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         unsigned          sign:1;        /**< signedness of this mode */
38         unsigned int      modulo_shift;  /**< number of bits a values of this mode will be shifted */
39         unsigned          vector_elem;   /**< if this is not equal 1, this is a vector mode with
40                                           vector_elem number of elements, size contains the size
41                                           of all bits and must be dividable by vector_elem */
42
43         /* ----------------------------------------------------------------------- */
44         tarval            *min;         /**< the minimum value that can be expressed */
45         tarval            *max;         /**< the maximum value that can be expressed */
46         tarval            *null;        /**< the value 0 */
47         tarval            *one;         /**< the value 1 */
48         tarval            *minus_one;   /**< the value -1 */
49         ir_mode           *eq_signed;   /**< For pointer modes, the equivalent signed integer one. */
50         ir_mode           *eq_unsigned; /**< For pointer modes, the equivalent unsigned integer one. */
51         void              *link;        /**< To store some intermediate information */
52         const void        *tv_priv;     /**< tarval module will save private data here */
53 };
54
55
56 /* ------------------------------- *
57  * inline functions                *
58  * ------------------------------- */
59 extern ir_mode *mode_P_code, *mode_P_data;
60
61 static INLINE ir_mode *
62 _get_modeP_code(void) { return mode_P_code; }
63
64 static INLINE ir_mode *
65 _get_modeP_data(void) { return mode_P_data; }
66
67 static INLINE modecode
68 _get_mode_modecode(const ir_mode *mode) { return mode->code; }
69
70 static INLINE ident *
71 _get_mode_ident(const ir_mode *mode) { return mode->name; }
72
73 static INLINE mode_sort
74 _get_mode_sort(const ir_mode* mode) { return mode->sort; }
75
76 static INLINE int
77 _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
78
79 static INLINE int
80 _get_mode_size_bytes(const ir_mode *mode) {
81         int size = _get_mode_size_bits(mode);
82         if ((size & 7) != 0) return -1;
83         return size >> 3;
84 }
85
86 static INLINE int
87 _get_mode_sign(const ir_mode *mode) { return mode->sign; }
88
89 static INLINE int
90 _get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
91
92 static INLINE unsigned int
93 _get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
94
95 static INLINE unsigned int
96 _get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
97
98 static INLINE void *
99 _get_mode_link(const ir_mode *mode) { return mode->link; }
100
101 static INLINE void
102 _set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
103
104 /* Functions to check, whether a modecode is signed, float, int, num, data,
105    datab or dataM. For more exact definitions read the corresponding pages
106    in the firm documentation or the following enumeration
107
108    The set of "float" is defined as:
109    ---------------------------------
110    float = {irm_F, irm_D, irm_E}
111
112    The set of "int" is defined as:
113    -------------------------------
114    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
115
116    The set of "num" is defined as:
117    -------------------------------
118    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
119             irm_Is, irm_Iu, irm_Ls, irm_Lu}
120             = {float || int}
121
122    The set of "data" is defined as:
123    -------------------------------
124    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
125             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
126             = {num || irm_C || irm_U || irm_P}
127
128    The set of "datab" is defined as:
129    ---------------------------------
130    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
131             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
132             = {data || irm_b }
133
134    The set of "dataM" is defined as:
135    ---------------------------------
136    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
137             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
138             = {data || irm_M}
139 */
140
141 static INLINE int
142 _mode_is_signed(const ir_mode *mode) {
143         assert(mode);
144         return mode->sign;
145 }
146
147 static INLINE int
148 _mode_is_float(const ir_mode *mode) {
149         assert(mode);
150         return (_get_mode_sort(mode) == irms_float_number);
151 }
152
153 static INLINE int
154 _mode_is_int(const ir_mode *mode) {
155         assert(mode);
156         return (_get_mode_sort(mode) == irms_int_number);
157 }
158
159 static INLINE int
160 _mode_is_character(const ir_mode *mode) {
161         assert(mode);
162         return (_get_mode_sort(mode) == irms_character);
163 }
164
165 static INLINE int
166 _mode_is_reference(const ir_mode *mode) {
167         assert(mode);
168         return (_get_mode_sort(mode) == irms_reference);
169 }
170
171 static INLINE int
172 _mode_is_num(const ir_mode *mode) {
173         assert(mode);
174         return (_mode_is_int(mode) || _mode_is_float(mode));
175 }
176
177 static INLINE int
178 _mode_is_numP(const ir_mode *mode) {
179         assert(mode);
180         return (_mode_is_int(mode) || _mode_is_float(mode) || _mode_is_reference(mode));
181 }
182
183 static INLINE int
184 _mode_is_data(const ir_mode *mode) {
185         assert(mode);
186         return (_mode_is_num(mode) || _get_mode_sort(mode) == irms_character || _get_mode_sort(mode) == irms_reference);
187 }
188
189 static INLINE int
190 _mode_is_datab(const ir_mode *mode) {
191         assert(mode);
192         return (_mode_is_data(mode) || _get_mode_sort(mode) == irms_internal_boolean);
193 }
194
195 static INLINE int
196 _mode_is_dataM(const ir_mode *mode) {
197         assert(mode);
198         return (_mode_is_data(mode) || _get_mode_modecode(mode) == irm_M);
199 }
200
201 static INLINE int
202 _mode_is_float_vector(const ir_mode *mode) {
203         assert(mode);
204         return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
205 }
206
207 static INLINE int
208 _mode_is_int_vector(const ir_mode *mode) {
209         assert(mode);
210         return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
211 }
212
213 /** mode module initialization, call once before use of any other function **/
214 void init_mode(void);
215
216 /** mode module finalization. frees all memory.  */
217 void finish_mode(void);
218
219 #define get_modeP_code()               _get_modeP_code()
220 #define get_modeP_data()               _get_modeP_data()
221 #define get_mode_modecode(mode)        _get_mode_modecode(mode)
222 #define get_mode_ident(mode)           _get_mode_ident(mode)
223 #define get_mode_sort(mode)            _get_mode_sort(mode)
224 #define get_mode_size_bits(mode)       _get_mode_size_bits(mode)
225 #define get_mode_size_bytes(mode)      _get_mode_size_bytes(mode)
226 #define get_mode_sign(mode)            _get_mode_sign(mode)
227 #define get_mode_arithmetic(mode)      _get_mode_arithmetic(mode)
228 #define get_mode_modulo_shift(mode)    _get_mode_modulo_shift(mode)
229 #define get_mode_n_vector_elems(mode)  _get_mode_vector_elems(mode)
230 #define get_mode_link(mode)            _get_mode_link(mode)
231 #define set_mode_link(mode, l)         _set_mode_link(mode, l)
232 #define mode_is_signed(mode)           _mode_is_signed(mode)
233 #define mode_is_float(mode)            _mode_is_float(mode)
234 #define mode_is_int(mode)              _mode_is_int(mode)
235 #define mode_is_character(mode)        _mode_is_character(mode)
236 #define mode_is_reference(mode)        _mode_is_reference(mode)
237 #define mode_is_num(mode)              _mode_is_num(mode)
238 #define mode_is_numP(mode)             _mode_is_numP(mode)
239 #define mode_is_data(mode)             _mode_is_data(mode)
240 #define mode_is_datab(mode)            _mode_is_datab(mode)
241 #define mode_is_dataM(mode)            _mode_is_dataM(mode)
242 #define mode_is_float_vector(mode)     _mode_is_float_vector(mode)
243 #define mode_is_int_vector(mode)       _mode_is_int_vector(mode)
244
245 #endif /* _IRMODE_T_H_ */