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"
44 # include "typegmod.h"
48 /** A path in a compund graph. */
49 struct compound_graph_path {
50 firm_kind kind; /**< dynamic type tag for compound graph path. */
51 type *tp; /**< The type this path belongs to. */
52 int len; /**< length of the path */
53 int *arr_indicees; /**< List of array indicees. To compute position of
55 entity *nodes[1]; /**< List of entities of length len to express the
59 /** the type of an entity */
61 firm_kind kind; /**< dynamic type tag for entity. */
62 ident *name; /**< name of this entity */
63 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
64 name. If the field is read before written a default
65 magling is applies. The name of the owner is prepended
66 to the name of the entity, separated by a underscore.
67 E.g., for a class `A' with field `a' this
68 is the ident for `A_a'. */
69 type *type; /**< The type of this entity, e.g., a method type, a
70 basic type of the language or a class itself */
71 type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
72 ent_allocation allocation; /**< Distinguishes static and dynamically allocated
73 entities and some further cases. */
74 ent_visibility visibility; /**< Specifies visibility to external program
76 ent_variability variability; /**< Specifies variability of entities content */
77 ent_volatility volatility; /**< Specifies volatility of entities content */
78 ent_stickyness stickyness; /**< Specifies whether this entity is sticky */
79 int offset; /**< Offset in bits for this entity. Fixed when layout
80 of owner is determined. */
81 void *link; /**< To store some intermediate information */
82 unsigned long visit; /**< visited counter for walks of the type information */
83 struct dbg_info* dbi; /**< A pointer to information for debug support. */
85 /* ------------- fields for atomic entities ---------------*/
87 ir_node *value; /**< value if entity is not of variability uninitialized.
88 Only for atomic entities. */
90 /* ------------- fields for compound entities ---------------*/
92 ir_node **values; /**< constant values of compound entities. Only available if
93 variablility not uninitialized. Must be set for variability constant
95 compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
96 variablility not uninitialized. Must be set for variability constant */
98 /* ------------- fields for entities owned by a class type ---------------*/
100 entity **overwrites; /**< A list of entities this entity overwrites. */
101 entity **overwrittenby; /**< A list of entities that overwrite this entity. */
103 /* ------------- fields for methods ---------------*/
105 enum peculiarity peculiarity;
106 ir_graph *irg; /**< If (type == method_type) this is the corresponding irg.
107 The ir_graph constructor automatically sets this field.
108 Yes, it must be here. */
110 /* ------------- fields for analyses ---------------*/
114 int nr; /**< a unique node number for each node to make output
116 char *c_name; /**< Since idents are ipaque, provide the name in cleartext */
117 # endif /* DEBUG_libfirm */
122 /* ----------------------- inline functions ------------------------ */
124 __is_entity(const void *thing) {
125 return get_kind(thing) == k_entity;
128 static INLINE const char *
129 __get_entity_name(const entity *ent) {
130 assert(ent && ent->kind == k_entity);
131 return get_id_str(get_entity_ident(ent));
134 static INLINE ident *
135 __get_entity_ident(const entity *ent) {
136 assert(ent && ent->kind == k_entity);
141 __get_entity_owner(entity *ent) {
142 assert(ent && ent->kind == k_entity);
143 return ent->owner = skip_tid(ent->owner);
146 static INLINE ident *
147 __get_entity_ld_ident(entity *ent)
149 assert(ent && ent->kind == k_entity);
150 if (ent->ld_name == NULL)
151 ent->ld_name = mangle_entity(ent);
156 __set_entity_ld_ident(entity *ent, ident *ld_ident) {
157 assert(ent && ent->kind == k_entity);
158 ent->ld_name = ld_ident;
161 static INLINE const char *
162 __get_entity_ld_name(entity *ent) {
163 assert(ent && ent->kind == k_entity);
164 return get_id_str(get_entity_ld_ident(ent));
168 __get_entity_type(entity *ent) {
169 assert(ent && ent->kind == k_entity);
170 return ent->type = skip_tid(ent->type);
174 __set_entity_type(entity *ent, type *type) {
175 assert(ent && ent->kind == k_entity);
179 static INLINE ent_allocation
180 __get_entity_allocation(const entity *ent) {
181 assert(ent && ent->kind == k_entity);
182 return ent->allocation;
186 __set_entity_allocation(entity *ent, ent_allocation al) {
187 assert(ent && ent->kind == k_entity);
188 ent->allocation = al;
191 static INLINE ent_visibility
192 __get_entity_visibility(const entity *ent) {
193 assert(ent && ent->kind == k_entity);
194 return ent->visibility;
197 static INLINE ent_variability
198 __get_entity_variability(const entity *ent) {
199 assert(ent && ent->kind == k_entity);
200 return ent->variability;
203 static INLINE ent_volatility
204 __get_entity_volatility(const entity *ent) {
205 assert(ent && ent->kind == k_entity);
206 return ent->volatility;
210 __set_entity_volatility(entity *ent, ent_volatility vol) {
211 assert(ent && ent->kind == k_entity);
212 ent->volatility = vol;
215 static INLINE peculiarity
216 __get_entity_peculiarity(const entity *ent) {
217 assert(ent && ent->kind == k_entity);
218 return ent->peculiarity;
222 * @todo why peculiarity only for methods
225 __set_entity_peculiarity(entity *ent, peculiarity pec) {
226 assert(ent && ent->kind == k_entity);
227 /* @@@ why peculiarity only for methods? */
228 assert(is_method_type(ent->type));
230 ent->peculiarity = pec;
233 static INLINE ent_stickyness
234 __get_entity_stickyness(const entity *ent) {
235 assert(ent && ent->kind == k_entity);
236 return ent->stickyness;
240 __set_entity_stickyness(entity *ent, ent_stickyness stickyness)
242 assert(ent && ent->kind == k_entity);
243 ent->stickyness = stickyness;
247 __get_entity_offset_bits(const entity *ent) {
248 assert(ent && ent->kind == k_entity);
253 __get_entity_offset_bytes(const entity *ent) {
254 int bits = __get_entity_offset_bits(ent);
256 if (bits & 7) return -1;
261 __set_entity_offset_bits(entity *ent, int offset) {
262 assert(ent && ent->kind == k_entity);
263 ent->offset = offset;
267 __set_entity_offset_bytes(entity *ent, int offset) {
268 __set_entity_offset_bits(ent, offset * 8);
272 __get_entity_link(const entity *ent) {
273 assert(ent && ent->kind == k_entity);
278 __set_entity_link(entity *ent, void *l) {
279 assert(ent && ent->kind == k_entity);
283 static INLINE ir_graph *
284 __get_entity_irg(const entity *ent) {
285 assert(ent && ent->kind == k_entity);
286 assert(is_method_type(ent->type));
290 #define is_entity(thing) __is_entity(thing)
291 #define get_entity_name(ent) __get_entity_name(ent)
292 #define get_entity_ident(ent) __get_entity_ident(ent)
293 #define get_entity_owner(ent) __get_entity_owner(ent)
294 #define get_entity_ld_ident(ent) __get_entity_ld_ident(ent)
295 #define set_entity_ld_ident(ent, ld_ident) __set_entity_ld_ident(ent, ld_ident)
296 #define get_entity_ld_name(ent) __get_entity_ld_name(ent)
297 #define get_entity_type(ent) __get_entity_type(ent)
298 #define set_entity_type(ent, type) __set_entity_type(ent, type)
299 #define get_entity_allocation(ent) __get_entity_allocation(ent)
300 #define set_entity_allocation(ent, al) __set_entity_allocation(ent, al)
301 #define get_entity_visibility(ent) __get_entity_visibility(ent)
302 #define get_entity_variability(ent) __get_entity_variability(ent)
303 #define get_entity_volatility(ent) __get_entity_volatility(ent)
304 #define set_entity_volatility(ent, vol) __set_entity_volatility(ent, vol)
305 #define get_entity_peculiarity(ent) __get_entity_peculiarity(ent)
306 #define set_entity_peculiarity(ent, pec) __set_entity_peculiarity(ent, pec)
307 #define get_entity_stickyness(ent) __get_entity_stickyness(ent)
308 #define set_entity_stickyness(ent, stickyness) __set_entity_stickyness(ent, stickyness)
309 #define get_entity_offset_bits(ent) __get_entity_offset_bits(ent)
310 #define get_entity_offset_bytes(ent) __get_entity_offset_bytes(ent)
311 #define set_entity_offset_bits(ent, offset) __set_entity_offset_bits(ent, offset)
312 #define set_entity_offset_bytes(ent, offset) __set_entity_offset_bytes(ent, offset)
313 #define get_entity_link(ent) __get_entity_link(ent)
314 #define set_entity_link(ent, l) __set_entity_link(ent, l)
315 #define get_entity_irg(ent) __get_entity_irg(ent)
317 # endif /* _ENTITY_T_H_ */