type type definitions to new irtype.h
[libfirm] / ir / ir / irmode_t.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Data modes of operations -- private header.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil,
24  *          Michael Beck
25  * @version $Id$
26  */
27 #ifndef FIRM_IR_IRMODE_T_H
28 #define FIRM_IR_IRMODE_T_H
29
30 #include <assert.h>
31 #include "irtypes.h"
32 #include "irmode.h"
33
34 /* ------------------------------- *
35  * inline functions                *
36  * ------------------------------- */
37 extern ir_mode *mode_P_code, *mode_P_data;
38
39 static INLINE ir_mode *
40 _get_modeP_code(void) { return mode_P_code; }
41
42 static INLINE ir_mode *
43 _get_modeP_data(void) { return mode_P_data; }
44
45 static INLINE modecode
46 _get_mode_modecode(const ir_mode *mode) { return mode->code; }
47
48 static INLINE ident *
49 _get_mode_ident(const ir_mode *mode) { return mode->name; }
50
51 static INLINE mode_sort
52 _get_mode_sort(const ir_mode* mode) { return mode->sort; }
53
54 static INLINE int
55 _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
56
57 static INLINE int
58 _get_mode_size_bytes(const ir_mode *mode) {
59         int size = _get_mode_size_bits(mode);
60         if ((size & 7) != 0) return -1;
61         return size >> 3;
62 }
63
64 static INLINE int
65 _get_mode_sign(const ir_mode *mode) { return mode->sign; }
66
67 static INLINE int
68 _get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
69
70 static INLINE unsigned int
71 _get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
72
73 static INLINE unsigned int
74 _get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
75
76 static INLINE void *
77 _get_mode_link(const ir_mode *mode) { return mode->link; }
78
79 static INLINE void
80 _set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
81
82 /* Functions to check, whether a modecode is signed, float, int, num, data,
83    datab or dataM. For more exact definitions read the corresponding pages
84    in the firm documentation or the following enumeration
85
86    The set of "float" is defined as:
87    ---------------------------------
88    float = {irm_F, irm_D, irm_E}
89
90    The set of "int" is defined as:
91    -------------------------------
92    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
93
94    The set of "num" is defined as:
95    -------------------------------
96    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
97             irm_Is, irm_Iu, irm_Ls, irm_Lu}
98             = {float || int}
99
100    The set of "data" is defined as:
101    -------------------------------
102    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
103             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
104             = {num || irm_C || irm_U || irm_P}
105
106    The set of "datab" is defined as:
107    ---------------------------------
108    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
109             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
110             = {data || irm_b }
111
112    The set of "dataM" is defined as:
113    ---------------------------------
114    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
115             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
116             = {data || irm_M}
117 */
118
119 static INLINE int
120 _mode_is_signed(const ir_mode *mode) {
121         assert(mode);
122         return mode->sign;
123 }
124
125 static INLINE int
126 _mode_is_float(const ir_mode *mode) {
127         assert(mode);
128         return (_get_mode_sort(mode) == irms_float_number);
129 }
130
131 static INLINE int
132 _mode_is_int(const ir_mode *mode) {
133         assert(mode);
134         return (_get_mode_sort(mode) == irms_int_number);
135 }
136
137 static INLINE int
138 _mode_is_character(const ir_mode *mode) {
139         assert(mode);
140         return (_get_mode_sort(mode) == irms_character);
141 }
142
143 static INLINE int
144 _mode_is_reference(const ir_mode *mode) {
145         assert(mode);
146         return (_get_mode_sort(mode) == irms_reference);
147 }
148
149 static INLINE int
150 _mode_is_num(const ir_mode *mode) {
151         assert(mode);
152         return (_mode_is_int(mode) || _mode_is_float(mode));
153 }
154
155 static INLINE int
156 _mode_is_numP(const ir_mode *mode) {
157         assert(mode);
158         return (_mode_is_int(mode) || _mode_is_float(mode) || _mode_is_reference(mode));
159 }
160
161 static INLINE int
162 _mode_is_data(const ir_mode *mode) {
163         assert(mode);
164         return (_mode_is_numP(mode) || _get_mode_sort(mode) == irms_character);
165 }
166
167 static INLINE int
168 _mode_is_datab(const ir_mode *mode) {
169         assert(mode);
170         return (_mode_is_data(mode) || _get_mode_sort(mode) == irms_internal_boolean);
171 }
172
173 static INLINE int
174 _mode_is_dataM(const ir_mode *mode) {
175         assert(mode);
176         return (_mode_is_data(mode) || _get_mode_modecode(mode) == irm_M);
177 }
178
179 static INLINE int
180 _mode_is_float_vector(const ir_mode *mode) {
181         assert(mode);
182         return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
183 }
184
185 static INLINE int
186 _mode_is_int_vector(const ir_mode *mode) {
187         assert(mode);
188         return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
189 }
190
191 /** mode module initialization, call once before use of any other function **/
192 void init_mode(void);
193
194 /** mode module finalization. frees all memory.  */
195 void finish_mode(void);
196
197 #define get_modeP_code()               _get_modeP_code()
198 #define get_modeP_data()               _get_modeP_data()
199 #define get_mode_modecode(mode)        _get_mode_modecode(mode)
200 #define get_mode_ident(mode)           _get_mode_ident(mode)
201 #define get_mode_sort(mode)            _get_mode_sort(mode)
202 #define get_mode_size_bits(mode)       _get_mode_size_bits(mode)
203 #define get_mode_size_bytes(mode)      _get_mode_size_bytes(mode)
204 #define get_mode_sign(mode)            _get_mode_sign(mode)
205 #define get_mode_arithmetic(mode)      _get_mode_arithmetic(mode)
206 #define get_mode_modulo_shift(mode)    _get_mode_modulo_shift(mode)
207 #define get_mode_n_vector_elems(mode)  _get_mode_vector_elems(mode)
208 #define get_mode_link(mode)            _get_mode_link(mode)
209 #define set_mode_link(mode, l)         _set_mode_link(mode, l)
210 #define mode_is_signed(mode)           _mode_is_signed(mode)
211 #define mode_is_float(mode)            _mode_is_float(mode)
212 #define mode_is_int(mode)              _mode_is_int(mode)
213 #define mode_is_character(mode)        _mode_is_character(mode)
214 #define mode_is_reference(mode)        _mode_is_reference(mode)
215 #define mode_is_num(mode)              _mode_is_num(mode)
216 #define mode_is_numP(mode)             _mode_is_numP(mode)
217 #define mode_is_data(mode)             _mode_is_data(mode)
218 #define mode_is_datab(mode)            _mode_is_datab(mode)
219 #define mode_is_dataM(mode)            _mode_is_dataM(mode)
220 #define mode_is_float_vector(mode)     _mode_is_float_vector(mode)
221 #define mode_is_int_vector(mode)       _mode_is_int_vector(mode)
222
223 #endif