Dumping pointers differently
[libfirm] / ir / tr / entity.h
1 /*
2 **  Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
3 **  All rights reserved.
4 **
5 **  Authors: Martin Trapp, Christian Schaefer,
6 **           Goetz Lindenmaier
7 **
8 **  entity.h:  entities represent all program known objects.
9 **
10 **  An entity is the representation of program known objects in Firm.
11 **  The primary concept of entities is to represent members of complex
12 **  types, i.e., fields and methods of classes.  As not all programming
13 **  language model all variables and methods as members of some class,
14 **  the concept of entities is extended to cover also local and global
15 **  variables, and arbitrary procedures.
16 **
17 **  An entity always specifies the type of the object it represents and
18 **  the type of the object it is a part of, the owner of the entity.
19 **  Originally this is the type of the class of which the entity is a
20 **  member.
21 **  The owner of local variables is the procedure they are defined in.
22 **  The owner of global variables and procedures visible in the whole
23 **  program is a universally defined class type "GlobalType".  The owner
24 **  of procedures defined in the scope of an other procedure is the
25 **  enclosing procedure.
26 **
27 **  In detail the datastructure entity has the following fields:
28 **
29 **  ident *name     Name of this entity as specified in the source code.
30 **                  Only unequivocal in conjuction with scope.
31 **  ident *ld_name  Unique name of this entity, i.e., the mangled
32 **                  name.  E.g., for a class `A' with field `a' this
33 **                  is the ident for `A_a'.
34 **  type *type      The type of this entity, e.g., a method type, a
35 **                  basic type of the language or a class itself.
36 **  type *owner;    The class this entity belongs to.  In case of local
37 **                  variables the method they are defined in.
38 **  int offset;     Offset in byte for this entity.  Fixed when layout
39 **                  of owner is determined.
40 **  ir_graph *irg;  If (type == method_type) this is the corresponding irg.
41 **                  The ir_graph constructor automatically sets this field.
42 **                  If (type !- method_type) access of this field will cause
43 **                  an assertion.
44 */
45
46 /* $Id$ */
47
48 # ifndef _ENTITY_H_
49 # define _ENTITY_H_
50
51 # include "ident.h"
52 # include "type.h"
53
54 /*******************************************************************/
55 /** general                                                       **/
56 /*******************************************************************/
57
58 /* initalize entity module */
59 void init_entity (void);
60
61 /*******************************************************************/
62 /** ENTITY                                                        **/
63 /*******************************************************************/
64
65 #ifndef _IR_GRAPH_TYPEDEF_
66 #define _IR_GRAPH_TYPEDEF_
67 /* to resolve recursion between entity.h and irgraph.h */
68 typedef struct ir_graph ir_graph;
69 #endif
70
71 /****s* entity/entity
72  *
73  * NAME
74  *   entity - An abstract data type to represent program entites.
75  * NOTE
76  *
77  * ATTRIBUTES
78  *   owner      A compound type this entity is a part of.
79  *   type       The type of this entity.
80  *   name       The string that represents this entity in the source program.
81  *   allocation A flag saying whether the entity is dynamically or statically
82  *              allocated (values: dynamic_allocated,  static_allocated,
83  *              automatic_allocated).
84  *   visibility A flag indicating the visibility of this entity (values: local,
85  *              external_visible,  external_allocated)
86  *   variability A flag indicating the variability of this entity (values:
87  *              uninitialized, initalized, part_constant, constant)
88  *   offset     The offset of the entity within the compound object.  Only set
89  *              if the owner in the state "layout_fixed".
90  *   overwrites A list of entities overwritten by this entity.  This list is only
91  *              existent if the owner of this entity is a class.  The members in
92  *              this list must be entities of super classes.
93  *   overwrittenby A list of entities that overwrite this entity.  This list is only
94  *              existent if the owner of this entity is a class.  The members in
95  *              this list must be entities of sub classes.
96  *   link       A void* to associate some additional information with the entity.
97  *   irg        If the entity is a method this is the ir graph that represents the
98  *              code of the method.
99  *   peculiarity The peculiarity of the entity.  If the entity is a method this
100  *              indicates whether the entity represents
101  *              a real method or whether it only exists to describe an interface.
102  *              In that case there nowhere exists code for this entity and this entity
103  *              is never dynamically used in the code.
104  *              Values: description, existent.  Default: existent.
105  *
106  *  These fields can only be accessed via access functions.
107  *
108  * SEE ALSO
109  *   type
110  * SOURCE
111  */
112
113 #ifndef _ENTITY_TYPEDEF_
114 #define _ENTITY_TYPEDEF_
115 /* to resolve recursion between entity.h and type.h */
116 typedef struct entity entity;
117 #endif
118
119 /* Creates a new entity.
120    Automatically inserts the entity as a member of owner.
121    Entity is automatic_allocated and uninitialize except if the type
122    is type_method, then it is static_allocated and constant.  The constant
123    value is a pointer to the method.
124    Visibility is local, offset -1, and it is not volatile. */
125 entity     *new_entity (type *owner, ident *name, type *type);
126 /* Copies the entity if the new_owner is different from the
127    owner of the old entity.  Else returns the old entity.
128    Automatically inserts the new entity as a member of owner. */
129 entity     *copy_entity_own (entity *old, type *new_owner);
130 /* Copies the entity if the new_name is different from the
131    name of the old entity.  Else returns the old entity.
132    Automatically inserts the new entity as a member of owner.
133    The mangled name ld_name is set to NULL. */
134 entity     *copy_entity_name (entity *old, ident *new_name);
135
136 /** manipulate fields of entity **/
137 const char *get_entity_name     (entity *ent);
138 ident      *get_entity_ident    (entity *ent);
139 /* returns the mangled name of the entity.  If the mangled name is
140    set it returns the existing name.  Else it generates a name
141    with mangle_entity() and remembers this new name internally. */
142 ident      *get_entity_ld_ident (entity *ent);
143 void        set_entity_ld_ident (entity *ent, ident *ld_ident);
144 const char *get_entity_ld_name (entity *end);
145
146 /*
147 char       *get_entity_ld_name  (entity *ent);
148 void        set_entity_ld_name  (entity *ent, char *ld_name);
149 */
150
151 type       *get_entity_owner (entity *ent);
152 /* Sets the owner field in entity to owner. */
153 void        set_entity_owner (entity *ent, type *owner);
154 inline void assert_legal_owner_of_ent(type *owner);
155
156 type     *get_entity_type (entity *ent);
157 void      set_entity_type (entity *ent, type *type);
158
159 typedef enum {
160   automatic_allocated,/* The entity is allocated during runtime, implicitly
161                          as component of a compound type.   This is the default. */
162   dynamic_allocated,  /* The entity is allocated during runtime, explicitly
163                          by an Alloc node. */
164   static_allocated    /* The entity is allocated statically.  We can use a
165                          SymConst(?) as address of the entity. */
166 } ent_allocation;
167
168 ent_allocation get_entity_allocation (entity *ent);
169 void           set_entity_allocation (entity *ent, ent_allocation al);
170
171 /* This enumeration flags the visibility of entities.  This is necessary
172    for partial compilation. */
173 typedef enum {
174   local,              /* The entity is only visible locally.  This is the default. */
175   external_visible,   /* The entity is visible to other external program parts, but
176                          it is defined here.  It may not be optimized away.  The entity must
177                          be static_allocated. */
178   external_allocated  /* The entity is defined and allocated externaly.  This compilation
179                          must not allocate memory for this entity. The entity must
180                          be static_allocated. */
181 } ent_visibility;
182
183 ent_visibility get_entity_visibility (entity *ent);
184 void           set_entity_visibility (entity *ent, ent_visibility vis);
185
186 /* This enumeration flags the variability of entities. */
187 typedef enum {
188   uninitialized,    /* The content of the entity is completely unknown. */
189   initialized,       /* After allocation the entity is initalized with the
190                        value given somewhere in the entity. */
191   part_constant,    /* For entities of compound types.  Some members of the entity
192                        are constant.  The others are uninitialized.  Those members
193                        given a value for are constant. */
194   constant          /* The entity is constant. */
195 } ent_variability;
196
197 ent_variability get_entity_variability (entity *ent);
198 void            set_entity_variability (entity *ent, ent_variability var);
199
200 /* This enumeration flags the volatility of entities. */
201 typedef enum {
202   non_volatile,    /* The entity is not volatile */
203   is_volatile      /* The entity is volatile */
204 } ent_volatility;
205
206 ent_volatility get_entity_volatility (entity *ent);
207 void           set_entity_volatility (entity *ent, ent_volatility vol);
208
209 /* For the definition of enumeration peculiarity see type.h */
210 peculiarity get_entity_peculiarity (entity *ent);
211 void        set_entity_peculiarity (entity *ent, peculiarity pec);
212
213 /* Set has no effect for entities of type method. */
214 ir_node *get_atomic_ent_value(entity *ent);
215 void     set_atomic_ent_value(entity *ent, ir_node *val);
216 /* Copies the value represented by the entity to current_block
217    in current_ir_graph. */
218 ir_node *copy_atomic_ent_value(entity *ent);
219
220 /* A value of a compound entity is a pair of value and the corresponding
221    member of the compound. */
222 void     add_compound_ent_value(entity *ent, ir_node *val, entity *member);
223 int      get_compound_ent_n_values(entity *ent);
224 ir_node *get_compound_ent_value(entity *ent, int pos);
225 entity  *get_compound_ent_value_member(entity *ent, int pos);
226 void     set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos);
227 /* Inits the entity ent witch must be of a one dimensional
228    array type with the values given in the values array.
229    The array must have a lower and an upper bound.  Keeps the
230    order of values. Does not test whether the number of values
231    fits into the given array size.  Does not test whether the
232    values have the proper mode for the array. */
233 void set_array_entity_values(entity *ent, tarval **values, int num_vals);
234 /* Copies the value pos of the entity to current_block in current_ir_graph. */
235 ir_node *copy_compound_ent_value(entity *ent, int pos);
236
237 /* Only set if layout = fixed. */
238 int       get_entity_offset (entity *ent);
239 void      set_entity_offset (entity *ent, int offset);
240
241 /* Overwrites is a field that specifies that an access to the overwritten
242    entity in the supertype must use this entity.  It's a list as with
243    multiple inheritance several enitites can be overwritten.  This field
244    is mostly useful for method entities.
245    If a Sel node selects an entity that is overwritten by other entities it
246    must return a pointer to the entity of the dynamic type of the pointer
247    that is passed to it.  Lowering of the Sel node must assure this.
248    Overwrittenby is the inverse of overwrites.  Both add routines add
249    both relations, they only differ in the order of arguments. */
250 void    add_entity_overwrites   (entity *ent, entity *overwritten);
251 int     get_entity_n_overwrites (entity *ent);
252 entity *get_entity_overwrites   (entity *ent, int pos);
253 void    set_entity_overwrites   (entity *ent, int pos, entity *overwritten);
254 void    add_entity_overwrittenby   (entity *ent, entity *overwrites);
255 int     get_entity_n_overwrittenby (entity *ent);
256 entity *get_entity_overwrittenby   (entity *ent, int pos);
257 void    set_entity_overwrittenby   (entity *ent, int pos, entity *overwrites);
258
259 /* A link to store intermediate information */
260 void*   get_entity_link(entity *ent);
261 void    set_entity_link(entity *ent, void *l);
262
263 /* The entity knows the corresponding irg if the entity is a method.
264    This allows to get from a Call to the called irg.
265    Only entities of peculiarity "existent" can have a corresponding irg,
266    else the field is fixed to NULL.  (Get returns NULL, set asserts.) */
267 ir_graph *get_entity_irg(entity *ent);
268 void      set_entity_irg(entity *ent, ir_graph *irg);
269
270
271 /* Returns true if the type of the entity is a primitive, pointer
272    enumeration or method type. */
273 int is_atomic_entity(entity *ent);
274 /* Returns true if the type of the entity is a class, structure,
275    array or union type. */
276 int is_compound_entity(entity *ent);
277
278
279 /*****/
280
281 # endif /* _ENTITY_H_ */