fixed config.h include
[libfirm] / ir / tr / entity_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/entity_t.h
4  * Purpose:     Representation of all program known entities -- private header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier
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  * @file entity_t.h
15  *
16  * entity.h:  entities represent all program known objects.
17  *
18  * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier
19  *
20  *  An entity is the representation of program known objects in Firm.
21  *  The primary concept of entities is to represent members of complex
22  *  types, i.e., fields and methods of classes.  As not all programming
23  *  language model all variables and methods as members of some class,
24  *  the concept of entities is extended to cover also local and global
25  *  variables, and arbitrary procedures.
26  *
27  *  An entity always specifies the type of the object it represents and
28  *  the type of the object it is a part of, the owner of the entity.
29  *  Originally this is the type of the class of which the entity is a
30  *  member.
31  *  The owner of local variables is the procedure they are defined in.
32  *  The owner of global variables and procedures visible in the whole
33  *  program is a universally defined class type "GlobalType".  The owner
34  *  of procedures defined in the scope of an other procedure is the
35  *  enclosing procedure.
36  */
37
38 # ifndef _ENTITY_T_H_
39 # define _ENTITY_T_H_
40
41 #include "firm_common_t.h"
42
43 # include "entity.h"
44 # include "typegmod.h"
45 # include "mangle.h"
46 # include "pseudo_irg.h"
47
48
49 /** A path in a compund graph. */
50 struct compound_graph_path {
51   firm_kind kind;       /**< dynamic type tag for compound graph path. */
52   type *tp;             /**< The type this path belongs to. */
53   int len;              /**< length of the path */
54   int *arr_indicees;    /**< List of array indicees.  To compute position of
55                  array elements */
56   entity *nodes[1];     /**< List of entities of length len to express the
57                  access path. */
58 };
59
60 /** the type of an entity */
61 struct entity {
62   firm_kind kind;       /**< dynamic type tag for entity. */
63   ident *name;          /**< name of this entity */
64   ident *ld_name;       /**< Unique name of this entity, i.e., the mangled
65                            name.  If the field is read before written a default
66                            magling is applies.  The name of the owner is prepended
67                            to the name of the entity, separated by a underscore.
68                            E.g.,  for a class `A' with field `a' this
69                            is the ident for `A_a'. */
70   type *type;           /**< The type of this entity, e.g., a method type, a
71                            basic type of the language or a class itself */
72   type *owner;          /**< The compound type (e.g. class type) this entity belongs to. */
73   ent_allocation allocation;  /**< Distinguishes static and dynamically allocated
74                  entities and some further cases. */
75   ent_visibility visibility;  /**< Specifies visibility to external program
76                  fragments */
77   ent_variability variability;  /**< Specifies variability of entities content */
78   ent_volatility volatility;    /**< Specifies volatility of entities content */
79   ent_stickyness stickyness;    /**< Specifies whether this entity is sticky  */
80   int  offset;          /**< Offset in bits for this entity.  Fixed when layout
81                of owner is determined.  */
82   void *link;           /**< To store some intermediate information */
83   unsigned long visit;  /**< visited counter for walks of the type information */
84   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
85
86   /* ------------- fields for atomic entities  ---------------*/
87
88   ir_node *value;            /**< value if entity is not of variability uninitialized.
89                                Only for atomic entities. */
90
91   /* ------------- fields for compound entities ---------------*/
92
93   ir_node **values;     /**< constant values of compound entities. Only available if
94                variablility not uninitialized.  Must be set for variability constant
95                            */
96   compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
97                       variablility not uninitialized.  Must be set for variability constant */
98
99   /* ------------- fields for entities owned by a class type ---------------*/
100
101   entity **overwrites;     /**< A list of entities this entity overwrites. */
102   entity **overwrittenby;  /**< A list of entities that overwrite this entity.  */
103
104   /* ------------- fields for methods ---------------*/
105
106   enum peculiarity peculiarity;
107   ir_graph *irg;        /**< If (type == method_type) this is the corresponding irg.
108                The ir_graph constructor automatically sets this field.
109                Yes, it must be here. */
110
111   /* ------------- fields for analyses ---------------*/
112
113
114 #ifdef DEBUG_libfirm
115   int nr;             /**< a unique node number for each node to make output
116              readable. */
117   char *c_name;                 /**< Since idents are ipaque, provide the name in cleartext */
118 # endif /* DEBUG_libfirm */
119 };
120
121
122
123 /* ----------------------- inline functions ------------------------ */
124 static INLINE int
125 __is_entity(const void *thing) {
126   return get_kind(thing) == k_entity;
127 }
128
129 static INLINE const char *
130 __get_entity_name(const entity *ent) {
131   assert(ent && ent->kind == k_entity);
132   return get_id_str(get_entity_ident(ent));
133 }
134
135 static INLINE ident *
136 __get_entity_ident(const entity *ent) {
137   assert(ent && ent->kind == k_entity);
138   return ent->name;
139 }
140
141 static INLINE type *
142 __get_entity_owner(entity *ent) {
143   assert(ent && ent->kind == k_entity);
144   return ent->owner = skip_tid(ent->owner);
145 }
146
147 static INLINE ident *
148 __get_entity_ld_ident(entity *ent)
149 {
150   assert(ent && ent->kind == k_entity);
151   if (ent->ld_name == NULL)
152     ent->ld_name = mangle_entity(ent);
153   return ent->ld_name;
154 }
155
156 static INLINE void
157 __set_entity_ld_ident(entity *ent, ident *ld_ident) {
158   assert(ent && ent->kind == k_entity);
159   ent->ld_name = ld_ident;
160 }
161
162 static INLINE const char *
163 __get_entity_ld_name(entity *ent) {
164   assert(ent && ent->kind == k_entity);
165   return get_id_str(get_entity_ld_ident(ent));
166 }
167
168 static INLINE type *
169 __get_entity_type(entity *ent) {
170   assert(ent && ent->kind == k_entity);
171   return ent->type = skip_tid(ent->type);
172 }
173
174 static INLINE void
175 __set_entity_type(entity *ent, type *type) {
176   assert(ent && ent->kind == k_entity);
177   ent->type = type;
178 }
179
180 static INLINE ent_allocation
181 __get_entity_allocation(const entity *ent) {
182   assert(ent && ent->kind == k_entity);
183   return ent->allocation;
184 }
185
186 static INLINE void
187 __set_entity_allocation(entity *ent, ent_allocation al) {
188   assert(ent && ent->kind == k_entity);
189   ent->allocation = al;
190 }
191
192 static INLINE ent_visibility
193 __get_entity_visibility(const entity *ent) {
194   assert(ent && ent->kind == k_entity);
195   return ent->visibility;
196 }
197
198 static INLINE ent_variability
199 __get_entity_variability(const entity *ent) {
200   assert(ent && ent->kind == k_entity);
201   return ent->variability;
202 }
203
204 static INLINE ent_volatility
205 __get_entity_volatility(const entity *ent) {
206   assert(ent && ent->kind == k_entity);
207   return ent->volatility;
208 }
209
210 static INLINE void
211 __set_entity_volatility(entity *ent, ent_volatility vol) {
212   assert(ent && ent->kind == k_entity);
213   ent->volatility = vol;
214 }
215
216 static INLINE peculiarity
217 __get_entity_peculiarity(const entity *ent) {
218   assert(ent && ent->kind == k_entity);
219   return ent->peculiarity;
220 }
221
222 /**
223  * @todo why peculiarity only for methods
224  */
225 static INLINE void
226 __set_entity_peculiarity(entity *ent, peculiarity pec) {
227   assert(ent && ent->kind == k_entity);
228   /* @@@ why peculiarity only for methods? */
229   assert(is_method_type(ent->type));
230
231   ent->peculiarity = pec;
232 }
233
234 static INLINE ent_stickyness
235 __get_entity_stickyness(const entity *ent) {
236   assert(ent && ent->kind == k_entity);
237   return ent->stickyness;
238 }
239
240 static INLINE void
241 __set_entity_stickyness(entity *ent, ent_stickyness stickyness)
242 {
243   assert(ent && ent->kind == k_entity);
244   ent->stickyness = stickyness;
245 }
246
247 static INLINE int
248 __get_entity_offset_bits(const entity *ent) {
249   assert(ent && ent->kind == k_entity);
250   return ent->offset;
251 }
252
253 static INLINE int
254 __get_entity_offset_bytes(const entity *ent) {
255   int bits = __get_entity_offset_bits(ent);
256
257   if (bits & 7) return -1;
258   return bits >> 3;
259 }
260
261 static INLINE void
262 __set_entity_offset_bits(entity *ent, int offset) {
263   assert(ent && ent->kind == k_entity);
264   ent->offset = offset;
265 }
266
267 static INLINE void
268 __set_entity_offset_bytes(entity *ent, int offset) {
269   __set_entity_offset_bits(ent, offset * 8);
270 }
271
272 static INLINE void *
273 __get_entity_link(const entity *ent) {
274   assert(ent && ent->kind == k_entity);
275   return ent->link;
276 }
277
278 static INLINE void
279 __set_entity_link(entity *ent, void *l) {
280   assert(ent && ent->kind == k_entity);
281   ent->link = l;
282 }
283
284 static INLINE ir_graph *
285 __get_entity_irg(const entity *ent) {
286   assert(ent && ent->kind == k_entity);
287   assert(ent == unknown_entity || is_method_type(ent->type));
288   if (!get_visit_pseudo_irgs() && ent->irg && is_pseudo_ir_graph(ent->irg))
289     return NULL;
290   return ent->irg;
291 }
292
293 #define is_entity(thing)                        __is_entity(thing)
294 #define get_entity_name(ent)                    __get_entity_name(ent)
295 #define get_entity_ident(ent)                   __get_entity_ident(ent)
296 #define get_entity_owner(ent)                   __get_entity_owner(ent)
297 #define get_entity_ld_ident(ent)                __get_entity_ld_ident(ent)
298 #define set_entity_ld_ident(ent, ld_ident)      __set_entity_ld_ident(ent, ld_ident)
299 #define get_entity_ld_name(ent)                 __get_entity_ld_name(ent)
300 #define get_entity_type(ent)                    __get_entity_type(ent)
301 #define set_entity_type(ent, type)              __set_entity_type(ent, type)
302 #define get_entity_allocation(ent)              __get_entity_allocation(ent)
303 #define set_entity_allocation(ent, al)          __set_entity_allocation(ent, al)
304 #define get_entity_visibility(ent)              __get_entity_visibility(ent)
305 #define get_entity_variability(ent)             __get_entity_variability(ent)
306 #define get_entity_volatility(ent)              __get_entity_volatility(ent)
307 #define set_entity_volatility(ent, vol)         __set_entity_volatility(ent, vol)
308 #define get_entity_peculiarity(ent)             __get_entity_peculiarity(ent)
309 #define set_entity_peculiarity(ent, pec)        __set_entity_peculiarity(ent, pec)
310 #define get_entity_stickyness(ent)              __get_entity_stickyness(ent)
311 #define set_entity_stickyness(ent, stickyness)  __set_entity_stickyness(ent, stickyness)
312 #define get_entity_offset_bits(ent)             __get_entity_offset_bits(ent)
313 #define get_entity_offset_bytes(ent)            __get_entity_offset_bytes(ent)
314 #define set_entity_offset_bits(ent, offset)     __set_entity_offset_bits(ent, offset)
315 #define set_entity_offset_bytes(ent, offset)    __set_entity_offset_bytes(ent, offset)
316 #define get_entity_link(ent)                    __get_entity_link(ent)
317 #define set_entity_link(ent, l)                 __set_entity_link(ent, l)
318 #define get_entity_irg(ent)                     __get_entity_irg(ent)
319
320 # endif /* _ENTITY_T_H_ */