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