fix some warnings, represent mode size as unsigned value
[libfirm] / ir / ir / irmode_t.h
1 /*
2  * Copyright (C) 1995-2008 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 unsigned
55 _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
56
57 static INLINE unsigned
58 _get_mode_size_bytes(const ir_mode *mode) {
59         unsigned size = _get_mode_size_bits(mode);
60         if ((size & 7) != 0) return (unsigned) -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 mode_arithmetic
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_reference(const ir_mode *mode) {
139         assert(mode);
140         return (_get_mode_sort(mode) == irms_reference);
141 }
142
143 static INLINE int
144 _mode_is_num(const ir_mode *mode) {
145         assert(mode);
146         return (_mode_is_int(mode) || _mode_is_float(mode));
147 }
148
149 static INLINE int
150 _mode_is_data(const ir_mode *mode) {
151         return (_mode_is_int(mode) || _mode_is_float(mode) || _mode_is_reference(mode));
152 }
153
154 static INLINE int
155 _mode_is_datab(const ir_mode *mode) {
156         assert(mode);
157         return (_mode_is_data(mode) || _get_mode_sort(mode) == irms_internal_boolean);
158 }
159
160 static INLINE int
161 _mode_is_dataM(const ir_mode *mode) {
162         assert(mode);
163         return (_mode_is_data(mode) || _get_mode_modecode(mode) == irm_M);
164 }
165
166 static INLINE int
167 _mode_is_float_vector(const ir_mode *mode) {
168         assert(mode);
169         return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
170 }
171
172 static INLINE int
173 _mode_is_int_vector(const ir_mode *mode) {
174         assert(mode);
175         return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
176 }
177
178 /** mode module initialization, call once before use of any other function **/
179 void init_mode(void);
180
181 /** mode module finalization. frees all memory.  */
182 void finish_mode(void);
183
184 #define get_modeP_code()               _get_modeP_code()
185 #define get_modeP_data()               _get_modeP_data()
186 #define get_mode_modecode(mode)        _get_mode_modecode(mode)
187 #define get_mode_ident(mode)           _get_mode_ident(mode)
188 #define get_mode_sort(mode)            _get_mode_sort(mode)
189 #define get_mode_size_bits(mode)       _get_mode_size_bits(mode)
190 #define get_mode_size_bytes(mode)      _get_mode_size_bytes(mode)
191 #define get_mode_sign(mode)            _get_mode_sign(mode)
192 #define get_mode_arithmetic(mode)      _get_mode_arithmetic(mode)
193 #define get_mode_modulo_shift(mode)    _get_mode_modulo_shift(mode)
194 #define get_mode_n_vector_elems(mode)  _get_mode_vector_elems(mode)
195 #define get_mode_link(mode)            _get_mode_link(mode)
196 #define set_mode_link(mode, l)         _set_mode_link(mode, l)
197 #define mode_is_signed(mode)           _mode_is_signed(mode)
198 #define mode_is_float(mode)            _mode_is_float(mode)
199 #define mode_is_int(mode)              _mode_is_int(mode)
200 #define mode_is_reference(mode)        _mode_is_reference(mode)
201 #define mode_is_num(mode)              _mode_is_num(mode)
202 #define mode_is_data(mode)             _mode_is_data(mode)
203 #define mode_is_datab(mode)            _mode_is_datab(mode)
204 #define mode_is_dataM(mode)            _mode_is_dataM(mode)
205 #define mode_is_float_vector(mode)     _mode_is_float_vector(mode)
206 #define mode_is_int_vector(mode)       _mode_is_int_vector(mode)
207
208 #endif