*** empty log message ***
[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 # ifndef _ENTITY_H_
47 # define _ENTITY_H_
48
49 # include "ident.h"
50 # include "type.h"
51
52 /*******************************************************************/
53 /** general                                                       **/
54 /*******************************************************************/
55
56 /* initalize entity module */
57 void init_entity (void);
58
59 /*******************************************************************/
60 /** ENTITY                                                        **/
61 /*******************************************************************/
62
63 #ifndef _IR_GRAPH_TYPEDEF_
64 #define _IR_GRAPH_TYPEDEF_
65 /* to resolve recursion between entity.h and irgraph.h */
66 typedef struct ir_graph ir_graph;
67 #endif
68
69 #ifndef _ENTITY_TYPEDEF_
70 #define _ENTITY_TYPEDEF_
71 /* to resolve recursion between entity.h and type.h */
72 typedef struct entity entity;
73 #endif
74
75 /* Creates a new entity.
76    Automatically inserts the entity as a member of owner. */
77 entity     *new_entity (type *owner, ident *name, type *type);
78
79 /* manipulate fields of entity */
80 const char *get_entity_name     (entity *ent);
81 ident      *get_entity_ident    (entity *ent);
82 /* returns the mangled name of the entity */
83 ident      *get_entity_ld_name  (entity *ent);
84
85 /*
86 char     *get_entity_ld_name  (entity *ent);
87 void      set_entity_ld_name  (entity *ent, char *ld_name);
88
89 ident    *get_entity_ld_ident (entity *ent);
90 void      set_entity_ld_ident (entity *ent, ident *ld_ident);
91 */
92
93 type     *get_entity_owner (entity *ent);
94 void      set_entity_owner (entity *ent, type *owner);
95 inline void  assert_legal_owner_of_ent(type *owner);
96
97 type     *get_entity_type (entity *ent);
98 void      set_entity_type (entity *ent, type *type);
99
100 int       get_entity_offset (entity *ent);
101 void      set_entity_offset (entity *ent, int offset);
102
103 /* The entity knows the corresponding irg if the entity is a method.
104    This allows to get from a Call to the called irg. */
105 ir_graph *get_entity_irg(entity *ent);
106 void      set_entity_irg(entity *ent, ir_graph *irg);
107
108
109 # endif /* _ENTITY_H_ */