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  */
26 #ifndef FIRM_IR_IRMODE_T_H
27 #define FIRM_IR_IRMODE_T_H
28 
29 #include <assert.h>
30 #include "irtypes.h"
31 #include "irmode.h"
32 
33 /* ------------------------------- *
34  * inline functions                *
35  * ------------------------------- */
get_modeP_code_(void)36 static inline ir_mode *get_modeP_code_(void) { return mode_P_code; }
37 
get_modeP_data_(void)38 static inline ir_mode *get_modeP_data_(void) { return mode_P_data; }
39 
get_mode_ident_(const ir_mode * mode)40 static inline ident *get_mode_ident_(const ir_mode *mode) { return mode->name; }
41 
get_mode_sort_(const ir_mode * mode)42 static inline ir_mode_sort get_mode_sort_(const ir_mode *mode) { return mode->sort; }
43 
get_mode_size_bits_(const ir_mode * mode)44 static inline unsigned get_mode_size_bits_(const ir_mode *mode) { return mode->size; }
45 
get_mode_size_bytes_(const ir_mode * mode)46 static inline unsigned get_mode_size_bytes_(const ir_mode *mode)
47 {
48 	unsigned size = get_mode_size_bits_(mode);
49 	if ((size & 7) != 0) return (unsigned) -1;
50 	return size >> 3;
51 }
52 
get_mode_sign_(const ir_mode * mode)53 static inline int get_mode_sign_(const ir_mode *mode) { return mode->sign; }
54 
get_mode_arithmetic_(const ir_mode * mode)55 static inline ir_mode_arithmetic get_mode_arithmetic_(const ir_mode *mode) { return mode->arithmetic; }
56 
get_mode_modulo_shift_(const ir_mode * mode)57 static inline unsigned int get_mode_modulo_shift_(const ir_mode *mode) { return mode->modulo_shift; }
58 
get_mode_link_(const ir_mode * mode)59 static inline void *get_mode_link_(const ir_mode *mode) { return mode->link; }
60 
set_mode_link_(ir_mode * mode,void * l)61 static inline void set_mode_link_(ir_mode *mode, void *l) { mode->link = l; }
62 
63 /* Functions to check, whether a mode is signed, float, int, num, data,
64    datab or dataM. For more exact definitions read the corresponding pages
65    in the firm documentation or the following enumeration
66 
67    The set of "float" is defined as:
68    ---------------------------------
69    float = {irm_F, irm_D, irm_E}
70 
71    The set of "int" is defined as:
72    -------------------------------
73    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
74 
75    The set of "num" is defined as:
76    -------------------------------
77    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
78             irm_Is, irm_Iu, irm_Ls, irm_Lu}
79             = {float || int}
80 
81    The set of "data" is defined as:
82    -------------------------------
83    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
84             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
85             = {num || irm_C || irm_U || irm_P}
86 
87    The set of "datab" is defined as:
88    ---------------------------------
89    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
90             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
91             = {data || irm_b }
92 
93    The set of "dataM" is defined as:
94    ---------------------------------
95    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
96             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
97             = {data || irm_M}
98 */
99 
mode_is_signed_(const ir_mode * mode)100 static inline int mode_is_signed_(const ir_mode *mode)
101 {
102 	return mode->sign;
103 }
104 
mode_is_float_(const ir_mode * mode)105 static inline int mode_is_float_(const ir_mode *mode)
106 {
107 	return (get_mode_sort_(mode) == irms_float_number);
108 }
109 
mode_is_int_(const ir_mode * mode)110 static inline int mode_is_int_(const ir_mode *mode)
111 {
112 	return (get_mode_sort_(mode) == irms_int_number);
113 }
114 
mode_is_reference_(const ir_mode * mode)115 static inline int mode_is_reference_(const ir_mode *mode)
116 {
117 	return (get_mode_sort_(mode) == irms_reference);
118 }
119 
mode_is_num_(const ir_mode * mode)120 static inline int mode_is_num_(const ir_mode *mode)
121 {
122 	return (get_mode_sort_(mode) & irmsh_is_num);
123 }
124 
mode_is_data_(const ir_mode * mode)125 static inline int mode_is_data_(const ir_mode *mode)
126 {
127 	return (get_mode_sort_(mode) & irmsh_is_data);
128 }
129 
mode_is_datab_(const ir_mode * mode)130 static inline int mode_is_datab_(const ir_mode *mode)
131 {
132 	return (get_mode_sort_(mode) & irmsh_is_datab);
133 }
134 
mode_is_dataM_(const ir_mode * mode)135 static inline int mode_is_dataM_(const ir_mode *mode)
136 {
137 	return (get_mode_sort_(mode) & irmsh_is_dataM);
138 }
139 
get_type_for_mode_(const ir_mode * mode)140 static inline ir_type *get_type_for_mode_(const ir_mode *mode)
141 {
142 	return mode->type;
143 }
144 
get_mode_mantissa_size_(const ir_mode * mode)145 static inline unsigned get_mode_mantissa_size_(const ir_mode *mode)
146 {
147 	return mode->float_desc.mantissa_size;
148 }
149 
get_mode_exponent_size_(const ir_mode * mode)150 static inline unsigned get_mode_exponent_size_(const ir_mode *mode)
151 {
152 	return mode->float_desc.exponent_size;
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_link(mode)            get_mode_link_(mode)
171 #define set_mode_link(mode, l)         set_mode_link_(mode, l)
172 #define mode_is_signed(mode)           mode_is_signed_(mode)
173 #define mode_is_float(mode)            mode_is_float_(mode)
174 #define mode_is_int(mode)              mode_is_int_(mode)
175 #define mode_is_reference(mode)        mode_is_reference_(mode)
176 #define mode_is_num(mode)              mode_is_num_(mode)
177 #define mode_is_data(mode)             mode_is_data_(mode)
178 #define mode_is_datab(mode)            mode_is_datab_(mode)
179 #define mode_is_dataM(mode)            mode_is_dataM_(mode)
180 #define get_type_for_mode(mode)        get_type_for_mode_(mode)
181 #define get_mode_mantissa_size(mode)   get_mode_mantissa_size_(mode)
182 #define get_mode_exponent_size(mode)   get_mode_exponent_size_(mode)
183 
184 #endif
185