bbd11962664381f5b4fa8f151d51e2161f472dc3
[libfirm] / ir / tr / tpop.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/tpop.h
4  * Purpose:     Opcode of types.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 # ifndef _TYPEOP_H_
14 # define _TYPEOP_H_
15
16 #include "ident.h"
17
18 /**
19  *  @file tpop.h
20  *
21  *  This module specifies the kinds of types available in firm.
22  *
23  *  @author  Goetz Lindenmaier
24  *
25  *  They are called type opcodes. These include classes, structs, methods, unions,
26  *  arrays, enumerations, pointers and primitive types.
27  */
28
29 /**
30  *   an enum for the type kinds.
31  *   For each type kind exists a typecode to identify it.
32  */
33 typedef enum {
34   tpo_class,
35   tpo_struct,
36   tpo_method,
37   tpo_union,
38   tpo_array,
39   tpo_enumeration,
40   tpo_pointer,
41   tpo_primitive,
42   tpo_id
43 } tp_opcode;
44
45 /**
46  *   A structure containing information about a kind of type.
47  *   A structure containing information about a kind of type.  So far
48  *   this is only the kind name, an enum for case-switching and some
49  *   internal values.
50  *
51  * @see  get_tpop_name(), get_tpop_code(), get_tpop_ident()
52  */
53 typedef struct tp_op tp_op;
54
55
56 /**
57  *   Returns the string for the type opcode.
58  *
59  *   @param op  The type opcode to get the string from.
60  *   @return a string.  (@todo Null terminated???)
61  */
62 const char *get_tpop_name (tp_op *op);
63
64 /**
65  *   Returns an enum for the type opcode.
66  *
67  *   @param op   The type opcode to get the enum from.
68  *   @return the enum.
69  */
70 tp_opcode get_tpop_code (tp_op *op);
71
72 /**
73  *   Returns the ident for the type opcode.
74  *
75  *   @param op   The type opcode to get the ident from.
76  *   @return The ident.
77  */
78 ident *get_tpop_ident (tp_op *op);
79
80 /**
81  *   This type opcode marks that the corresponding type is a class type.
82  *
83  *   Consequently the type refers to supertypes, subtypes and entities.
84  *   Entities can be any fields, but also methods.
85  *   @@@ value class or not???
86  *   This struct is dynamically allocated but constant for the lifetime
87  *   of the library.
88  */
89 extern tp_op *type_class;
90 tp_op *get_type_class(void);
91
92 /**
93  *   This type opcode marks that the corresponding type is a compound type
94  *   as a struct in C.
95  *
96  *   Consequently the type refers to a list of entities
97  *   which may not be methods (but pointers to methods).
98  *   This struct is dynamically allocated but constant for the lifetime
99  *   of the library.
100  */
101 extern tp_op *type_struct;
102 tp_op *get_type_struct(void);
103
104 /**
105  *   This type opcode marks that the corresponding type is a method type.
106  *
107  *   Consequently it refers to a list of arguments and results.
108  *   This struct is dynamically allocated but constant for the lifetime
109  *   of the library.
110  */
111 extern tp_op *type_method;
112 tp_op *get_type_method(void);
113
114 /**
115  *   This type opcode marks that the corresponding type is a union type.
116  *
117  *   Consequently it refers to a list of unioned types.
118  *   This struct is dynamically allocated but constant for the lifetime
119  *   of the library.
120  */
121 extern tp_op *type_union;
122 tp_op *get_type_union(void);
123
124 /**
125  *   This type opcode marks that the corresponding type is an array type.
126  *
127  *   Consequently it contains a list of dimensions (lower and upper bounds)
128  *   and an element type.
129  *   This struct is dynamically allocated but constant for the lifetime
130  *   of the library.
131  */
132 extern tp_op *type_array;
133 tp_op *get_type_array(void);
134
135 /**
136  *   This type opcode marks that the corresponding type is an enumeration type.
137  *
138  *   Consequently it contains a list of idents for the enumeration identifiers
139  *   and a list of tarbet values that are the constants used to implement
140  *   the enumerators.
141  *   This struct is dynamically allocated but constant for the lifetime
142  *   of the library.
143  */
144 extern tp_op *type_enumeration;
145 tp_op *get_type_enumeration(void);
146
147 /**
148  *   This type opcode marks that the corresponding type is a pointer type.
149  *
150  *   It contains a reference to the type the pointer points to.
151  *   This struct is dynamically allocated but constant for the lifetime
152  *   of the library.
153  */
154 extern tp_op *type_pointer;
155 tp_op *get_type_pointer(void);
156
157 /**
158  *   This type opcode marks that the corresponding type is a primitive type.
159  *
160  *   Primitive types are types that are directly mapped to target machine
161  *   modes.
162  *   This struct is dynamically allocated but constant for the lifetime
163  *   of the library.
164  */
165 extern tp_op *type_primitive;
166 tp_op *get_type_primitive(void);
167
168 /**
169  *   This type opcode is an auxiliary opcode dedicated to support transformations
170  *   of the type structure.
171  *
172  *   If a type is changed to another type with another
173  *   opcode the new type will be allocated with new memory.  All nodes refering
174  *   to the old type need to be changed to refer the new one.  This is simplified
175  *   by turning the old type into an id type that merely forwards to the new type
176  *   that now replaces the old one.
177  *   type_ids should never be visible out of the type module.  All access routines
178  *   should automatically check for type_id and eventually follow the forward in
179  *   type_id.  Two types are exchanged by a call to exchange_types.
180  *   If a type_id is visible externally report this as bug.  If it is assured that
181  *   this never happens this extern variable can be moved to tpop_t.h.
182  *   This struct is dynamically allocated but constant for the lifetime
183  *   of the library.
184  */
185 extern tp_op *type_id;
186 tp_op *get_type_id(void);
187
188 # endif /*_TYPEOP_H_ */