bugfix
[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 "entity.h"
42 # include "typegmod.h"
43 # include "mangle.h"
44
45 /** A path in a compund graph. */
46 struct compound_graph_path {
47   firm_kind kind;       /**< dynamic type tag for compound graph path. */
48   type *tp;
49   int len;
50   entity *nodes[1];
51 };
52
53 /** the type of an entity */
54 struct entity {
55   firm_kind kind;       /**< dynamic type tag for entity. */
56   ident *name;          /**< name of this entity */
57   ident *ld_name;       /**< Unique name of this entity, i.e., the mangled
58                            name.  If the field is read before written a default
59                            magling is applies.  The name of the owner is prepended
60                            to the name of the entity, separated by a underscore.
61                            E.g.,  for a class `A' with field `a' this
62                            is the ident for `A_a'. */
63   type *type;           /**< The type of this entity, e.g., a method type, a
64                            basic type of the language or a class itself */
65   type *owner;          /**< The compound type (e.g. class type) this entity belongs to. */
66   ent_allocation allocation;  /**< Distinguishes static and dynamically allocated
67                  entities and some further cases. */
68   ent_visibility visibility;  /**< Specifies visibility to external program
69                  fragments */
70   ent_variability variability;  /**< Specifies variability of entities content */
71   ent_volatility volatility;    /**< Specifies volatility of entities content */
72   ent_stickyness stickyness;    /**< Specifies whether this entity is sticky  */
73   int  offset;          /**< Offset in bits for this entity.  Fixed when layout
74                            of owner is determined.  */
75   void *link;           /**< To store some intermediate information */
76   unsigned long visit;  /**< visited counter for walks of the type information */
77   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
78
79   /* ------------- fields for atomic entities  ---------------*/
80   ir_node *value;            /**< value if entity is not of variability uninitialized.
81                                Only for atomic entities. */
82
83   /* ------------- fields for compound entities ---------------*/
84   ir_node **values;     /**< constant values of compound entities. Only available if
85                           variablility not uninitialized.  Must be set for variability constant
86                            */
87   compound_graph_path **val_paths;    /**< paths corresponding to constant values. Only available if
88                           variablility not uninitialized.  Must be set for variability constant */
89
90   /* ------------- fields for entities owned by a class type ---------------*/
91   entity **overwrites;  /**< A list of entities this entity overwrites. */
92   entity **overwrittenby;  /**< A list of entities that overwrite this entity.  */
93
94   /* ------------- fields for methods ---------------*/
95   enum peculiarity peculiarity;
96   ir_graph *irg;        /**< If (type == method_type) this is the corresponding irg.
97                The ir_graph constructor automatically sets this field.
98                Yes, it must be here. */
99 #ifdef DEBUG_libfirm
100   int nr;             /**< a unique node number for each node to make output
101                   readable. */
102 #endif
103 };
104
105 /* ----------------------- inline functions ------------------------ */
106 static INLINE int
107 __is_entity(void *thing) {
108   return get_kind(thing) == k_entity;
109 }
110
111 static INLINE const char *
112 __get_entity_name(entity *ent) {
113   assert(ent && ent->kind == k_entity);
114   return get_id_str(get_entity_ident(ent));
115 }
116
117 static INLINE ident *
118 __get_entity_ident(entity *ent) {
119   assert(ent && ent->kind == k_entity);
120   return ent->name;
121 }
122
123 static INLINE type *
124 __get_entity_owner(entity *ent) {
125   assert(ent && ent->kind == k_entity);
126   return ent->owner = skip_tid(ent->owner);
127 }
128
129 static INLINE ident *
130 __get_entity_ld_ident(entity *ent)
131 {
132   assert(ent && ent->kind == k_entity);
133   if (ent->ld_name == NULL)
134     ent->ld_name = mangle_entity(ent);
135   return ent->ld_name;
136 }
137
138 static INLINE void
139 __set_entity_ld_ident(entity *ent, ident *ld_ident) {
140   assert(ent && ent->kind == k_entity);
141   ent->ld_name = ld_ident;
142 }
143
144 static INLINE const char *
145 __get_entity_ld_name(entity *ent) {
146   assert(ent && ent->kind == k_entity);
147   return get_id_str(get_entity_ld_ident(ent));
148 }
149
150 static INLINE type *
151 __get_entity_type(entity *ent) {
152   assert(ent && ent->kind == k_entity);
153   return ent->type = skip_tid(ent->type);
154 }
155
156 static INLINE void
157 __set_entity_type(entity *ent, type *type) {
158   assert(ent && ent->kind == k_entity);
159   ent->type = type;
160 }
161
162 static INLINE ent_allocation
163 __get_entity_allocation(entity *ent) {
164   assert(ent && ent->kind == k_entity);
165   return ent->allocation;
166 }
167
168 static INLINE void
169 __set_entity_allocation(entity *ent, ent_allocation al) {
170   assert(ent && ent->kind == k_entity);
171   ent->allocation = al;
172 }
173
174 static INLINE ent_visibility
175 __get_entity_visibility(entity *ent) {
176   assert(ent && ent->kind == k_entity);
177   return ent->visibility;
178 }
179
180 static INLINE ent_variability
181 __get_entity_variability(entity *ent) {
182   assert(ent && ent->kind == k_entity);
183   return ent->variability;
184 }
185
186 static INLINE ent_volatility
187 __get_entity_volatility(entity *ent) {
188   assert(ent && ent->kind == k_entity);
189   return ent->volatility;
190 }
191
192 static INLINE void
193 __set_entity_volatility(entity *ent, ent_volatility vol) {
194   assert(ent && ent->kind == k_entity);
195   ent->volatility = vol;
196 }
197
198 static INLINE peculiarity
199 __get_entity_peculiarity(entity *ent) {
200   assert(ent && ent->kind == k_entity);
201   return ent->peculiarity;
202 }
203
204 /**
205  * @todo why peculiarity only for methods
206  */
207 static INLINE void
208 __set_entity_peculiarity(entity *ent, peculiarity pec) {
209   assert(ent && ent->kind == k_entity);
210   /* @@@ why peculiarity only for methods? */
211   assert(is_method_type(ent->type));
212   ent->peculiarity = pec;
213 }
214
215 static INLINE ent_stickyness
216 __get_entity_stickyness(entity *ent) {
217   assert(ent && ent->kind == k_entity);
218   return ent->stickyness;
219 }
220
221 static INLINE void
222 __set_entity_stickyness(entity *ent, ent_stickyness stickyness)
223 {
224   assert(ent && ent->kind == k_entity);
225   ent->stickyness = stickyness;
226 }
227
228 static INLINE int
229 __get_entity_offset_bits(entity *ent) {
230   assert(ent && ent->kind == k_entity);
231   return ent->offset;
232 }
233
234 static INLINE int
235 __get_entity_offset_bytes(entity *ent) {
236   int bits = __get_entity_offset_bits(ent);
237
238   if (bits & 7) return -1;
239   return bits >> 3;
240 }
241
242 static INLINE void
243 __set_entity_offset_bits(entity *ent, int offset) {
244   assert(ent && ent->kind == k_entity);
245   ent->offset = offset;
246 }
247
248 static INLINE void
249 __set_entity_offset_bytes(entity *ent, int offset) {
250   __set_entity_offset_bits(ent, offset * 8);
251 }
252
253 static INLINE void *
254 __get_entity_link(entity *ent) {
255   assert(ent && ent->kind == k_entity);
256   return ent->link;
257 }
258
259 static INLINE void
260 __set_entity_link(entity *ent, void *l) {
261   assert(ent && ent->kind == k_entity);
262   ent->link = l;
263 }
264
265 static INLINE ir_graph *
266 __get_entity_irg(entity *ent) {
267   assert(ent && ent->kind == k_entity);
268   assert(is_method_type(ent->type));
269   return ent->irg;
270 }
271
272 #define is_entity(thing)                        __is_entity(thing)
273 #define get_entity_name(ent)                    __get_entity_name(ent)
274 #define get_entity_ident(ent)                   __get_entity_ident(ent)
275 #define get_entity_owner(ent)                   __get_entity_owner(ent)
276 #define get_entity_ld_ident(ent)                __get_entity_ld_ident(ent)
277 #define set_entity_ld_ident(ent, ld_ident)      __set_entity_ld_ident(ent, ld_ident)
278 #define get_entity_ld_name(ent)                 __get_entity_ld_name(ent)
279 #define get_entity_type(ent)                    __get_entity_type(ent)
280 #define set_entity_type(ent, type)              __set_entity_type(ent, type)
281 #define get_entity_allocation(ent)              __get_entity_allocation(ent)
282 #define set_entity_allocation(ent, al)          __set_entity_allocation(ent, al)
283 #define get_entity_visibility(ent)              __get_entity_visibility(ent)
284 #define get_entity_variability(ent)             __get_entity_variability(ent)
285 #define get_entity_volatility(ent)              __get_entity_volatility(ent)
286 #define set_entity_volatility(ent, vol)         __set_entity_volatility(ent, vol)
287 #define get_entity_peculiarity(ent)             __get_entity_peculiarity(ent)
288 #define set_entity_peculiarity(ent, pec)        __set_entity_peculiarity(ent, pec)
289 #define get_entity_stickyness(ent)              __get_entity_stickyness(ent)
290 #define set_entity_stickyness(ent, stickyness)  __set_entity_stickyness(ent, stickyness)
291 #define get_entity_offset_bits(ent)             __get_entity_offset_bits(ent)
292 #define get_entity_offset_bytes(ent)            __get_entity_offset_bytes(ent)
293 #define set_entity_offset_bits(ent, offset)     __set_entity_offset_bits(ent, offset)
294 #define set_entity_offset_bytes(ent, offset)    __set_entity_offset_bytes(ent, offset)
295 #define get_entity_link(ent)                    __get_entity_link(ent)
296 #define set_entity_link(ent, l)                 __set_entity_link(ent, l)
297 #define get_entity_irg(ent)                     __get_entity_irg(ent)
298
299 # endif /* _ENTITY_T_H_ */