4 * file type.h - datastructure to hold type information.
6 * (C) 2001 by Universitaet Karlsruhe
11 * This module supplies a datastructure to represent all types
12 * known in the compiled program. This includes types specified
13 * in the program as well as types defined by the language. In the
14 * view of the intermediate representation there is no difference
15 * between these types.
17 * There exist several kinds of types, arranged by the structure of
18 * the type. A type is described by a set of attributes. Some of
19 * these attributes are common to all types, others depend on the
22 * Types are different from the modes defined in irmode: Types are
23 * on the level of the programming language, modes at the level of
24 * the target processor.
39 #ifndef _ENTITY_TYPEDEF_
40 #define _ENTITY_TYPEDEF_
41 /* to resolve recursion between entity.h and type.h */
42 typedef struct entity entity;
48 * type - An abstract data type to represent types.
50 * This is the abstract data type with which any type known in the
51 * compiled program can be represented. This includes types specified
52 * in the program as well as types defined by the language. In the
53 * view of the intermediate representation there is no difference
54 * between these types.
56 * There exist several kinds of types, arranged by the structure of
57 * the type. These are distinguished by a type opcode.
58 * A type is described by a set of attributes. Some of these attributes
59 * are common to all types, others depend on the kind of the type.
61 * The following describes the common attributes. They can only be
62 * accessed by the functions given below.
65 * The common fields are:
67 * firm_kind A firm_kind tag containing k_type. This is useful
68 * for dynamically checking whether a node is a type node.
69 * type_op A tp_op specifying the kind of the type.
70 * mode The mode to be used to represent the type on a machine.
71 * @@@ maybe not global field??
72 * name An identifier specifying the name of the type. To be
73 * set by the frontend.
74 * size The size of the type, i.e. an entity of this type will
75 * occupy size bytes in memory. In several cases this is
76 * determined when fixing the layout of this type (class,
77 * struct, union, array, enumeration).
78 * visit A counter for walks of the type information.
80 * These fields can only be accessed via access functions.
82 * Depending on the value of type_op, i.e., depending on the kind of the
83 * type the adt contains further attributes. These are documented below.
85 * class, struct, method, union, array, enumeration, pointer, primitive
88 typedef struct type type;
90 tp_op* get_type_tpop(type *tp);
91 ident* get_type_tpop_nameid(type *tp);
92 const char* get_type_tpop_name(type *tp);
93 tp_opcode get_type_tpop_code(type *tp);
95 ir_mode* get_type_mode(type *tp);
96 void set_type_mode(type *tp, ir_mode* m);
98 ident* get_type_nameid(type *tp);
99 void set_type_nameid(type *tp, ident* id);
100 const char* get_type_name(type *tp);
102 int get_type_size(type *tp);
103 void set_type_size(type *tp, int size);
105 unsigned long get_type_visited(type *tp);
106 void set_type_visited(type *tp, unsigned long num);
107 /* Sets visited field in type to type_visited. */
108 void mark_type_visited(type *tp);
114 * type_visited - visited flag to traverse the type information
116 * Increase this flag by one before traversing the type information.
117 * Mark type nodes as visited by set_type_visited(type, type_visited).
118 * Check whether node was already visited by comparing get_type_visited(type)
120 * Or use the function to walk all types.
125 extern unsigned long type_visited;
131 * is_type - Checks whether a pointer points to a type.
133 * bool is_type (void *thing);
137 * true if the thing is a type, else false
140 int is_type (void *thing);
144 * Representation of a class type.
146 * If the type opcode is set to type_class the type represents class
147 * types. A list of fields and methods is associated with a class.
148 * Further a class can inherit from and bequest to other classes.
151 * The following attributes are private to this type kind.
152 * member All entities belonging to this class. This are methode entities
153 * which have type_method or fields that can have any of the
154 * following type kinds: type_class, type_struct, type_union,
155 * type_array, type_enumeration, type_pointer, type_primitive.
157 * subtypes A list of direct subclasses.
159 * supertypes A list of direct superclasses.
161 * These are dynamic lists that can be grown with an "add_" function,
165 /* create a new class type */
166 type *new_type_class (ident *name);
168 /* manipulate private fields of class type */
169 void add_class_member (type *clss, entity *member);
170 int get_class_n_member (type *clss);
171 entity *get_class_member (type *clss, int pos);
172 void set_class_member (type *clss, entity *member, int pos);
174 void add_class_subtype (type *clss, type *subtype);
175 int get_class_n_subtype (type *clss);
176 type *get_class_subtype (type *clss, int pos);
177 void set_class_subtype (type *clss, type *subtype, int pos);
179 void add_class_supertype (type *clss, type *supertype);
180 int get_class_n_supertype (type *clss);
181 type *get_class_supertype (type *clss, int pos);
182 void set_class_supertype (type *clss, type *supertype, int pos);
185 bool is_class_type(type *clss);
190 * Representation of a struct type.
192 * Type_strct represents aggregate types that consist of a list
195 * member All entities belonging to this class. This are the fields
196 * that can have any of the following types: type_class,
197 * type_struct, type_union, type_array, type_enumeration,
198 * type_pointer, type_primitive.
199 * This is a dynamic list that can be grown with an "add_" function,
201 * This is a dynamic list that can be grown with an "add_" function,
205 /* create a new type struct */
206 type *new_type_struct (ident *name);
208 /* manipulate private fields of struct */
209 void add_struct_member (type *strct, entity *member);
210 int get_struct_n_member (type *strct);
211 entity *get_struct_member (type *strct, int pos);
212 void set_struct_member (type *strct, int pos, entity *member);
215 bool is_struct_type(type *strct);
220 * Representation of a method type.
222 * A method type represents a method, function or procedure type.
223 * It contains a list of the parameter and result types, as these
224 * are part of the type description. These lists should not
225 * be changed by a optimization, as a change creates a new method
226 * type. Therefore optimizations should allocated new method types.
227 * The set_ routines are only for construction by a frontend.
229 * n_params Number of parameters to the procedure.
230 * A procedure in FIRM has only call by value parameters.
232 * param_type A list with the types of parameters. This list is ordered.
233 * The nth type in this list corresponds to the nth element
234 * in the parameter tuple that is a result of the start node.
235 * (See ircons.h for more information.)
237 * n_res The number of results of the method. In general, procedures
238 * have zero results, functions one.
240 * res_type A list with the types of parameters. This list is ordered.
241 * The nth type in this list corresponds to the nth input to
242 * Return nodes. (See ircons.h for more information.)
246 /* Create a new method type.
247 N_param is the number of parameters, n_res the number of results.
248 The arrays for the parameter and result types are not initialized by
250 type *new_type_method (ident *name, int n_param, int n_res);
252 /* manipulate private fields of method. */
253 int get_method_n_params (type *method);
254 type *get_method_param_type(type *method, int pos);
255 void set_method_param_type(type *method, int pos, type* type);
257 int get_method_n_res (type *method);
258 type *get_method_res_type(type *method, int pos);
259 void set_method_res_type(type *method, int pos, type* type);
262 bool is_method_type (type *method);
267 * Representation of a union type.
269 * The union type represents union types.
271 * n_types Number of unioned types.
272 * members Entities for unioned types. Fixed length array.
273 * This is a dynamic list that can be grown with an "add_" function,
277 /* create a new type union */
278 type *new_type_union (ident *name);
280 /* manipulate private fields of struct */
281 int get_union_n_members (type *uni);
282 void add_union_member (type *uni, entity *member);
283 entity *get_union_member (type *uni, int pos);
284 void set_union_member (type *uni, int pos, entity *member);
287 bool is_union_type (type *uni);
291 /* We don't need these if the union has entities, which it now
292 does. The entities are necessary for the analysis algorithms. */
293 type *get_union_unioned_type (type *uni, int pos);
294 void set_union_unioned_type (type *uni, int pos, type *type);
296 ident *get_union_delim_nameid (type *uni, int pos);
297 const char *get_union_delim_name (type *uni, int pos);
298 void set_union_delim_nameid (type *uni, int pos, ident *id);
303 * Representation of an array type.
305 * The array type represents rectangular multi dimensional arrays.
307 * n_dimensions Number of array dimensions.
308 * *lower_bound Lower bounds of dimensions. Usually all 0.
309 * *upper_bound Upper bounds or dimensions.
310 * *element_type The type of the array elements.
313 /* create a new type array -- set dimension sizes independently */
314 type *new_type_array (ident *name, int n_dimensions);
316 /* manipulate private fields of array type */
317 int get_array_n_dimensions (type *array);
318 void set_array_bounds (type *array, int dimension, int lower_bound,
320 void set_array_lower_bound (type *array, int dimension, int lower_bound);
321 void set_array_upper_bound (type *array, int dimension, int upper_bound);
322 int get_array_lower_bound (type *array, int dimension);
323 int get_array_upper_bound (type *array, int dimension);
325 void set_array_element_type (type *array, type *type);
326 type *get_array_element_type (type *array);
329 bool is_array_type (type *array);
332 /****** type/enumeration
334 * Representation of an enumeration type.
336 * Enumeration types need not necessarily be represented explicitly
337 * by Firm types, as the frontend can lower them to integer constants as
338 * well. For debugging purposes or similar tasks this information is useful.
340 * *enum The target values representing the constants used to
341 * represent individual enumerations.
342 * *enum_nameid Idents containing the source program name of the enumeration
347 /* create a new type enumeration -- set the enumerators independently */
348 type *new_type_enumeration (ident *name, int n_enums);
350 /* manipulate fields of enumeration type. */
351 int get_enumeration_n_enums (type *enumeration);
353 void set_enumeration_enum (type *enumeration, int pos, tarval *con);
354 tarval *get_enumeration_enum (type *enumeration, int pos);
356 void set_enumeration_nameid (type *enumeration, int pos, ident *id);
357 ident *get_enumeration_nameid (type *enumeration, int pos);
358 const char *get_enumeration_name(type *enumeration, int pos);
361 bool is_enumeration_type (type *enumeration);
366 * Representation of a pointer type.
370 * points_to The type of the entity this pointer points to.
373 /* Create a new type pointer */
374 type *new_type_pointer (ident *name, type *points_to);
376 /* manipulate fields of type_pointer */
377 void set_pointer_points_to_type (type *pointer, type *type);
378 type *get_pointer_points_to_type (type *pointer);
381 bool is_pointer_type (type *pointer);
384 /****** type/primitive
386 * Representation of a primitive type.
388 * Primitive types are types that represent indivisible data values that
389 * map directly to modes. They don't have a private attribute. The
390 * important information they carry is held in the common mode field.
393 /* create a new type primitive */
394 type *new_type_primitive (ident *name, ir_mode *mode);
397 bool is_primitive_type (type *primitive);
400 # endif /* _TYPE_H_ */