6e79a80eda0e27fc622d396ed82f99975659424b
[libfirm] / ir / ir / irmode_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irmode_t.h
4  * Purpose:     Data modes of operations -- private header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier, Mathias Heil
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 /**
15  * @file irmode_t.h
16  */
17
18 # ifndef _IRMODE_T_H_
19 # define _IRMODE_T_H_
20
21 # include "irmode.h"
22 # include "tv.h"
23
24 /** This struct is supposed to completely define a mode. **/
25 struct ir_mode {
26   firm_kind         kind;       /**< distinguishes this node from others */
27   modecode          code;       /**< unambiguous identifier of a mode */
28   ident             *name;      /**< Name ident of this mode */
29
30   /* ----------------------------------------------------------------------- */
31   /* On changing this struct you have to evaluate the mode_are_equal function!*/
32   mode_sort         sort;          /**< coarse classification of this mode:
33                                      int, float, reference ...
34                                      (see irmode.h) */
35   mode_arithmetic   arithmetic;    /**< different arithmetic operations possible with a mode */
36   int               size;          /**< size of the mode in Bits. */
37   unsigned          sign:1;        /**< signedness of this mode */
38   unsigned int      modulo_shift;  /**< number of bits a values of this mode will be shifted */
39   unsigned          vector_elem;   /**< if this is not equal 1, this is a vector mode with
40                                         vector_elem number of elements, size contains the size
41                                         of all bits and must be dividable by vector_elem */
42
43   /* ----------------------------------------------------------------------- */
44   tarval            *min;       /**< the minimum value that can be expressed */
45   tarval            *max;       /**< the maximum value that can be expressed */
46   tarval            *null;      /**< the value 0 */
47   tarval            *one;       /**< the value 1 */
48   tarval            *minus_one; /**< the value -1 */
49   void              *link;      /**< To store some intermediate information */
50   const void        *tv_priv;   /**< tarval module will save private data here */
51 };
52
53
54 /* ------------------------------- *
55  * inline functions                *
56  * ------------------------------- */
57 extern ir_mode *mode_P_mach;
58
59 static INLINE ir_mode *
60 _get_modeP_mach(void) { return mode_P_mach; }
61
62 static INLINE void
63 _set_modeP_mach(ir_mode *p) {
64   assert(mode_is_reference(p));
65   mode_P_mach = p;
66 }
67
68 static INLINE modecode
69 _get_mode_modecode(const ir_mode *mode) { return mode->code; }
70
71 static INLINE ident *
72 _get_mode_ident(const ir_mode *mode) { return mode->name; }
73
74 static INLINE mode_sort
75 _get_mode_sort(const ir_mode* mode) { return mode->sort; }
76
77 static INLINE int
78 _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
79
80 static INLINE int
81 _get_mode_size_bytes(const ir_mode *mode) {
82   int size = _get_mode_size_bits(mode);
83   if ((size & 7) != 0) return -1;
84   return size >> 3;
85 }
86
87 static INLINE int
88 _get_mode_sign(const ir_mode *mode) { return mode->sign; }
89
90 static INLINE int
91 _get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
92
93 static INLINE unsigned int
94 _get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
95
96 static INLINE unsigned int
97 _get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
98
99 static INLINE void *
100 _get_mode_link(const ir_mode *mode) { return mode->link; }
101
102 static INLINE void
103 _set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
104
105 /* Functions to check, whether a modecode is signed, float, int, num, data,
106    datab or dataM. For more exact definitions read the corresponding pages
107    in the firm documentation or the followingenumeration
108
109    The set of "float" is defined as:
110    ---------------------------------
111    float = {irm_F, irm_D, irm_E}
112
113    The set of "int" is defined as:
114    -------------------------------
115    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
116
117    The set of "num" is defined as:
118    -------------------------------
119    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
120             irm_Is, irm_Iu, irm_Ls, irm_Lu}
121             = {float || int}
122
123    The set of "data" is defined as:
124    -------------------------------
125    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
126             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
127             = {num || irm_C || irm_U || irm_P}
128
129    The set of "datab" is defined as:
130    ---------------------------------
131    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
132             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
133             = {data || irm_b }
134
135    The set of "dataM" is defined as:
136    ---------------------------------
137    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
138             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
139             = {data || irm_M}
140 */
141
142 static INLINE int
143 _mode_is_signed(const ir_mode *mode) {
144   assert(mode);
145   return mode->sign;
146 }
147
148 static INLINE int
149 _mode_is_float(const ir_mode *mode) {
150   assert(mode);
151   return (_get_mode_sort(mode) == irms_float_number);
152 }
153
154 static INLINE int
155 _mode_is_int(const ir_mode *mode) {
156   assert(mode);
157   return (_get_mode_sort(mode) == irms_int_number);
158 }
159
160 static INLINE int
161 _mode_is_character(const ir_mode *mode) {
162   assert(mode);
163   return (_get_mode_sort(mode) == irms_character);
164 }
165
166 static INLINE int
167 _mode_is_reference(const ir_mode *mode) {
168   assert(mode);
169   return (_get_mode_sort(mode) == irms_reference);
170 }
171
172 static INLINE int
173 _mode_is_num(const ir_mode *mode) {
174   assert(mode);
175   return (_mode_is_int(mode) || _mode_is_float(mode));
176 }
177
178 static INLINE int
179 _mode_is_numP(const ir_mode *mode) {
180   assert(mode);
181   return (_mode_is_int(mode) || _mode_is_float(mode) || _mode_is_reference(mode));
182 }
183
184 static INLINE int
185 _mode_is_data(const ir_mode *mode) {
186   assert(mode);
187   return (_mode_is_num(mode) || _get_mode_sort(mode) == irms_character || _get_mode_sort(mode) == irms_reference);
188 }
189
190 static INLINE int
191 _mode_is_datab(const ir_mode *mode) {
192   assert(mode);
193   return (_mode_is_data(mode) || _get_mode_sort(mode) == irms_internal_boolean);
194 }
195
196 static INLINE int
197 _mode_is_dataM(const ir_mode *mode) {
198   assert(mode);
199   return (_mode_is_data(mode) || _get_mode_modecode(mode) == irm_M);
200 }
201
202 static INLINE int
203 _mode_is_float_vector(const ir_mode *mode) {
204   assert(mode);
205   return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
206 }
207
208 static INLINE int
209 _mode_is_int_vector(const ir_mode *mode) {
210   assert(mode);
211   return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
212 }
213
214 /** mode module initialization, call once before use of any other function **/
215 void init_mode(void);
216
217 /** mode module finalization. frees all memory.  */
218 void finish_mode(void);
219
220 #define get_modeP_mach()               _get_modeP_mach()
221 #define set_modeP_mach(p)              _set_modeP_mach(p)
222 #define get_mode_modecode(mode)        _get_mode_modecode(mode)
223 #define get_mode_ident(mode)           _get_mode_ident(mode)
224 #define get_mode_sort(mode)            _get_mode_sort(mode)
225 #define get_mode_size_bits(mode)       _get_mode_size_bits(mode)
226 #define get_mode_size_bytes(mode)      _get_mode_size_bytes(mode)
227 #define get_mode_sign(mode)            _get_mode_sign(mode)
228 #define get_mode_arithmetic(mode)      _get_mode_arithmetic(mode)
229 #define get_mode_modulo_shift(mode)    _get_mode_modulo_shift(mode)
230 #define get_mode_n_vector_elems(mode)  _get_mode_vector_elems(mode)
231 #define get_mode_link(mode)            _get_mode_link(mode)
232 #define set_mode_link(mode, l)         _set_mode_link(mode, l)
233 #define mode_is_signed(mode)           _mode_is_signed(mode)
234 #define mode_is_float(mode)            _mode_is_float(mode)
235 #define mode_is_int(mode)              _mode_is_int(mode)
236 #define mode_is_character(mode)        _mode_is_character(mode)
237 #define mode_is_reference(mode)        _mode_is_reference(mode)
238 #define mode_is_num(mode)              _mode_is_num(mode)
239 #define mode_is_numP(mode)             _mode_is_numP(mode)
240 #define mode_is_data(mode)             _mode_is_data(mode)
241 #define mode_is_datab(mode)            _mode_is_datab(mode)
242 #define mode_is_dataM(mode)            _mode_is_dataM(mode)
243 #define mode_is_float_vector(mode)     _mode_is_float_vector(mode)
244 #define mode_is_int_vector(mode)       _mode_is_int_vector(mode)
245
246 #endif /* _IRMODE_T_H_ */