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