2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Opcode of types.
23 * @author Goetz Lindenmaier, Michael Beck
27 * This module specifies the kinds of types available in firm.
29 * They are called type opcodes. These include classes, structs, methods, unions,
30 * arrays, enumerations, pointers and primitive types.
31 * Special types with own opcodes are the id type, a type representing an unknown
32 * type and a type used to specify that something has no type.
36 #ifndef FIRM_TR_TPOP_H
37 #define FIRM_TR_TPOP_H
42 * An enum for the type kinds.
43 * For each type kind exists a typecode to identify it.
46 tpo_uninitialized = 0, /* not a type opcode */
47 tpo_class, /**< A class type. */
48 tpo_struct, /**< A struct type. */
49 tpo_method, /**< A method type. */
50 tpo_union, /**< An union type. */
51 tpo_array, /**< An array type. */
52 tpo_enumeration, /**< An enumeration type. */
53 tpo_pointer, /**< A pointer type. */
54 tpo_primitive, /**< A primitive type. */
55 tpo_id, /**< Special Id tag used for type replacement. */
56 tpo_none, /**< Special type for the None type. */
57 tpo_unknown, /**< Special code for the Unknown type. */
58 tpo_max /* not a type opcode */
62 * A structure containing information about a kind of type.
63 * A structure containing information about a kind of type. So far
64 * this is only the kind name, an enum for case-switching and some
67 * @see get_tpop_name(), get_tpop_code(), get_tpop_ident()
69 typedef struct tp_op tp_op;
73 * Returns the string for the type opcode.
75 * @param op The type opcode to get the string from.
76 * @return a string. (@todo Null terminated???)
78 const char *get_tpop_name (const tp_op *op);
81 * Returns an enum for the type opcode.
83 * @param op The type opcode to get the enum from.
86 tp_opcode get_tpop_code (const tp_op *op);
89 * Returns the ident for the type opcode.
91 * @param op The type opcode to get the ident from.
94 ident *get_tpop_ident (const tp_op *op);
97 * This type opcode marks that the corresponding type is a class type.
99 * Consequently the type refers to supertypes, subtypes and entities.
100 * Entities can be any fields, but also methods.
101 * @@@ value class or not???
102 * This struct is dynamically allocated but constant for the lifetime
105 extern tp_op *type_class;
106 tp_op *get_tpop_class(void);
109 * This type opcode marks that the corresponding type is a compound type
112 * Consequently the type refers to a list of entities
113 * which may not be methods (but pointers to methods).
114 * This struct is dynamically allocated but constant for the lifetime
117 extern tp_op *type_struct;
118 tp_op *get_tpop_struct(void);
121 * This type opcode marks that the corresponding type is a method type.
123 * Consequently it refers to a list of arguments and results.
124 * This struct is dynamically allocated but constant for the lifetime
127 extern tp_op *type_method;
128 tp_op *get_tpop_method(void);
131 * This type opcode marks that the corresponding type is a union type.
133 * Consequently it refers to a list of unioned types.
134 * This struct is dynamically allocated but constant for the lifetime
137 extern tp_op *type_union;
138 tp_op *get_tpop_union(void);
141 * This type opcode marks that the corresponding type is an array type.
143 * Consequently it contains a list of dimensions (lower and upper bounds)
144 * and an element type.
145 * This struct is dynamically allocated but constant for the lifetime
148 extern tp_op *type_array;
149 tp_op *get_tpop_array(void);
152 * This type opcode marks that the corresponding type is an enumeration type.
154 * Consequently it contains a list of idents for the enumeration identifiers
155 * and a list of target values that are the constants used to implement
157 * This struct is dynamically allocated but constant for the lifetime
160 extern tp_op *type_enumeration;
161 tp_op *get_tpop_enumeration(void);
164 * This type opcode marks that the corresponding type is a pointer type.
166 * It contains a reference to the type the pointer points to.
167 * This struct is dynamically allocated but constant for the lifetime
170 extern tp_op *type_pointer;
171 tp_op *get_tpop_pointer(void);
174 * This type opcode marks that the corresponding type is a primitive type.
176 * Primitive types are types that are directly mapped to target machine
178 * This struct is dynamically allocated but constant for the lifetime
181 extern tp_op *type_primitive;
182 tp_op *get_tpop_primitive(void);
185 * This type opcode is an auxiliary opcode dedicated to support transformations
186 * of the type structure.
188 * If a type is changed to another type with another
189 * opcode the new type will be allocated with new memory. All nodes refering
190 * to the old type need to be changed to refer to the new one. This is simplified
191 * by turning the old type into an id type that merely forwards to the new type
192 * that now replaces the old one.
193 * type_ids should never be visible out of the type module. All access routines
194 * should automatically check for type_id and eventually follow the forward in
195 * type_id. Two types are exchanged by a call to exchange_types.
196 * If a type_id is visible externally report this as bug. If it is assured that
197 * this never happens this extern variable can be moved to tpop_t.h.
198 * This struct is dynamically allocated but constant for the lifetime
201 extern tp_op *type_id;
202 tp_op *get_tpop_id(void);
205 * This type opcode is an auxiliary opcode dedicated to support type analyses.
207 * Types with this opcode represents that there is no type.
208 * The type can be used to initialize fields of the type* that actually can not
209 * contain a type or that are initialized for an analysis. There exists exactly
210 * one type with this opcode.
212 extern tp_op *tpop_none;
213 tp_op *get_tpop_none(void);
216 * This type opcode is an auxiliary opcode dedicated to support type analyses.
218 * Types with this opcode represents that there could be a type, but it is not
219 * known. This type can be used to initialize fields before an analysis (not known
220 * yet) or to represent the top of a lattice (could not be determined). There exists
221 * exactly one type with this opcode.
223 extern tp_op *tpop_unknown;
224 tp_op *get_tpop_unknown(void);
226 #endif /* FIRM_TR_TPOP_H */