Some more cleanup: Put the return type and other specifiers on the same line as the...
[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 *_get_modeP_code(void) { return mode_P_code; }
40
41 static inline ir_mode *_get_modeP_data(void) { return mode_P_data; }
42
43 static inline ident *_get_mode_ident(const ir_mode *mode) { return mode->name; }
44
45 static inline ir_mode_sort _get_mode_sort(const ir_mode *mode) { return mode->sort; }
46
47 static inline unsigned _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
48
49 static inline unsigned _get_mode_size_bytes(const ir_mode *mode)
50 {
51         unsigned size = _get_mode_size_bits(mode);
52         if ((size & 7) != 0) return (unsigned) -1;
53         return size >> 3;
54 }
55
56 static inline int _get_mode_sign(const ir_mode *mode) { return mode->sign; }
57
58 static inline ir_mode_arithmetic _get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
59
60 static inline unsigned int _get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
61
62 static inline unsigned int _get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
63
64 static inline void * _get_mode_link(const ir_mode *mode) { return mode->link; }
65
66 static inline void _set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
67
68 /* Functions to check, whether a mode is signed, float, int, num, data,
69    datab or dataM. For more exact definitions read the corresponding pages
70    in the firm documentation or the following enumeration
71
72    The set of "float" is defined as:
73    ---------------------------------
74    float = {irm_F, irm_D, irm_E}
75
76    The set of "int" is defined as:
77    -------------------------------
78    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
79
80    The set of "num" is defined as:
81    -------------------------------
82    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
83             irm_Is, irm_Iu, irm_Ls, irm_Lu}
84             = {float || int}
85
86    The set of "data" is defined as:
87    -------------------------------
88    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
89             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
90             = {num || irm_C || irm_U || irm_P}
91
92    The set of "datab" is defined as:
93    ---------------------------------
94    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
95             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
96             = {data || irm_b }
97
98    The set of "dataM" is defined as:
99    ---------------------------------
100    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
101             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
102             = {data || irm_M}
103 */
104
105 static inline int _mode_is_signed(const ir_mode *mode)
106 {
107         return mode->sign;
108 }
109
110 static inline int _mode_is_float(const ir_mode *mode)
111 {
112         return (_get_mode_sort(mode) == irms_float_number);
113 }
114
115 static inline int _mode_is_int(const ir_mode *mode)
116 {
117         return (_get_mode_sort(mode) == irms_int_number);
118 }
119
120 static inline int _mode_is_reference(const ir_mode *mode)
121 {
122         return (_get_mode_sort(mode) == irms_reference);
123 }
124
125 static inline int _mode_is_num(const ir_mode *mode)
126 {
127         return (_get_mode_sort(mode) & irmsh_is_num);
128 }
129
130 static inline int _mode_is_data(const ir_mode *mode)
131 {
132         return (_get_mode_sort(mode) & irmsh_is_data);
133 }
134
135 static inline int _mode_is_datab(const ir_mode *mode)
136 {
137         return (_get_mode_sort(mode) & irmsh_is_datab);
138 }
139
140 static inline int _mode_is_dataM(const ir_mode *mode)
141 {
142         return (_get_mode_sort(mode) & irmsh_is_dataM);
143 }
144
145 static inline int _mode_is_float_vector(const ir_mode *mode)
146 {
147         return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
148 }
149
150 static inline int _mode_is_int_vector(const ir_mode *mode)
151 {
152         return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
153 }
154
155 /** mode module initialization, call once before use of any other function **/
156 void init_mode(void);
157
158 /** mode module finalization. frees all memory.  */
159 void finish_mode(void);
160
161 #define get_modeP_code()               _get_modeP_code()
162 #define get_modeP_data()               _get_modeP_data()
163 #define get_mode_ident(mode)           _get_mode_ident(mode)
164 #define get_mode_sort(mode)            _get_mode_sort(mode)
165 #define get_mode_size_bits(mode)       _get_mode_size_bits(mode)
166 #define get_mode_size_bytes(mode)      _get_mode_size_bytes(mode)
167 #define get_mode_sign(mode)            _get_mode_sign(mode)
168 #define get_mode_arithmetic(mode)      _get_mode_arithmetic(mode)
169 #define get_mode_modulo_shift(mode)    _get_mode_modulo_shift(mode)
170 #define get_mode_n_vector_elems(mode)  _get_mode_vector_elems(mode)
171 #define get_mode_link(mode)            _get_mode_link(mode)
172 #define set_mode_link(mode, l)         _set_mode_link(mode, l)
173 #define mode_is_signed(mode)           _mode_is_signed(mode)
174 #define mode_is_float(mode)            _mode_is_float(mode)
175 #define mode_is_int(mode)              _mode_is_int(mode)
176 #define mode_is_reference(mode)        _mode_is_reference(mode)
177 #define mode_is_num(mode)              _mode_is_num(mode)
178 #define mode_is_data(mode)             _mode_is_data(mode)
179 #define mode_is_datab(mode)            _mode_is_datab(mode)
180 #define mode_is_dataM(mode)            _mode_is_dataM(mode)
181 #define mode_is_float_vector(mode)     _mode_is_float_vector(mode)
182 #define mode_is_int_vector(mode)       _mode_is_int_vector(mode)
183
184 #endif