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 compund graph. */
51 struct compound_graph_path {
52 firm_kind kind; /**< dynamic type tag for compound graph path. */
53 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 type *type; /**< The type of this entity, e.g., a method type, a
73 basic type of the language or a class itself */
74 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 void *link; /**< To store some intermediate information */
85 unsigned long visit; /**< visited counter for walks of the type information */
86 struct dbg_info *dbi; /**< A pointer to information for debug support. */
88 /* ------------- fields for atomic entities ---------------*/
90 ir_node *value; /**< value if entity is not of variability uninitialized.
91 Only for atomic entities. */
93 /* ------------- fields for compound entities ---------------*/
95 ir_node **values; /**< constant values of compound entities. Only available if
96 variability not uninitialized. Must be set for variability constant
98 compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
99 variability not uninitialized. Must be set for variability constant */
101 /* ------------- fields for entities owned by a class type ---------------*/
103 entity **overwrites; /**< A list of entities this entity overwrites. */
104 entity **overwrittenby; /**< A list of entities that overwrite this entity. */
106 /* ------------- fields for methods ---------------*/
108 enum peculiarity peculiarity;
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; /**< If (type == method_type) this is a set of additional.
113 graph flags if the irg of an entity is not known. */
114 unsigned irg_calling_conv; /**< If (type == method_type) this is a set of calling.
115 convention flags if the irg of an entity is not known. */
117 /* ------------- fields for analyses ---------------*/
121 int nr; /**< a unique node number for each node to make output
123 # endif /* DEBUG_libfirm */
126 /** Initialize entity module. */
127 void firm_init_entity(void);
130 /* ----------------------- inline functions ------------------------ */
132 _is_entity(const void *thing) {
133 return get_kind(thing) == k_entity;
136 static INLINE const char *
137 _get_entity_name(const entity *ent) {
138 assert(ent && ent->kind == k_entity);
139 return get_id_str(get_entity_ident(ent));
142 static INLINE ident *
143 _get_entity_ident(const entity *ent) {
144 assert(ent && ent->kind == k_entity);
149 _get_entity_owner(entity *ent) {
150 assert(ent && ent->kind == k_entity);
151 return ent->owner = skip_tid(ent->owner);
154 static INLINE ident *
155 _get_entity_ld_ident(entity *ent)
157 assert(ent && ent->kind == k_entity);
158 if (ent->ld_name == NULL)
159 ent->ld_name = mangle_entity(ent);
164 _set_entity_ld_ident(entity *ent, ident *ld_ident) {
165 assert(ent && ent->kind == k_entity);
166 ent->ld_name = ld_ident;
169 static INLINE const char *
170 _get_entity_ld_name(entity *ent) {
171 assert(ent && ent->kind == k_entity);
172 return get_id_str(get_entity_ld_ident(ent));
176 _get_entity_type(entity *ent) {
177 assert(ent && ent->kind == k_entity);
178 return ent->type = skip_tid(ent->type);
182 _set_entity_type(entity *ent, type *type) {
183 assert(ent && ent->kind == k_entity);
187 static INLINE ent_allocation
188 _get_entity_allocation(const entity *ent) {
189 assert(ent && ent->kind == k_entity);
190 return ent->allocation;
194 _set_entity_allocation(entity *ent, ent_allocation al) {
195 assert(ent && ent->kind == k_entity);
196 ent->allocation = al;
199 static INLINE visibility
200 _get_entity_visibility(const entity *ent) {
201 assert(ent && ent->kind == k_entity);
202 return ent->visibility;
205 static INLINE ent_variability
206 _get_entity_variability(const entity *ent) {
207 assert(ent && ent->kind == k_entity);
208 return ent->variability;
211 static INLINE ent_volatility
212 _get_entity_volatility(const entity *ent) {
213 assert(ent && ent->kind == k_entity);
214 return ent->volatility;
218 _set_entity_volatility(entity *ent, ent_volatility vol) {
219 assert(ent && ent->kind == k_entity);
220 ent->volatility = vol;
223 static INLINE peculiarity
224 _get_entity_peculiarity(const entity *ent) {
225 assert(ent && ent->kind == k_entity);
226 return ent->peculiarity;
230 * @todo Why peculiarity only for methods?
231 * Good question. Originally, there were only description and
232 * existent. The thought was, what sense does it make to
233 * describe a field? With inherited the situation changed. So
234 * I removed the assertion. GL, 28.2.05
237 _set_entity_peculiarity(entity *ent, peculiarity pec) {
238 assert(ent && ent->kind == k_entity);
239 /* @@@ why peculiarity only for methods? */
240 //assert(is_Method_type(ent->type));
242 ent->peculiarity = pec;
245 static INLINE ent_stickyness
246 _get_entity_stickyness(const entity *ent) {
247 assert(ent && ent->kind == k_entity);
248 return ent->stickyness;
252 _set_entity_stickyness(entity *ent, ent_stickyness stickyness)
254 assert(ent && ent->kind == k_entity);
255 ent->stickyness = stickyness;
259 _get_entity_offset_bits(const entity *ent) {
260 assert(ent && ent->kind == k_entity);
265 _get_entity_offset_bytes(const entity *ent) {
266 int bits = _get_entity_offset_bits(ent);
268 if (bits & 7) return -1;
273 _set_entity_offset_bits(entity *ent, int offset) {
274 assert(ent && ent->kind == k_entity);
275 ent->offset = offset;
279 _set_entity_offset_bytes(entity *ent, int offset) {
280 _set_entity_offset_bits(ent, offset * 8);
284 _get_entity_link(const entity *ent) {
285 assert(ent && ent->kind == k_entity);
290 _set_entity_link(entity *ent, void *l) {
291 assert(ent && ent->kind == k_entity);
295 static INLINE ir_graph *
296 _get_entity_irg(const entity *ent) {
297 assert(ent && ent->kind == k_entity);
298 assert(ent == unknown_entity || is_Method_type(ent->type));
299 if (!get_visit_pseudo_irgs() && ent->irg && is_pseudo_ir_graph(ent->irg))
304 static INLINE unsigned long
305 _get_entity_visited(entity *ent) {
306 assert(ent && ent->kind == k_entity);
311 _set_entity_visited(entity *ent, unsigned long num) {
312 assert(ent && ent->kind == k_entity);
317 _mark_entity_visited(entity *ent) {
318 assert(ent && ent->kind == k_entity);
319 ent->visit = firm_type_visited;
323 _entity_visited(entity *ent) {
324 return _get_entity_visited(ent) >= firm_type_visited;
328 _entity_not_visited(entity *ent) {
329 return _get_entity_visited(ent) < firm_type_visited;
332 static INLINE unsigned
333 _get_entity_additional_properties(const entity *ent) {
335 assert(ent && ent->kind == k_entity);
336 assert(ent == unknown_entity || is_Method_type(ent->type));
337 irg = _get_entity_irg(ent);
339 get_irg_additional_properties(irg) :
340 ent->irg_add_properties;
344 _set_entity_additional_properties(entity *ent, unsigned mask) {
346 assert(ent && ent->kind == k_entity);
347 assert(ent == unknown_entity || is_Method_type(ent->type));
348 irg = _get_entity_irg(ent);
350 set_irg_additional_properties(irg, mask);
352 ent->irg_add_properties = mask;
356 _set_entity_additional_property(entity *ent, irg_additional_property flag) {
358 assert(ent && ent->kind == k_entity);
359 assert(ent == unknown_entity || is_Method_type(ent->type));
360 irg = _get_entity_irg(ent);
362 set_irg_additional_property(irg, flag);
364 ent->irg_add_properties |= flag;
367 static INLINE unsigned
368 _get_entity_calling_convention(const entity *ent) {
370 assert(ent && ent->kind == k_entity);
371 assert(ent == unknown_entity || is_Method_type(ent->type));
372 irg = _get_entity_irg(ent);
374 return get_irg_calling_convention(irg);
376 return ent->irg_calling_conv;
380 _set_entity_calling_convention(entity *ent, unsigned cc_mask) {
382 assert(ent && ent->kind == k_entity);
383 assert(ent == unknown_entity || is_Method_type(ent->type));
384 irg = _get_entity_irg(ent);
386 set_irg_calling_convention(irg, cc_mask);
388 ent->irg_calling_conv = cc_mask;
391 #define is_entity(thing) _is_entity(thing)
392 #define get_entity_name(ent) _get_entity_name(ent)
393 #define get_entity_ident(ent) _get_entity_ident(ent)
394 #define get_entity_owner(ent) _get_entity_owner(ent)
395 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
396 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
397 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
398 #define get_entity_type(ent) _get_entity_type(ent)
399 #define set_entity_type(ent, type) _set_entity_type(ent, type)
400 #define get_entity_allocation(ent) _get_entity_allocation(ent)
401 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
402 #define get_entity_visibility(ent) _get_entity_visibility(ent)
403 #define get_entity_variability(ent) _get_entity_variability(ent)
404 #define get_entity_volatility(ent) _get_entity_volatility(ent)
405 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
406 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
407 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
408 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
409 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
410 #define get_entity_offset_bits(ent) _get_entity_offset_bits(ent)
411 #define get_entity_offset_bytes(ent) _get_entity_offset_bytes(ent)
412 #define set_entity_offset_bits(ent, offset) _set_entity_offset_bits(ent, offset)
413 #define set_entity_offset_bytes(ent, offset) _set_entity_offset_bytes(ent, offset)
414 #define get_entity_link(ent) _get_entity_link(ent)
415 #define set_entity_link(ent, l) _set_entity_link(ent, l)
416 #define get_entity_irg(ent) _get_entity_irg(ent)
417 #define get_entity_visited(ent) _get_entity_visited(ent)
418 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
419 #define mark_entity_visited(ent) _mark_entity_visited(ent)
420 #define entity_visited(ent) _entity_visited(ent)
421 #define entity_not_visited(ent) _entity_not_visited(ent)
422 #define get_entity_additional_properties(ent) _get_entity_additional_properties(ent)
423 #define set_entity_additional_properties(ent, m) _set_entity_additional_properties(ent, m)
424 #define set_entity_additional_property(ent, f) _set_entity_additional_property(ent, f)
425 #define get_entity_calling_convention(ent) _get_entity_calling_convention(ent)
426 #define set_entity_calling_convention(ent, cc) _set_entity_calling_convention(ent, cc)
428 # endif /* _ENTITY_T_H_ */