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.
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 entitiy/index tuple of length len to express the
62 /** the type of an entity */
64 firm_kind kind; /**< dynamic type tag for entity. */
65 ident *name; /**< name of this entity */
66 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
67 name. If the field is read before written a default
68 mangling is applies. The name of the owner is prepended
69 to the name of the entity, separated by a underscore.
70 E.g., for a class `A' with field `a' this
71 is the ident for `A_a'. */
72 ir_type *type; /**< The type of this entity, e.g., a method type, a
73 basic type of the language or a class itself */
74 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
75 ent_allocation allocation; /**< Distinguishes static and dynamically allocated
76 entities and some further cases. */
77 visibility visibility; /**< Specifies visibility to external program
79 ent_variability variability; /**< Specifies variability of entities content */
80 ent_volatility volatility; /**< Specifies volatility of entities content */
81 ent_stickyness stickyness; /**< Specifies whether this entity is sticky */
82 int offset; /**< Offset in bits for this entity. Fixed when layout
83 of owner is determined. */
84 peculiarity peculiarity; /**< peculiarity of this entity */
85 unsigned long visit; /**< visited counter for walks of the type information */
86 struct dbg_info *dbi; /**< A pointer to information for debug support. */
87 void *link; /**< To store some intermediate information */
89 /* ------------- fields for atomic entities ---------------*/
91 ir_node *value; /**< value if entity is not of variability uninitialized.
92 Only for atomic entities. */
94 /* ------------- fields for compound entities ---------------*/
96 ir_node **values; /**< constant values of compound entities. Only available if
97 variability not uninitialized. Must be set for variability constant
99 compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
100 variability not uninitialized. Must be set for variability constant */
102 /* ------------- fields for entities owned by a class type ---------------*/
104 entity **overwrites; /**< A list of entities this entity overwrites. */
105 entity **overwrittenby; /**< A list of entities that overwrite this entity. */
107 /* ------------- fields for methods ---------------*/
109 ir_graph *irg; /**< If (type == method_type) this is the corresponding irg.
110 The ir_graph constructor automatically sets this field.
111 Yes, it must be here. */
112 unsigned irg_add_properties; /**< Additional graph properties can be
113 stored in a entity if no irg is available. */
115 ptr_access_kind *param_access; /**< the parameter access */
116 float *param_weight; /**< The weight of method's parameters. Parameters
117 with a high weight are good for procedure cloning.*/
119 /* ------------- fields for analyses ---------------*/
123 long nr; /**< a unique node number for each node to make output
125 # endif /* DEBUG_libfirm */
128 /** Initialize entity module. */
129 void firm_init_entity(void);
132 /* ----------------------- inline functions ------------------------ */
134 _is_entity(const void *thing) {
135 return get_kind(thing) == k_entity;
138 static INLINE const char *
139 _get_entity_name(const entity *ent) {
140 assert(ent && ent->kind == k_entity);
141 return get_id_str(get_entity_ident(ent));
144 static INLINE ident *
145 _get_entity_ident(const entity *ent) {
146 assert(ent && ent->kind == k_entity);
150 static INLINE ir_type *
151 _get_entity_owner(entity *ent) {
152 assert(ent && ent->kind == k_entity);
153 return ent->owner = skip_tid(ent->owner);
156 static INLINE ident *
157 _get_entity_ld_ident(entity *ent)
159 assert(ent && ent->kind == k_entity);
160 if (ent->ld_name == NULL)
161 ent->ld_name = mangle_entity(ent);
166 _set_entity_ld_ident(entity *ent, ident *ld_ident) {
167 assert(ent && ent->kind == k_entity);
168 ent->ld_name = ld_ident;
171 static INLINE const char *
172 _get_entity_ld_name(entity *ent) {
173 assert(ent && ent->kind == k_entity);
174 return get_id_str(get_entity_ld_ident(ent));
177 static INLINE ir_type *
178 _get_entity_type(entity *ent) {
179 assert(ent && ent->kind == k_entity);
180 return ent->type = skip_tid(ent->type);
184 _set_entity_type(entity *ent, ir_type *type) {
185 assert(ent && ent->kind == k_entity);
189 static INLINE ent_allocation
190 _get_entity_allocation(const entity *ent) {
191 assert(ent && ent->kind == k_entity);
192 return ent->allocation;
196 _set_entity_allocation(entity *ent, ent_allocation al) {
197 assert(ent && ent->kind == k_entity);
198 ent->allocation = al;
201 static INLINE visibility
202 _get_entity_visibility(const entity *ent) {
203 assert(ent && ent->kind == k_entity);
204 return ent->visibility;
207 static INLINE ent_variability
208 _get_entity_variability(const entity *ent) {
209 assert(ent && ent->kind == k_entity);
210 return ent->variability;
213 static INLINE ent_volatility
214 _get_entity_volatility(const entity *ent) {
215 assert(ent && ent->kind == k_entity);
216 return ent->volatility;
220 _set_entity_volatility(entity *ent, ent_volatility vol) {
221 assert(ent && ent->kind == k_entity);
222 ent->volatility = vol;
225 static INLINE peculiarity
226 _get_entity_peculiarity(const entity *ent) {
227 assert(ent && ent->kind == k_entity);
228 return ent->peculiarity;
232 * @todo Why peculiarity only for methods?
233 * Good question. Originally, there were only description and
234 * existent. The thought was, what sense does it make to
235 * describe a field? With inherited the situation changed. So
236 * I removed the assertion. GL, 28.2.05
239 _set_entity_peculiarity(entity *ent, peculiarity pec) {
240 assert(ent && ent->kind == k_entity);
241 /* @@@ why peculiarity only for methods? */
242 //assert(is_Method_type(ent->type));
244 ent->peculiarity = pec;
247 static INLINE ent_stickyness
248 _get_entity_stickyness(const entity *ent) {
249 assert(ent && ent->kind == k_entity);
250 return ent->stickyness;
254 _set_entity_stickyness(entity *ent, ent_stickyness stickyness)
256 assert(ent && ent->kind == k_entity);
257 ent->stickyness = stickyness;
261 _get_entity_offset_bits(const entity *ent) {
262 assert(ent && ent->kind == k_entity);
267 _get_entity_offset_bytes(const entity *ent) {
268 int bits = _get_entity_offset_bits(ent);
270 if (bits & 7) return -1;
275 _set_entity_offset_bits(entity *ent, int offset) {
276 assert(ent && ent->kind == k_entity);
277 ent->offset = offset;
281 _set_entity_offset_bytes(entity *ent, int offset) {
282 _set_entity_offset_bits(ent, offset * 8);
286 _get_entity_link(const entity *ent) {
287 assert(ent && ent->kind == k_entity);
292 _set_entity_link(entity *ent, void *l) {
293 assert(ent && ent->kind == k_entity);
297 static INLINE ir_graph *
298 _get_entity_irg(const entity *ent) {
299 assert(ent && ent->kind == k_entity);
300 assert(ent == unknown_entity || is_Method_type(ent->type));
301 if (!get_visit_pseudo_irgs() && ent->irg && is_pseudo_ir_graph(ent->irg))
306 static INLINE unsigned long
307 _get_entity_visited(entity *ent) {
308 assert(ent && ent->kind == k_entity);
313 _set_entity_visited(entity *ent, unsigned long num) {
314 assert(ent && ent->kind == k_entity);
319 _mark_entity_visited(entity *ent) {
320 assert(ent && ent->kind == k_entity);
321 ent->visit = firm_type_visited;
325 _entity_visited(entity *ent) {
326 return _get_entity_visited(ent) >= firm_type_visited;
330 _entity_not_visited(entity *ent) {
331 return _get_entity_visited(ent) < firm_type_visited;
334 #define is_entity(thing) _is_entity(thing)
335 #define get_entity_name(ent) _get_entity_name(ent)
336 #define get_entity_ident(ent) _get_entity_ident(ent)
337 #define get_entity_owner(ent) _get_entity_owner(ent)
338 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
339 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
340 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
341 #define get_entity_type(ent) _get_entity_type(ent)
342 #define set_entity_type(ent, type) _set_entity_type(ent, type)
343 #define get_entity_allocation(ent) _get_entity_allocation(ent)
344 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
345 #define get_entity_visibility(ent) _get_entity_visibility(ent)
346 #define get_entity_variability(ent) _get_entity_variability(ent)
347 #define get_entity_volatility(ent) _get_entity_volatility(ent)
348 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
349 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
350 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
351 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
352 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
353 #define get_entity_offset_bits(ent) _get_entity_offset_bits(ent)
354 #define get_entity_offset_bytes(ent) _get_entity_offset_bytes(ent)
355 #define set_entity_offset_bits(ent, offset) _set_entity_offset_bits(ent, offset)
356 #define set_entity_offset_bytes(ent, offset) _set_entity_offset_bytes(ent, offset)
357 #define get_entity_link(ent) _get_entity_link(ent)
358 #define set_entity_link(ent, l) _set_entity_link(ent, l)
359 #define get_entity_irg(ent) _get_entity_irg(ent)
360 #define get_entity_visited(ent) _get_entity_visited(ent)
361 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
362 #define mark_entity_visited(ent) _mark_entity_visited(ent)
363 #define entity_visited(ent) _entity_visited(ent)
364 #define entity_not_visited(ent) _entity_not_visited(ent)
366 # endif /* _ENTITY_T_H_ */