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, Michael Beck
9 * Copyright: (c) 1998-2006 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; /**< The dynamic type tag for compound graph path. */
53 ir_type *tp; /**< The type this path belongs to. */
54 int len; /**< The length of the path. */
56 int index; /**< Array index. To compute position of array elements */
57 ir_entity *node; /**< The accessed entity. */
58 } list[1]; /**< List of entity/index tuple of length len to express the
62 /** The 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 /** The 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;
73 /**< paths corresponding to constant values. Only available if
74 variability not uninitialized. Must be set for variability constant. */
77 /** A reserved value for "not yet set". */
78 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
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 unsigned irg_add_properties; /**< Additional graph properties can be
85 stored in a entity if no irg is available. */
87 unsigned vtable_number; /**< For a dynamically called method, the number assigned
88 in the virtual function table. */
90 ptr_access_kind *param_access; /**< the parameter access */
91 float *param_weight; /**< The weight of method's parameters. Parameters
92 with a high weight are good for procedure cloning. */
93 ir_img_section section; /**< The code section where this method should be placed */
98 * An abstract data type to represent program entities.
103 firm_kind kind; /**< The dynamic type tag for entity. */
104 ident *name; /**< The name of this entity. */
105 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
106 name. If the field is read before written a default
107 mangling is applies. The name of the owner is prepended
108 to the name of the entity, separated by a underscore.
109 E.g., for a class `A' with field `a' this
110 is the ident for `A_a'. */
111 ir_type *type; /**< The type of this entity, e.g., a method type, a
112 basic type of the language or a class itself. */
113 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
114 ir_allocation allocation:3; /**< Distinguishes static and dynamically allocated
115 entities and some further cases. */
116 ir_visibility visibility:3; /**< Specifies visibility to external program
118 ir_variability variability:3; /**< Specifies variability of entities content. */
119 ir_volatility volatility:2; /**< Specifies volatility of entities content. */
120 ir_stickyness stickyness:2; /**< Specifies whether this entity is sticky. */
121 ir_peculiarity peculiarity:3; /**< The peculiarity of this entity. */
122 unsigned final:1; /**< If set, this entity cannot be overridden. */
123 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
124 int offset; /**< Offset in bytes for this entity. Fixed when layout
125 of owner is determined. */
126 unsigned char offset_bit_remainder;
127 /**< If the entity is a bit field, this is the offset of
128 the start of the bit field within the byte specified
130 unsigned long visit; /**< visited counter for walks of the type information. */
131 struct dbg_info *dbi; /**< A pointer to information for debug support. */
132 void *link; /**< To store some intermediate information. */
133 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
135 /* ------------- fields for entities owned by a class type ---------------*/
137 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
138 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
140 /* ------------- fields for atomic entities --------------- */
141 ir_node *value; /**< value if entity is not of variability uninitialized.
142 Only for atomic entities. */
144 /* ------------- fields for compound entities -------------- */
145 compound_ent_attr cmpd_attr;
146 /* ------------- fields for method entities ---------------- */
147 method_ent_attr mtd_attr;
148 } attr; /**< type specific attributes */
150 /* ------------- fields for analyses ---------------*/
153 long nr; /**< A unique node number for each node to make output readable. */
154 # endif /* DEBUG_libfirm */
157 /** Initialize the entity module. */
158 void firm_init_entity(void);
161 /* ----------------------- inline functions ------------------------ */
163 _is_entity(const void *thing) {
164 return get_kind(thing) == k_entity;
167 static INLINE const char *
168 _get_entity_name(const ir_entity *ent) {
169 assert(ent && ent->kind == k_entity);
170 return get_id_str(get_entity_ident(ent));
173 static INLINE ident *
174 _get_entity_ident(const ir_entity *ent) {
175 assert(ent && ent->kind == k_entity);
180 _set_entity_ident(ir_entity *ent, ident *id) {
181 assert(ent && ent->kind == k_entity);
185 static INLINE ir_type *
186 _get_entity_owner(ir_entity *ent) {
187 assert(ent && ent->kind == k_entity);
188 return ent->owner = skip_tid(ent->owner);
191 static INLINE ident *
192 _get_entity_ld_ident(ir_entity *ent)
194 assert(ent && ent->kind == k_entity);
195 if (ent->ld_name == NULL)
196 ent->ld_name = mangle_entity(ent);
201 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
202 assert(ent && ent->kind == k_entity);
203 ent->ld_name = ld_ident;
206 static INLINE const char *
207 _get_entity_ld_name(ir_entity *ent) {
208 assert(ent && ent->kind == k_entity);
209 return get_id_str(get_entity_ld_ident(ent));
212 static INLINE ir_type *
213 _get_entity_type(ir_entity *ent) {
214 assert(ent && ent->kind == k_entity);
215 return ent->type = skip_tid(ent->type);
219 _set_entity_type(ir_entity *ent, ir_type *type) {
220 assert(ent && ent->kind == k_entity);
224 static INLINE ir_allocation
225 _get_entity_allocation(const ir_entity *ent) {
226 assert(ent && ent->kind == k_entity);
227 return ent->allocation;
231 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
232 assert(ent && ent->kind == k_entity);
233 ent->allocation = al;
236 static INLINE ir_visibility
237 _get_entity_visibility(const ir_entity *ent) {
238 assert(ent && ent->kind == k_entity);
239 return ent->visibility;
242 static INLINE ir_variability
243 _get_entity_variability(const ir_entity *ent) {
244 assert(ent && ent->kind == k_entity);
245 return ent->variability;
248 static INLINE ir_volatility
249 _get_entity_volatility(const ir_entity *ent) {
250 assert(ent && ent->kind == k_entity);
251 return ent->volatility;
255 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
256 assert(ent && ent->kind == k_entity);
257 ent->volatility = vol;
260 static INLINE ir_peculiarity
261 _get_entity_peculiarity(const ir_entity *ent) {
262 assert(ent && ent->kind == k_entity);
263 return ent->peculiarity;
267 * @todo Why peculiarity only for methods?
268 * Good question. Originally, there were only description and
269 * existent. The thought was, what sense does it make to
270 * describe a field? With inherited the situation changed. So
271 * I removed the assertion. GL, 28.2.05
274 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
275 assert(ent && ent->kind == k_entity);
276 /* @@@ why peculiarity only for methods? */
277 //assert(is_Method_type(ent->type));
279 ent->peculiarity = pec;
282 static INLINE ir_stickyness
283 _get_entity_stickyness(const ir_entity *ent) {
284 assert(ent && ent->kind == k_entity);
285 return ent->stickyness;
289 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
290 assert(ent && ent->kind == k_entity);
291 ent->stickyness = stickyness;
295 _get_entity_final(const ir_entity *ent) {
296 assert(ent && ent->kind == k_entity);
297 return (int)ent->final;
301 _set_entity_final(ir_entity *ent, int final) {
302 assert(ent && ent->kind == k_entity);
303 ent->final = final ? 1 : 0;
307 _get_entity_offset(const ir_entity *ent) {
308 assert(ent && ent->kind == k_entity);
313 _set_entity_offset(ir_entity *ent, int offset) {
314 assert(ent && ent->kind == k_entity);
315 ent->offset = offset;
318 static INLINE unsigned char
319 _get_entity_offset_bits_remainder(const ir_entity *ent) {
320 assert(ent && ent->kind == k_entity);
321 return ent->offset_bit_remainder;
325 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
326 assert(ent && ent->kind == k_entity);
327 ent->offset_bit_remainder = offset;
331 _get_entity_link(const ir_entity *ent) {
332 assert(ent && ent->kind == k_entity);
337 _set_entity_link(ir_entity *ent, void *l) {
338 assert(ent && ent->kind == k_entity);
342 static INLINE ir_graph *
343 _get_entity_irg(const ir_entity *ent) {
344 assert(ent && ent->kind == k_entity);
345 assert(ent == unknown_entity || is_Method_type(ent->type));
346 if (!get_visit_pseudo_irgs() && ent->attr.mtd_attr.irg
347 && is_pseudo_ir_graph(ent->attr.mtd_attr.irg))
349 return ent->attr.mtd_attr.irg;
352 static INLINE unsigned long
353 _get_entity_visited(ir_entity *ent) {
354 assert(ent && ent->kind == k_entity);
359 _set_entity_visited(ir_entity *ent, unsigned long num) {
360 assert(ent && ent->kind == k_entity);
365 _mark_entity_visited(ir_entity *ent) {
366 assert(ent && ent->kind == k_entity);
367 ent->visit = firm_type_visited;
371 _entity_visited(ir_entity *ent) {
372 return _get_entity_visited(ent) >= firm_type_visited;
376 _entity_not_visited(ir_entity *ent) {
377 return _get_entity_visited(ent) < firm_type_visited;
380 static INLINE ir_type *
381 _get_entity_repr_class(const ir_entity *ent) {
382 assert(ent && ent->kind == k_entity);
383 return ent->repr_class;
386 #define is_entity(thing) _is_entity(thing)
387 #define get_entity_name(ent) _get_entity_name(ent)
388 #define get_entity_ident(ent) _get_entity_ident(ent)
389 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
390 #define get_entity_owner(ent) _get_entity_owner(ent)
391 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
392 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
393 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
394 #define get_entity_type(ent) _get_entity_type(ent)
395 #define set_entity_type(ent, type) _set_entity_type(ent, type)
396 #define get_entity_allocation(ent) _get_entity_allocation(ent)
397 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
398 #define get_entity_visibility(ent) _get_entity_visibility(ent)
399 #define get_entity_variability(ent) _get_entity_variability(ent)
400 #define get_entity_volatility(ent) _get_entity_volatility(ent)
401 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
402 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
403 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
404 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
405 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
406 #define get_entity_final(ent) _get_entity_final(ent)
407 #define set_entity_final(ent, final) _set_entity_final(ent, final)
408 #define get_entity_offset(ent) _get_entity_offset(ent)
409 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
410 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
411 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
412 #define get_entity_link(ent) _get_entity_link(ent)
413 #define set_entity_link(ent, l) _set_entity_link(ent, l)
414 #define get_entity_irg(ent) _get_entity_irg(ent)
415 #define get_entity_visited(ent) _get_entity_visited(ent)
416 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
417 #define mark_entity_visited(ent) _mark_entity_visited(ent)
418 #define entity_visited(ent) _entity_visited(ent)
419 #define entity_not_visited(ent) _entity_not_visited(ent)
420 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
423 #endif /* _FIRM_TR_ENTITY_T_H_ */