Fixed some warning about unused variables.
[libfirm] / ir / tr / entity_t.h
1 /*
2  * Copyright (C) 1995-2011 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   Representation of all program known entities -- private header.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  */
26 #ifndef FIRM_TR_ENTITY_T_H
27 #define FIRM_TR_ENTITY_T_H
28
29 #include <assert.h>
30
31 #include "typerep.h"
32 #include "type_t.h"
33 #include "ident.h"
34 #include "compound_path.h"
35
36 typedef struct ir_initializer_base_t {
37         ir_initializer_kind_t kind;
38 } ir_initializer_base_t;
39
40 /**
41  * An compound initializer.
42  */
43 typedef struct ir_initializer_compound_t {
44         ir_initializer_base_t  base;
45         size_t                 n_initializers;
46         ir_initializer_t      *initializers[1];
47 } ir_initializer_compound_t;
48
49 /**
50  * An initializer containing an ir_node,
51  */
52 typedef struct ir_initializer_const_t {
53         ir_initializer_base_t  base;
54         ir_node               *value;
55 } ir_initializer_const_t ;
56
57 /**
58  * An initializer containing a tarval.
59  */
60 typedef struct ir_initializer_tarval_t {
61         ir_initializer_base_t  base;
62         ir_tarval             *value;
63 } ir_initializer_tarval_t ;
64
65 union ir_initializer_t {
66         ir_initializer_kind_t      kind;
67         ir_initializer_base_t      base;
68         ir_initializer_compound_t  compound;
69         ir_initializer_const_t     consti;
70         ir_initializer_tarval_t    tarval;
71 };
72
73 /** The attributes for compound entities. */
74 typedef struct compound_ent_attr {
75         ir_node **values;     /**< constant values of compound entities. */
76         compound_graph_path **val_paths;
77                              /**< paths corresponding to constant values. */
78 } compound_ent_attr;
79
80 /** The attributes for methods. */
81 typedef struct method_ent_attr {
82         ir_graph *irg;                 /**< The corresponding irg if known.
83                                             The ir_graph constructor automatically sets this field. */
84         mtp_additional_properties irg_add_properties;   /**< Additional graph properties can be
85                                             stored in a entity if no irg is available. */
86
87         unsigned vtable_number;        /**< For a dynamically called method, the number assigned
88                                             in the virtual function table. */
89
90         ptr_access_kind *param_access; /**< the parameter access */
91         unsigned *param_weight;        /**< The weight of method's parameters. Parameters
92                                             with a high weight are good candidates for procedure cloning. */
93 } method_ent_attr;
94
95 /** additional attributes for code entities */
96 typedef struct code_ent_attr {
97         ir_label_t  label;       /** label of the basic block */
98 } code_ent_attr;
99
100
101 /**
102  * An abstract data type to represent program entities.
103  *
104  * @see  ir_type
105  */
106 struct ir_entity {
107         firm_kind kind;       /**< The dynamic type tag for entity. */
108         ident *name;          /**< The name of this entity. */
109         ident *ld_name;       /**< Unique name of this entity, i.e., the mangled
110                                    name.  If the field is read before written a default
111                                    mangling is applies.  The name of the owner is prepended
112                                    to the name of the entity, separated by a underscore.
113                                    E.g.,  for a class `A' with field `a' this
114                                    is the ident for `A_a'. */
115         ir_type *type;        /**< The type of this entity, e.g., a method type, a
116                                    basic type of the language or a class itself. */
117         ir_type *owner;       /**< The compound type (e.g. class type) this entity belongs to. */
118         unsigned linkage:10;        /**< Specifies linkage type */
119         unsigned volatility:1;      /**< Specifies volatility of entities content.*/
120         unsigned aligned:1;         /**< Specifies alignment of entities content. */
121         unsigned usage:4;           /**< flag indicating usage types of this entity,
122                                          see ir_entity_usage. */
123         unsigned compiler_gen:1;    /**< If set, this entity was compiler generated.
124                                      */
125         unsigned visibility:3;      /**< @deprecated */
126         unsigned allocation:3;      /**< @deprecated */
127         unsigned peculiarity:3;     /**< @deprecated */
128         unsigned final:1;           /**< @deprecated */
129         int offset;                 /**< Offset in bytes for this entity. Fixed
130                                          when layout of owner is determined. */
131         unsigned alignment;         /**< entity alignment in bytes */
132         unsigned char offset_bit_remainder;
133                                     /**< If the entity is a bit field, this is the
134                                          offset of the start of the bit field
135                                          within the byte specified by offset. */
136         ir_visited_t visit;         /**< visited counter for walks of the type
137                                          information. */
138         struct dbg_info *dbi;       /**< A pointer to information for debug support.
139                                      */
140         void *link;                 /**< To store some intermediate information. */
141         ir_type *repr_class;        /**< If this entity represents a class info, the
142                                          associated class. */
143
144         /* ------------- fields for entities owned by a class type ---------------*/
145
146         ir_entity **overwrites;     /**< A list of entities this entity overwrites.
147                                      */
148         ir_entity **overwrittenby;  /**< A list of entities that overwrite this
149                                          entity. */
150
151         /* ------------- fields for atomic entities  --------------- */
152         ir_initializer_t *initializer; /**< entity initializer */
153         union {
154                 /* ------------- fields for compound entities -------------- */
155                 compound_ent_attr cmpd_attr;
156                 /* ------------- fields for method entities ---------------- */
157                 method_ent_attr   mtd_attr;
158                 /* fields for code entities */
159                 code_ent_attr     code_attr;
160         } attr; /**< type specific attributes */
161
162         /* ------------- fields for analyses ---------------*/
163
164 #ifdef DEBUG_libfirm
165         long nr;             /**< A unique node number for each node to make output
166                                   readable. */
167 #endif
168 };
169
170 /** Initialize the entity module. */
171 void ir_init_entity(void);
172 /** Cleanup entity module */
173 void ir_finish_entity(void);
174
175 /* ----------------------- inline functions ------------------------ */
176 static inline int _is_entity(const void *thing)
177 {
178         return get_kind(thing) == k_entity;
179 }
180
181 static inline const char *_get_entity_name(const ir_entity *ent)
182 {
183         assert(ent && ent->kind == k_entity);
184         return get_id_str(get_entity_ident(ent));
185 }
186
187 static inline ident *_get_entity_ident(const ir_entity *ent)
188 {
189         assert(ent && ent->kind == k_entity);
190         return ent->name;
191 }
192
193 static inline void _set_entity_ident(ir_entity *ent, ident *id)
194 {
195         assert(ent && ent->kind == k_entity);
196         ent->name = id;
197 }
198
199 static inline ir_type *_get_entity_owner(const ir_entity *ent)
200 {
201         assert(ent && ent->kind == k_entity);
202         return ent->owner;
203 }
204
205 static inline ident *_get_entity_ld_ident(const ir_entity *ent)
206 {
207         assert(ent && ent->kind == k_entity);
208         if (ent->ld_name == NULL)
209                 return ent->name;
210         return ent->ld_name;
211 }
212
213 static inline void _set_entity_ld_ident(ir_entity *ent, ident *ld_ident)
214 {
215         assert(ent && ent->kind == k_entity);
216         ent->ld_name = ld_ident;
217 }
218
219 static inline const char *_get_entity_ld_name(const ir_entity *ent)
220 {
221         assert(ent && ent->kind == k_entity);
222         return get_id_str(get_entity_ld_ident(ent));
223 }
224
225 static inline ir_type *_get_entity_type(const ir_entity *ent)
226 {
227         assert(ent && ent->kind == k_entity);
228         return ent->type;
229 }
230
231 static inline void _set_entity_type(ir_entity *ent, ir_type *type)
232 {
233         assert(ent && ent->kind == k_entity);
234         ent->type = type;
235 }
236
237 static inline ir_linkage _get_entity_linkage(const ir_entity *ent)
238 {
239         assert(ent && ent->kind == k_entity);
240         return (ir_linkage) ent->linkage;
241 }
242
243 static inline ir_volatility _get_entity_volatility(const ir_entity *ent)
244 {
245         assert(ent && ent->kind == k_entity);
246         return (ir_volatility) ent->volatility;
247 }
248
249 static inline void _set_entity_volatility(ir_entity *ent, ir_volatility vol)
250 {
251         assert(ent && ent->kind == k_entity);
252         ent->volatility = vol;
253 }
254
255 static inline unsigned _get_entity_alignment(const ir_entity *ent)
256 {
257         assert(ent && ent->kind == k_entity);
258         return ent->alignment;
259 }
260
261 static inline void _set_entity_alignment(ir_entity *ent, unsigned alignment)
262 {
263         assert(ent && ent->kind == k_entity);
264         ent->alignment = alignment;
265 }
266
267 static inline ir_align _get_entity_aligned(const ir_entity *ent)
268 {
269         assert(ent && ent->kind == k_entity);
270         return (ir_align) ent->aligned;
271 }
272
273 static inline void _set_entity_aligned(ir_entity *ent, ir_align a)
274 {
275         assert(ent && ent->kind == k_entity);
276         ent->aligned = a;
277 }
278
279 static inline int _is_entity_compiler_generated(const ir_entity *ent)
280 {
281         assert(ent && ent->kind == k_entity);
282         return ent->compiler_gen;
283 }
284
285 static inline void _set_entity_compiler_generated(ir_entity *ent, int flag)
286 {
287         assert(ent && ent->kind == k_entity);
288         ent->compiler_gen = flag ? 1 : 0;
289 }
290
291 static inline ir_entity_usage _get_entity_usage(const ir_entity *ent)
292 {
293         assert(ent && ent->kind == k_entity);
294         return (ir_entity_usage) ent->usage;
295 }
296
297 static inline void _set_entity_usage(ir_entity *ent, ir_entity_usage state)
298 {
299         assert(ent && ent->kind == k_entity);
300         ent->usage = state;
301 }
302
303 static inline int _get_entity_offset(const ir_entity *ent)
304 {
305         assert(ent && ent->kind == k_entity);
306         return ent->offset;
307 }
308
309 static inline void _set_entity_offset(ir_entity *ent, int offset)
310 {
311         assert(ent && ent->kind == k_entity);
312         ent->offset = offset;
313 }
314
315 static inline unsigned char _get_entity_offset_bits_remainder(const ir_entity *ent)
316 {
317         assert(ent && ent->kind == k_entity);
318         return ent->offset_bit_remainder;
319 }
320
321 static inline void _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset)
322 {
323         assert(ent && ent->kind == k_entity);
324         ent->offset_bit_remainder = offset;
325 }
326
327 static inline void *_get_entity_link(const ir_entity *ent)
328 {
329         assert(ent && ent->kind == k_entity);
330         return ent->link;
331 }
332
333 static inline void _set_entity_link(ir_entity *ent, void *l)
334 {
335         assert(ent && ent->kind == k_entity);
336         ent->link = l;
337 }
338
339 static inline ir_graph *_get_entity_irg(const ir_entity *ent)
340 {
341         assert(ent && ent->kind == k_entity);
342         if (!is_Method_type(ent->type) || ent == unknown_entity) {
343                 return NULL;
344         }
345
346         return ent->attr.mtd_attr.irg;
347 }
348
349 static inline ir_visited_t _get_entity_visited(const ir_entity *ent)
350 {
351         assert(ent && ent->kind == k_entity);
352         return ent->visit;
353 }
354
355 static inline void _set_entity_visited(ir_entity *ent, ir_visited_t num)
356 {
357         assert(ent && ent->kind == k_entity);
358         ent->visit = num;
359 }
360
361 static inline void _mark_entity_visited(ir_entity *ent)
362 {
363         assert(ent && ent->kind == k_entity);
364         ent->visit = firm_type_visited;
365 }
366
367 static inline int _entity_visited(const ir_entity *ent)
368 {
369         return _get_entity_visited(ent) >= firm_type_visited;
370 }
371
372 static inline int _entity_not_visited(const ir_entity *ent)
373 {
374         return _get_entity_visited(ent) < firm_type_visited;
375 }
376
377 static inline ir_type *_get_entity_repr_class(const ir_entity *ent)
378 {
379         assert(ent && ent->kind == k_entity);
380         return ent->repr_class;
381 }
382
383 static inline dbg_info *_get_entity_dbg_info(const ir_entity *ent)
384 {
385         return ent->dbi;
386 }
387
388 static inline void _set_entity_dbg_info(ir_entity *ent, dbg_info *db)
389 {
390         ent->dbi = db;
391 }
392
393 #define is_entity(thing)                         _is_entity(thing)
394 #define get_entity_name(ent)                     _get_entity_name(ent)
395 #define get_entity_ident(ent)                    _get_entity_ident(ent)
396 #define set_entity_ident(ent, id)                _set_entity_ident(ent, id)
397 #define get_entity_owner(ent)                    _get_entity_owner(ent)
398 #define get_entity_ld_ident(ent)                 _get_entity_ld_ident(ent)
399 #define set_entity_ld_ident(ent, ld_ident)       _set_entity_ld_ident(ent, ld_ident)
400 #define get_entity_ld_name(ent)                  _get_entity_ld_name(ent)
401 #define get_entity_type(ent)                     _get_entity_type(ent)
402 #define set_entity_type(ent, type)               _set_entity_type(ent, type)
403 #define get_entity_linkage(ent)                  _get_entity_linkage(ent)
404 #define get_entity_volatility(ent)               _get_entity_volatility(ent)
405 #define set_entity_volatility(ent, vol)          _set_entity_volatility(ent, vol)
406 #define set_entity_alignment(ent, alignment)     _set_entity_alignment(ent, alignment)
407 #define get_entity_alignment(ent)                _get_entity_alignment(ent)
408 #define get_entity_align(ent)                    _get_entity_align(ent)
409 #define set_entity_align(ent, a)                 _set_entity_align(ent, a)
410 #define is_entity_compiler_generated(ent)        _is_entity_compiler_generated(ent)
411 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
412 #define get_entity_usage(ent)                    _get_entity_usage(ent)
413 #define set_entity_usage(ent, flags)             _set_entity_usage(ent, flags)
414 #define get_entity_offset(ent)                   _get_entity_offset(ent)
415 #define set_entity_offset(ent, offset)           _set_entity_offset(ent, offset)
416 #define get_entity_offset_bits_remainder(ent)    _get_entity_offset_bits_remainder(ent)
417 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
418 #define get_entity_link(ent)                     _get_entity_link(ent)
419 #define set_entity_link(ent, l)                  _set_entity_link(ent, l)
420 #define get_entity_irg(ent)                      _get_entity_irg(ent)
421 #define get_entity_visited(ent)                  _get_entity_visited(ent)
422 #define set_entity_visited(ent, num)             _set_entity_visited(ent, num)
423 #define mark_entity_visited(ent)                 _mark_entity_visited(ent)
424 #define entity_visited(ent)                      _entity_visited(ent)
425 #define entity_not_visited(ent)                  _entity_not_visited(ent)
426 #define get_entity_repr_class(ent)               _get_entity_repr_class(ent)
427 #define get_entity_dbg_info(ent)                 _get_entity_dbg_info(ent)
428 #define set_entity_dbg_info(ent, db)             _set_entity_dbg_info(ent, db)
429
430 #endif