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
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * entity.h: entities represent all program known objects.
18 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier
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.
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
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.
38 #ifndef _FIRM_TR_ENTITY_T_H_
39 #define _FIRM_TR_ENTITY_T_H_
41 #include "firm_common_t.h"
42 #include "firm_config.h"
48 #include "pseudo_irg.h"
50 /** A path in a compound graph. */
51 struct compound_graph_path {
52 firm_kind kind; /**< dynamic type tag for compound graph path. */
53 ir_type *tp; /**< The type this path belongs to. */
54 int len; /**< length of the path */
56 int index; /**< Array index. To compute position of array elements */
57 entity *node; /**< entity */
58 } list[1]; /**< List of entity/index tuple of length len to express the
62 /** attributes for atomic entities */
63 typedef struct atomic_ent_attr {
64 ir_node *value; /**< value if entity is not of variability uninitialized.
65 Only for atomic entities. */
68 /** attributes for compound entities */
69 typedef struct compound_ent_attr {
70 ir_node **values; /**< constant values of compound entities. Only available if
71 variability not uninitialized. Must be set for variability constant. */
72 compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
73 variability not uninitialized. Must be set for variability constant. */
76 /** a reserved value for "not yet set" */
77 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
79 /** attributes for methods */
80 typedef struct method_ent_attr {
81 ir_graph *irg; /**< The corresponding irg if known.
82 The ir_graph constructor automatically sets this field. */
83 unsigned irg_add_properties; /**< Additional graph properties can be
84 stored in a entity if no irg is available. */
86 unsigned vtable_number; /**< For a dynamically called method, the number assigned
87 in the virtual function table. */
89 ptr_access_kind *param_access; /**< the parameter access */
90 float *param_weight; /**< The weight of method's parameters. Parameters
91 with a high weight are good for procedure cloning. */
92 ir_img_section section; /**< The code section where this method should be placed */
96 /** the type of an entity */
98 firm_kind kind; /**< The dynamic type tag for entity. */
99 ident *name; /**< The name of this entity. */
100 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
101 name. If the field is read before written a default
102 mangling is applies. The name of the owner is prepended
103 to the name of the entity, separated by a underscore.
104 E.g., for a class `A' with field `a' this
105 is the ident for `A_a'. */
106 ir_type *type; /**< The type of this entity, e.g., a method type, a
107 basic type of the language or a class itself. */
108 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
109 ir_allocation allocation:3; /**< Distinguishes static and dynamically allocated
110 entities and some further cases. */
111 ir_visibility visibility:3; /**< Specifies visibility to external program
113 ir_variability variability:3; /**< Specifies variability of entities content. */
114 ir_volatility volatility:2; /**< Specifies volatility of entities content. */
115 ir_stickyness stickyness:2; /**< Specifies whether this entity is sticky. */
116 ir_peculiarity peculiarity:3; /**< The peculiarity of this entity. */
117 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
118 int offset; /**< Offset in bits for this entity. Fixed when layout
119 of owner is determined. */
120 unsigned long visit; /**< visited counter for walks of the type information. */
121 struct dbg_info *dbi; /**< A pointer to information for debug support. */
122 void *link; /**< To store some intermediate information. */
124 /* ------------- fields for entities owned by a class type ---------------*/
126 entity **overwrites; /**< A list of entities this entity overwrites. */
127 entity **overwrittenby; /**< A list of entities that overwrite this entity. */
129 /* ------------- fields for atomic entities --------------- */
130 ir_node *value; /**< value if entity is not of variability uninitialized.
131 Only for atomic entities. */
133 /* ------------- fields for compound entities -------------- */
134 compound_ent_attr cmpd_attr;
135 /* ------------- fields for method entities ---------------- */
136 method_ent_attr mtd_attr;
137 } attr; /**< type specific attributes */
139 /* ------------- fields for analyses ---------------*/
142 long nr; /**< A unique node number for each node to make output
144 # endif /* DEBUG_libfirm */
147 /** Initialize entity module. */
148 void firm_init_entity(void);
151 /* ----------------------- inline functions ------------------------ */
153 _is_entity(const void *thing) {
154 return get_kind(thing) == k_entity;
157 static INLINE const char *
158 _get_entity_name(const entity *ent) {
159 assert(ent && ent->kind == k_entity);
160 return get_id_str(get_entity_ident(ent));
163 static INLINE ident *
164 _get_entity_ident(const entity *ent) {
165 assert(ent && ent->kind == k_entity);
170 _set_entity_ident(entity *ent, ident *id) {
171 assert(ent && ent->kind == k_entity);
175 static INLINE ir_type *
176 _get_entity_owner(entity *ent) {
177 assert(ent && ent->kind == k_entity);
178 return ent->owner = skip_tid(ent->owner);
181 static INLINE ident *
182 _get_entity_ld_ident(entity *ent)
184 assert(ent && ent->kind == k_entity);
185 if (ent->ld_name == NULL)
186 ent->ld_name = mangle_entity(ent);
191 _set_entity_ld_ident(entity *ent, ident *ld_ident) {
192 assert(ent && ent->kind == k_entity);
193 ent->ld_name = ld_ident;
196 static INLINE const char *
197 _get_entity_ld_name(entity *ent) {
198 assert(ent && ent->kind == k_entity);
199 return get_id_str(get_entity_ld_ident(ent));
202 static INLINE ir_type *
203 _get_entity_type(entity *ent) {
204 assert(ent && ent->kind == k_entity);
205 return ent->type = skip_tid(ent->type);
209 _set_entity_type(entity *ent, ir_type *type) {
210 assert(ent && ent->kind == k_entity);
214 static INLINE ir_allocation
215 _get_entity_allocation(const entity *ent) {
216 assert(ent && ent->kind == k_entity);
217 return ent->allocation;
221 _set_entity_allocation(entity *ent, ir_allocation al) {
222 assert(ent && ent->kind == k_entity);
223 ent->allocation = al;
226 static INLINE ir_visibility
227 _get_entity_visibility(const entity *ent) {
228 assert(ent && ent->kind == k_entity);
229 return ent->visibility;
232 static INLINE ir_variability
233 _get_entity_variability(const entity *ent) {
234 assert(ent && ent->kind == k_entity);
235 return ent->variability;
238 static INLINE ir_volatility
239 _get_entity_volatility(const entity *ent) {
240 assert(ent && ent->kind == k_entity);
241 return ent->volatility;
245 _set_entity_volatility(entity *ent, ir_volatility vol) {
246 assert(ent && ent->kind == k_entity);
247 ent->volatility = vol;
250 static INLINE ir_peculiarity
251 _get_entity_peculiarity(const entity *ent) {
252 assert(ent && ent->kind == k_entity);
253 return ent->peculiarity;
257 * @todo Why peculiarity only for methods?
258 * Good question. Originally, there were only description and
259 * existent. The thought was, what sense does it make to
260 * describe a field? With inherited the situation changed. So
261 * I removed the assertion. GL, 28.2.05
264 _set_entity_peculiarity(entity *ent, ir_peculiarity pec) {
265 assert(ent && ent->kind == k_entity);
266 /* @@@ why peculiarity only for methods? */
267 //assert(is_Method_type(ent->type));
269 ent->peculiarity = pec;
272 static INLINE ir_stickyness
273 _get_entity_stickyness(const entity *ent) {
274 assert(ent && ent->kind == k_entity);
275 return ent->stickyness;
279 _set_entity_stickyness(entity *ent, ir_stickyness stickyness)
281 assert(ent && ent->kind == k_entity);
282 ent->stickyness = stickyness;
286 _get_entity_offset_bits(const entity *ent) {
287 assert(ent && ent->kind == k_entity);
292 _get_entity_offset_bytes(const entity *ent) {
293 int bits = _get_entity_offset_bits(ent);
295 if (bits & 7) return -1;
300 _set_entity_offset_bits(entity *ent, int offset) {
301 assert(ent && ent->kind == k_entity);
302 ent->offset = offset;
306 _set_entity_offset_bytes(entity *ent, int offset) {
307 _set_entity_offset_bits(ent, offset * 8);
311 _get_entity_link(const entity *ent) {
312 assert(ent && ent->kind == k_entity);
317 _set_entity_link(entity *ent, void *l) {
318 assert(ent && ent->kind == k_entity);
322 static INLINE ir_graph *
323 _get_entity_irg(const entity *ent) {
324 assert(ent && ent->kind == k_entity);
325 assert(ent == unknown_entity || is_Method_type(ent->type));
326 if (!get_visit_pseudo_irgs() && ent->attr.mtd_attr.irg
327 && is_pseudo_ir_graph(ent->attr.mtd_attr.irg))
329 return ent->attr.mtd_attr.irg;
332 static INLINE unsigned long
333 _get_entity_visited(entity *ent) {
334 assert(ent && ent->kind == k_entity);
339 _set_entity_visited(entity *ent, unsigned long num) {
340 assert(ent && ent->kind == k_entity);
345 _mark_entity_visited(entity *ent) {
346 assert(ent && ent->kind == k_entity);
347 ent->visit = firm_type_visited;
351 _entity_visited(entity *ent) {
352 return _get_entity_visited(ent) >= firm_type_visited;
356 _entity_not_visited(entity *ent) {
357 return _get_entity_visited(ent) < firm_type_visited;
360 #define is_entity(thing) _is_entity(thing)
361 #define get_entity_name(ent) _get_entity_name(ent)
362 #define get_entity_ident(ent) _get_entity_ident(ent)
363 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
364 #define get_entity_owner(ent) _get_entity_owner(ent)
365 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
366 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
367 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
368 #define get_entity_type(ent) _get_entity_type(ent)
369 #define set_entity_type(ent, type) _set_entity_type(ent, type)
370 #define get_entity_allocation(ent) _get_entity_allocation(ent)
371 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
372 #define get_entity_visibility(ent) _get_entity_visibility(ent)
373 #define get_entity_variability(ent) _get_entity_variability(ent)
374 #define get_entity_volatility(ent) _get_entity_volatility(ent)
375 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
376 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
377 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
378 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
379 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
380 #define get_entity_offset_bits(ent) _get_entity_offset_bits(ent)
381 #define get_entity_offset_bytes(ent) _get_entity_offset_bytes(ent)
382 #define set_entity_offset_bits(ent, offset) _set_entity_offset_bits(ent, offset)
383 #define set_entity_offset_bytes(ent, offset) _set_entity_offset_bytes(ent, offset)
384 #define get_entity_link(ent) _get_entity_link(ent)
385 #define set_entity_link(ent, l) _set_entity_link(ent, l)
386 #define get_entity_irg(ent) _get_entity_irg(ent)
387 #define get_entity_visited(ent) _get_entity_visited(ent)
388 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
389 #define mark_entity_visited(ent) _mark_entity_visited(ent)
390 #define entity_visited(ent) _entity_visited(ent)
391 #define entity_not_visited(ent) _entity_not_visited(ent)
393 #endif /* _FIRM_TR_ENTITY_T_H_ */