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"
45 # include "typegmod.h"
47 # 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 */
55 int *arr_indicees; /**< List of array indeces. To compute position of
57 entity *nodes[1]; /**< List of entities of length len to express the
61 /** the type of an entity */
63 firm_kind kind; /**< dynamic type tag for entity. */
64 ident *name; /**< name of this entity */
65 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
66 name. If the field is read before written a default
67 mangling is applies. The name of the owner is prepended
68 to the name of the entity, separated by a underscore.
69 E.g., for a class `A' with field `a' this
70 is the ident for `A_a'. */
71 type *type; /**< The type of this entity, e.g., a method type, a
72 basic type of the language or a class itself */
73 type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
74 ent_allocation allocation; /**< Distinguishes static and dynamically allocated
75 entities and some further cases. */
76 visibility visibility; /**< Specifies visibility to external program
78 ent_variability variability; /**< Specifies variability of entities content */
79 ent_volatility volatility; /**< Specifies volatility of entities content */
80 ent_stickyness stickyness; /**< Specifies whether this entity is sticky */
81 int offset; /**< Offset in bits for this entity. Fixed when layout
82 of owner is determined. */
83 void *link; /**< To store some intermediate information */
84 unsigned long visit; /**< visited counter for walks of the type information */
85 struct dbg_info* dbi; /**< A pointer to information for debug support. */
87 /* ------------- fields for atomic entities ---------------*/
89 ir_node *value; /**< value if entity is not of variability uninitialized.
90 Only for atomic entities. */
92 /* ------------- fields for compound entities ---------------*/
94 ir_node **values; /**< constant values of compound entities. Only available if
95 variablility not uninitialized. Must be set for variability constant
97 compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if
98 variablility not uninitialized. Must be set for variability constant */
100 /* ------------- fields for entities owned by a class type ---------------*/
102 entity **overwrites; /**< A list of entities this entity overwrites. */
103 entity **overwrittenby; /**< A list of entities that overwrite this entity. */
105 /* ------------- fields for methods ---------------*/
107 enum peculiarity peculiarity;
108 ir_graph *irg; /**< If (type == method_type) this is the corresponding irg.
109 The ir_graph constructor automatically sets this field.
110 Yes, it must be here. */
112 /* ------------- fields for analyses ---------------*/
116 int nr; /**< a unique node number for each node to make output
118 # endif /* DEBUG_libfirm */
123 /* ----------------------- inline functions ------------------------ */
125 _is_entity(const void *thing) {
126 return get_kind(thing) == k_entity;
129 static INLINE const char *
130 _get_entity_name(const entity *ent) {
131 assert(ent && ent->kind == k_entity);
132 return get_id_str(get_entity_ident(ent));
135 static INLINE ident *
136 _get_entity_ident(const entity *ent) {
137 assert(ent && ent->kind == k_entity);
142 _get_entity_owner(entity *ent) {
143 assert(ent && ent->kind == k_entity);
144 return ent->owner = skip_tid(ent->owner);
147 static INLINE ident *
148 _get_entity_ld_ident(entity *ent)
150 assert(ent && ent->kind == k_entity);
151 if (ent->ld_name == NULL)
152 ent->ld_name = mangle_entity(ent);
157 _set_entity_ld_ident(entity *ent, ident *ld_ident) {
158 assert(ent && ent->kind == k_entity);
159 ent->ld_name = ld_ident;
162 static INLINE const char *
163 _get_entity_ld_name(entity *ent) {
164 assert(ent && ent->kind == k_entity);
165 return get_id_str(get_entity_ld_ident(ent));
169 _get_entity_type(entity *ent) {
170 assert(ent && ent->kind == k_entity);
171 return ent->type = skip_tid(ent->type);
175 _set_entity_type(entity *ent, type *type) {
176 assert(ent && ent->kind == k_entity);
180 static INLINE ent_allocation
181 _get_entity_allocation(const entity *ent) {
182 assert(ent && ent->kind == k_entity);
183 return ent->allocation;
187 _set_entity_allocation(entity *ent, ent_allocation al) {
188 assert(ent && ent->kind == k_entity);
189 ent->allocation = al;
192 static INLINE visibility
193 _get_entity_visibility(const entity *ent) {
194 assert(ent && ent->kind == k_entity);
195 return ent->visibility;
198 static INLINE ent_variability
199 _get_entity_variability(const entity *ent) {
200 assert(ent && ent->kind == k_entity);
201 return ent->variability;
204 static INLINE ent_volatility
205 _get_entity_volatility(const entity *ent) {
206 assert(ent && ent->kind == k_entity);
207 return ent->volatility;
211 _set_entity_volatility(entity *ent, ent_volatility vol) {
212 assert(ent && ent->kind == k_entity);
213 ent->volatility = vol;
216 static INLINE peculiarity
217 _get_entity_peculiarity(const entity *ent) {
218 assert(ent && ent->kind == k_entity);
219 return ent->peculiarity;
223 * @todo Why peculiarity only for methods?
224 * Good question. Originally, there were only description and
225 * existent. The thought was, what sense does it make to
226 * describe a field? With inherited the situation changed. So
227 * I removed the assertion. GL, 28.2.05
230 _set_entity_peculiarity(entity *ent, peculiarity pec) {
231 assert(ent && ent->kind == k_entity);
232 /* @@@ why peculiarity only for methods? */
233 //assert(is_Method_type(ent->type));
235 ent->peculiarity = pec;
238 static INLINE ent_stickyness
239 _get_entity_stickyness(const entity *ent) {
240 assert(ent && ent->kind == k_entity);
241 return ent->stickyness;
245 _set_entity_stickyness(entity *ent, ent_stickyness stickyness)
247 assert(ent && ent->kind == k_entity);
248 ent->stickyness = stickyness;
252 _get_entity_offset_bits(const entity *ent) {
253 assert(ent && ent->kind == k_entity);
258 _get_entity_offset_bytes(const entity *ent) {
259 int bits = _get_entity_offset_bits(ent);
261 if (bits & 7) return -1;
266 _set_entity_offset_bits(entity *ent, int offset) {
267 assert(ent && ent->kind == k_entity);
268 ent->offset = offset;
272 _set_entity_offset_bytes(entity *ent, int offset) {
273 _set_entity_offset_bits(ent, offset * 8);
277 _get_entity_link(const entity *ent) {
278 assert(ent && ent->kind == k_entity);
283 _set_entity_link(entity *ent, void *l) {
284 assert(ent && ent->kind == k_entity);
288 static INLINE ir_graph *
289 _get_entity_irg(const entity *ent) {
290 assert(ent && ent->kind == k_entity);
291 assert(ent == unknown_entity || is_Method_type(ent->type));
292 if (!get_visit_pseudo_irgs() && ent->irg && is_pseudo_ir_graph(ent->irg))
297 #define is_entity(thing) _is_entity(thing)
298 #define get_entity_name(ent) _get_entity_name(ent)
299 #define get_entity_ident(ent) _get_entity_ident(ent)
300 #define get_entity_owner(ent) _get_entity_owner(ent)
301 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
302 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
303 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
304 #define get_entity_type(ent) _get_entity_type(ent)
305 #define set_entity_type(ent, type) _set_entity_type(ent, type)
306 #define get_entity_allocation(ent) _get_entity_allocation(ent)
307 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
308 #define get_entity_visibility(ent) _get_entity_visibility(ent)
309 #define get_entity_variability(ent) _get_entity_variability(ent)
310 #define get_entity_volatility(ent) _get_entity_volatility(ent)
311 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
312 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
313 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
314 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
315 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
316 #define get_entity_offset_bits(ent) _get_entity_offset_bits(ent)
317 #define get_entity_offset_bytes(ent) _get_entity_offset_bytes(ent)
318 #define set_entity_offset_bits(ent, offset) _set_entity_offset_bits(ent, offset)
319 #define set_entity_offset_bytes(ent, offset) _set_entity_offset_bytes(ent, offset)
320 #define get_entity_link(ent) _get_entity_link(ent)
321 #define set_entity_link(ent, l) _set_entity_link(ent, l)
322 #define get_entity_irg(ent) _get_entity_irg(ent)
324 # endif /* _ENTITY_T_H_ */