1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer &
8 @@@@@@@ Improve documentation: distinguish fields that are
9 set by the frontend and contain knowledge specified by the source
10 program from fields containing information derived by analysis/optimization
14 ** type.h: datastructures to hold type information.
16 ** This module supplies datastructures to represent all types
17 ** known in the compiled program. This includes types specified
18 ** in the program as well as types defined by the language. In the
19 ** view of the intermediate representation there is no difference
20 ** between these types.
21 ** Types are different from the modes defined in irmode: Types are
22 ** on the level of the programming language, modes at the level of
23 ** the target processor.
26 ** General datastructure
27 ** =====================
29 ** Firm distinguishes several different type constructs. These are
30 ** implemented as structs. A union of the individual structs constructs
31 ** the firm node "type".
33 ** All type constructs have the following fields:
35 ** kind A firm_kind tag containing k_type_class. This is useful
36 ** for dynamically checking the sort of a type. Automatically
39 ** name An identifier specifying the type name. Set by the frontend.
41 ** visit A counter for walks of the type information.
44 ** General functionality
45 ** =====================
47 ** is_type(t) Returns true if t is a type node, else false.
53 ** Type_class represents class types. A list of fields and
54 ** methods is associated with a class. Further a class can
55 ** inherit from and bequest to other classes.
60 ** **member All entities belonging to this class. This are methodes
61 ** which have type_method or fields that can have any of the
62 ** following types: k_type_class, k_type_strct, k_type_union,
63 ** k_type_array, k_type_enumeration, k_type_pointer, k_type_primitive.
65 ** **subtypes A list of direct subclasses.
67 ** **supertypes A list of direct superclasses.
73 ** Type_strct represents aggregate types that consist of a list
79 ** **member All entities belonging to this class. This are the fields
80 ** that can have any of the following types: k_type_class,
81 ** k_type_strct, k_type_union, k_type_array, k_type_enumeration,
82 ** k_type_pointer, k_type_primitive.
87 ** Type_method represents method, function and procedure types.
92 ** arity Number of parameters to the procedure. @@@ better n_params
93 ** A procedure in FIRM has only call by value parameters.
95 ** **param_type A list with the types of parameters. This list is ordered.
96 ** The nth type in this list corresponds to the nth element
97 ** in the parameter tuple that is a result of the start node.
98 ** (See ircons.h for more information.)
100 ** n_res The number of results of the method. In general, procedures
101 ** have zero results, functions one.
103 ** **res_type A list with the types of parameters. This list is ordered.
104 ** The nth type in this list corresponds to the nth input to
105 ** Return nodes. (See ircons.h for more information.)
111 ** Type_union represents union types.
116 ** **unioned_type A list of unioned types.
122 ** Type_array represents rectangular multi dimensional arrays.
127 ** n_dimensions Number of array dimensions.
129 ** *lower_bound Lower bounds of dimensions. Mostly all 0.
131 ** *upper_bound Upper bounds or dimensions.
133 ** *element_type The type of the array elements.
139 ** Enumeration types. These need not necessarily be represented explicitly
140 ** by Firm types, as the frontend can lower them to integer constants as
141 ** well. For debugging purposes or similar tasks this information is useful.
146 ** **enum The target values representing the constants used to
147 ** represent individual enumerations.
149 ** **enum_name Idents containing the source program name of the enumeration
160 ** *mode The mode used to implement a pointer. @@@ So far this field
161 ** is constant and set to mode_P. Maybe we will move this
162 ** to a global constant (irprog), or are there processors
163 ** that require a set of different pointer modes?
165 ** *points_to The type of the entity this pointer points to.
170 ** Primitive types are types that represent indivisible data values that
171 ** map directly to modes.
176 ** mode The mode to be used for this type.
187 #ifndef _ENTITY_TYPEDEF_
188 #define _ENTITY_TYPEDEF_
189 /* to resolve recursion between entity.h and type.h */
190 typedef struct entity entity;
193 /* for recursive type definiton */
194 //#ifndef _TYPE_TYPEDEF_
195 //#define _TYPE_TYPEDEF_
196 /* to resolve recursion between entity.h and irgraph.h */
197 typedef union type type;
201 /* visited flag to traverse the type information */
202 extern unsigned long type_visited;
204 /*******************************************************************/
206 /*******************************************************************/
208 typedef struct type_class type_class;
212 ident *name; /* needs list with it's entities
214 Entities can be added during their creation. */
215 struct entity **members; /* to represent inheritance */
216 type_class **subtypes; /* direct subtypes */
217 type_class **supertypes; /* direct supertypes */
218 unsigned long visit; /* visited counter for walks of
219 the type information */
223 /* create a new type_class */
224 type_class *new_type_class (ident *name);
226 /* manipulate fields of type_class */
228 const char *get_class_name (type_class *class);
229 ident *get_class_ident (type_class *class);
231 /* Not necessary now!
232 void set_class_name (type_class *class, char *name);
233 void set_class_ident (type_class *class, ident* ident);
236 void add_class_member (type_class *class, entity *member);
237 int get_class_n_member (type_class *class);
238 entity *get_class_member (type_class *class, int pos);
239 void set_class_member (type_class *class, entity *member, int pos);
241 void add_class_subtype (type_class *class,type_class *subtype);
242 int get_class_n_subtype (type_class *class);
243 type_class *get_class_subtype (type_class *class, int pos);
244 void set_class_subtype (type_class *class, type_class *subtype, int pos);
246 void add_class_supertype (type_class *class, type_class *supertype);
247 int get_class_n_supertype (type_class *class);
248 type_class *get_class_supertype (type_class *class, int pos);
249 void set_class_supertype (type_class *class, type_class *supertype, int pos);
251 /*******************************************************************/
253 /*******************************************************************/
259 unsigned long visit; /* visited counter for walks of the type information */
263 /* create a new type_strct */
264 type_strct *new_type_strct (ident *name);
266 /* manipulate fields of type_strct */
267 const char *get_strct_name (type_strct *strct);
268 ident *get_strct_ident (type_strct *strct);
270 void add_strct_member (type_strct *strct, entity *member);
271 int get_strct_n_member (type_strct *strct);
272 entity *get_strct_member (type_strct *strct, int pos);
273 void set_strct_member (type_strct *strct, int pos, entity *member);
276 void set_strct_name (type_strct *strct, char *name);
277 void set_strct_ident (type_strct *strct, ident* ident);
281 /*******************************************************************/
283 /*******************************************************************/
287 ident *name; /* Name of the method type. Usually method
288 types are not explicitly named (but the entity). */
289 int arity; /* number of parameters, better n_params */
290 type **param_type; /* code generation needs this information.
291 Should it be generated by the frontend,
292 or does this impose unnecessary work for
293 optimizations that change the parameters of
295 int n_res; /* number of results */
296 type **res_type; /* array with result types */
297 unsigned long visit; /* visited counter for walks of the type information */
300 /* Create a new type_method.
301 Arity is the number of parameters. */
302 type_method *new_type_method (ident *name, int arity, int n_res);
304 /* manipulate fields of type_method */
305 const char *get_method_name (type_method *method);
306 ident *get_method_ident (type_method *method);
308 void set_method_name (type_method *method, char *name);
309 void set_method_ident (type_method *method, ident* ident); */
311 inline int get_method_n_params (type_method *method);
312 inline int get_method_arity (type_method *method);
313 /*inline void set_method_arity (type_method *method, int arity);*/
314 inline type *get_method_param_type(type_method *method, int pos);
315 inline void set_method_param_type(type_method *method, int pos, type* type);
317 inline int get_method_n_res (type_method *method);
318 /*inline void set_method_n_res (type_method *method, int n_res);*/
319 inline type *get_method_res_type(type_method *method, int pos);
320 inline void set_method_res_type(type_method *method, int pos, type* type);
323 /*******************************************************************/
325 /*******************************************************************/
329 ident *name; /* do I need a name? */
331 /* type **unioned_type; ... or something like that? */
332 unsigned long visit; /* visited counter for walks of the type information */
335 /* create a new type_union -- set unioned types by hand. */
336 type_union *new_type_union (ident *name, int n_types);
338 /* manipulate fields of type_union */
339 const char *get_union_name (type_union *uni);
340 ident *get_union_ident (type_union *uni);
342 void set_union_name (type_union *union, char *name);
343 void set_union_ident (type_union *union, ident* ident);
346 int get_union_n_types (type_union *union);
347 void set_union_n_types (type_union *union, int n);
348 type *get_union_unioned_type (type_union *union, int pos);
349 void set_union_unioned_type (type_union *union, int pos, type *type);
352 /*******************************************************************/
354 /*******************************************************************/
356 /* multidimensional, polyhedric arrays */
364 unsigned long visit; /* visited counter for walks of the type information */
367 /* create a new type array -- set dimension sizes independently */
368 type_array *new_type_array (ident *name, int n_dimensions);
370 /* manipulate fields of type_array */
371 const char *get_array_name (type_array *array);
372 ident *get_array_ident (type_array *array);
374 void set_array_name (type_array *array, char *name);
375 void set_array_ident (type_array *array, ident* ident);
377 void set_array_n_dimensions (type_array *array, int n);
378 int get_array_n_dimensions (type_array *array);
380 void set_array_bounds (type_array *array, int dimension, int lower_bound,
382 void set_array_lower_bound (type_array *array, int dimension, int lower_bound);
383 void set_array_upper_bound (type_array *array, int dimension, int upper_bound);
384 int get_array_lower_bound (type_array *array, int dimension);
385 int get_array_upper_bound (type_array *array, int dimension);
387 void set_array_element_type (type_array *array, type *type);
388 type *get_array_element_type (type_array *array);
390 /*******************************************************************/
391 /** TYPE_ENUMERATION **/
392 /*******************************************************************/
393 /** Enums are needed to keep debugging information. They can as well
394 be lowered to integers. **/
400 tarval **enum * Contains all constant nodes that represent a member
401 of the enum -- enumerators. */
403 ident **enum_name * Contains the names of the enum fields as specified by
404 the source program */
405 /* is ir_node the propper array member? */
406 unsigned long visit; /* visited counter for walks of the type information */
409 /* create a new type enumeration -- set the enumerators independently */
410 type_enumeration *new_type_enumeration (ident *name /* , int n_enums */);
412 /* manipulate fields of type_enumeration */
413 const char *get_enumeration_name (type_enumeration *enumeration);
414 ident *get_enumeration_ident (type_enumeration *enumeration);
416 void set_enumeration_name (type_enumeration *enumeration, char *name);
417 void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
420 void set_enumeration_n_enums (type_enumeration *enumeration, int n);
421 int *get_enumeration_n_enums (type_enumeration *enumeration);
422 void set_enumeration_enum (type_enumeration *enumeration, int pos,
424 ir_node *get_enumeration_enum (type_enumeration *enumeration, int pos);
427 /*******************************************************************/
429 /*******************************************************************/
434 /* ir_mode *mode; * The mode to be used for this type.
435 Not here as there might be several pointer types?
436 A method get_pointer_mode should read a unique,
439 unsigned long visit; /* visited counter for walks of the type information */
442 /* create a new type pointer */
443 type_pointer *new_type_pointer (ident *name, type *points_to);
445 /* manipulate fields of type_pointer */
446 const char *get_pointer_name (type_pointer *pointer);
447 ident *get_pointer_ident (type_pointer *pointer);
449 void set_pointer_name (type_pointer *pointer, char *name);
450 void set_pointer_ident (type_pointer *pointer, ident* ident);
452 void set_pointer_points_to_type (type_pointer *pointer, type *type);
453 type *get_pointer_points_to_type (type_pointer *pointer);
455 /*******************************************************************/
456 /** TYPE_PRIMITIVE **/
457 /*******************************************************************/
459 /* primitive, language-defined types */
460 /* What is the type of an entity if it is atomic? Are alle basic data
461 types classses in Sather? Else this is needed. */
465 ir_mode *mode; /* The mode to be used for this type */
466 unsigned long visit; /* visited counter for walks of the type information */
469 /* create a new type primitive */
470 type_primitive *new_type_primitive (ident *name, ir_mode *mode);
472 /* manipulate fields of type_primitive */
473 const char *get_primitive_name (type_primitive *primitive);
474 ident *get_primitive_ident (type_primitive *primitive);
476 void set_primitive_name (type_primitive *primitive, char *name);
477 void set_primitive_ident (type_primitive *primitive, ident* ident);
479 ir_mode *get_primitive_mode (type_primitive *primitive);
480 void set_primitive_mode (type_primitive *primitive, ir_mode *mode);
485 /*******************************************************************/
486 /** To manage all different types the same **/
487 /*******************************************************************/
495 type_union uni; /* union is keyword */
496 type_enumeration enumeration;
497 type_pointer pointer;
498 type_primitive primitive;
502 int is_type(void *thing);
507 # endif /* _TYPE_H_ */