1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer &
7 ** type.c: datastructures to hold type information.
11 # include "irprog.h" /* So that constructors can add the type to global
16 unsigned long type_visited = 0;
23 /*******************************************************************/
25 /*******************************************************************/
28 new_type_class (ident *name)//, int members)
32 res = (type_class *) xmalloc (sizeof (type_class));
33 add_irp_type((type *) res); /* Remember the new type global. */
34 res->kind = k_type_class;
37 res->members = NEW_ARR_F (entity *, 1);
38 res->subtypes = NEW_ARR_F (type_class *, 1);
39 res->supertypes = NEW_ARR_F (type_class *, 1);
46 /* manipulate fields of type_class */
48 get_class_name (type_class *class) {
50 return id_to_str(class->name);
55 get_class_ident (type_class *class) {
61 void set_class_name (type_class *class, char *name);
62 void set_class_ident (type_class *class, ident* ident);
67 add_class_member (type_class *class, entity *member)
69 ARR_APP1 (entity *, class->members, member);
73 get_class_member (type_class *class, int pos)
76 return class->members[pos+1];
80 set_class_member (type_class *class, entity *member, int pos)
82 class->members[pos+1] = member;
87 add_class_subtype (type_class *class, type_class *subtype)
89 ARR_APP1 (type_class *, class->subtypes, subtype);
93 get_class_subtype (type_class *class, int pos)
96 return class->subtypes[pos+1];
100 set_class_subtype (type_class *class, type_class *subtype, int pos)
102 class->subtypes[pos+1] = subtype;
105 /* field: supertype */
107 add_class_supertype (type_class *class, type_class *supertype)
109 ARR_APP1 (type_class *, class->supertypes, supertype);
113 get_class_supertype (type_class *class, int pos)
116 return class->supertypes[pos+1];
120 set_class_supertype (type_class *class, type_class *supertype, int pos)
122 class->supertypes[pos+1] = supertype;
125 /*******************************************************************/
127 /*******************************************************************/
130 new_type_strct (ident *name)//, int members)
134 res = (type_strct *) xmalloc (sizeof (type_strct));
135 add_irp_type((type *) res); /* Remember the new type global. */
136 res->kind = k_type_strct;
139 res->members = NEW_ARR_F (entity *, 1);
145 /* manipulate fields of type_strct */
148 get_strct_name (type_strct *strct) {
150 return ID_TO_STR(strct->name);
155 get_strct_ident (type_strct *strct) {
161 void set_strct_name (type_strct *strct, char *name);
162 void set_strct_ident (type_strct *strct, ident* ident);
166 /*******************************************************************/
168 /*******************************************************************/
170 /* create a new type_method */
172 new_type_method (ident *name, int arity, int n_res)
176 res = (type_method *) xmalloc (sizeof (type_method));
177 add_irp_type((type *) res); /* Remember the new type global. */
178 res->kind = k_type_method;
179 res->name = name; // do I need the name, or is the name in entity sufficient?
181 res->param_type = (type **) xmalloc (sizeof (type *) * arity);
183 res->res_type = (type **) xmalloc (sizeof (type *) * n_res);
190 /* manipulate fields of type_method */
192 get_method_name (type_method *method) {
194 return ID_TO_STR(method->name);
198 get_method_ident (type_method *method) {
204 void set_method_name (type_method *method, char *name);
205 void set_method_ident (type_method *method, ident* ident);
209 get_method_arity (type_method *method) {
210 return method->arity;
215 set_method_arity (type_method *method, int arity) {
216 method->arity = arity;
217 / change array size, somehow copy. *
222 get_method_param_type(type_method *method, int pos) {
223 return method->param_type[pos];
227 set_method_param_type(type_method *method, int pos, type* type) {
228 method->param_type[pos] = type;
233 get_method_n_res (type_method *method) {
234 return method->n_res;
239 set_method_n_res (type_method *method, int n_res) {
240 method->n_res = n_res;
245 get_method_res_type(type_method *method, int pos) {
246 return method->res_type[pos];
250 set_method_res_type(type_method *method, int pos, type* type) {
251 method->res_type[pos] = type;
255 /*******************************************************************/
257 /*******************************************************************/
259 /* create a new type_union -- set unioned types by hand. */
261 new_type_union (ident *name, int n_types)
265 res = (type_union *) xmalloc (sizeof (type_union));
266 add_irp_type((type *) res); /* Remember the new type global. */
267 res->kind = k_type_union;
268 res->name = name; // do I need a name?
269 res->n_types = n_types;
271 res->unioned_type = (int *) xmalloc (sizeof (int) * n_types);
279 /* manipulate fields of type_union */
282 get_union_name (type_union *uni) {
284 return ID_TO_STR(uni->name);
289 get_union_ident (type_union *uni) {
295 void set_union_name (type_union *union, char *name);
296 void set_union_ident (type_union *union, ident* ident);
299 int get_union_n_types (type_union *union);
300 void set_union_n_types (type_union *union, int n);
301 type *get_union_unioned_type (type_union *union, int pos);
302 void set_union_unioned_type (type_union *union, int pos, type *type);
305 /*******************************************************************/
307 /*******************************************************************/
309 /* create a new type_array */
311 new_type_array (ident *name, int n_dimensions)
315 res = (type_array *) xmalloc (sizeof (type_array));
316 add_irp_type((type *) res); /* Remember the new type global. */
317 res->kind = k_type_array;
319 res->n_dimensions = n_dimensions;
320 res->lower_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
321 res->upper_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
328 /* manipulate fields of type_array */
331 get_array_name (type_array *array) {
333 return ID_TO_STR(array->name);
338 get_array_ident (type_array *array) {
344 void set_array_name (type_array *array, char *name);
345 void set_array_ident (type_array *array, ident* ident);
349 set_array_dimensions (type_array* array, int n) {
350 array->n_dimensions = n;
354 get_array_dimensions (type_array* array) {
355 return array->n_dimensions;
359 set_array_bounds (type_array* array, int dimension, int lower_bound,
361 array->lower_bound[dimension-1] = lower_bound;
362 array->upper_bound[dimension-1] = upper_bound;
366 set_array_lower_bound (type_array* array, int dimension, int lower_bound) {
367 array->lower_bound[dimension-1] = lower_bound;
371 set_array_upper_bound (type_array* array, int dimension, int upper_bound) {
372 array->upper_bound[dimension-1] = upper_bound;
376 get_array_lower_bound (type_array* array, int dimension) {
377 return array->lower_bound[dimension-1];
381 get_array_upper_bound (type_array* array, int dimension) {
382 return array->upper_bound[dimension-1];
385 inline void set_array_element_type (type_array *array, type *type) {
386 array->element_type = type;
390 get_array_element_type (type_array *array) {
391 return array->element_type;
395 /*******************************************************************/
396 /** TYPE_ENUMERATION **/
397 /*******************************************************************/
399 /* create a new type enumeration -- set the enumerators independently */
401 new_type_enumeration (ident *name /* , int n_enums */)
403 type_enumeration *res;
405 res = (type_enumeration *) xmalloc (sizeof (type_enumeration));
406 add_irp_type((type *) res); /* Remember the new type global. */
407 res->kind = k_type_enumeration;
410 res->n_enums = n_enums;
411 res->enum = (int *) xmalloc (sizeof (int) * n_enums);
419 /* manipulate fields of type_enumeration */
422 get_enumeration_name (type_enumeration *enumeration) {
424 return ID_TO_STR(enumeration->name);
429 get_enumeration_ident (type_enumeration *enumeration) {
431 return enumeration->name;
435 void set_enumeration_name (type_enumeration *enumeration, char *name);
436 void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
439 void set_enumeration_n_enums (type_enumeration *enumeration, int n);
440 int *get_enumeration_n_enums (type_enumeration *enumeration);
441 void set_enumeration_enum (type_enumeration *enumeration, int pos,
443 ir_node *get_enumeration_enum (type_enumeration *enumeration, int pos);
447 /*******************************************************************/
449 /*******************************************************************/
451 /* create a new type pointer */
453 new_type_pointer (ident *name, type *points_to)
457 res = (type_pointer *) xmalloc (sizeof (type_pointer));
458 add_irp_type((type *) res); /* Remember the new type global. */
459 res->kind = k_type_pointer;
461 res->points_to = points_to;
468 /* manipulate fields of type_pointer */
471 get_pointer_name (type_pointer *pointer) {
473 return ID_TO_STR(pointer->name);
478 get_pointer_ident (type_pointer *pointer) {
480 return pointer->name;
484 void set_pointer_name (type_pointer *pointer, char *name);
485 void set_pointer_ident (type_pointer *pointer, ident* ident);
489 set_pointer_points_to_type (type_pointer *pointer, type* type) {
490 pointer->points_to = type;
494 get_pointer_points_to_type (type_pointer *pointer) {
495 return pointer->points_to;
499 /*******************************************************************/
500 /** TYPE_PRIMITIVE **/
501 /*******************************************************************/
503 /* create a new type_primitive */
504 inline type_primitive *
505 new_type_primitive (ident *name, ir_mode *mode)
509 res = (type_primitive *) xmalloc (sizeof (type_primitive));
510 add_irp_type((type *) res); /* Remember the new type global. */
511 res->kind = k_type_primitive;
520 /* manipulate fields of type_primitive */
524 get_primitive_name (type_primitive *primitive) {
526 return ID_TO_STR(primitive->name);
531 get_primitive_ident (type_primitive *primitive) {
533 return primitive->name;
536 void set_primitive_name (type_primitive *primitive, char *name);
537 void set_primitive_ident (type_primitive *primitive, ident* ident);
541 get_primitive_mode (type_primitive *primitive) {
542 return primitive->mode;
546 set_primitive_mode (type_primitive *primitive, ir_mode *mode) {
547 primitive->mode = mode;
553 /*******************************************************************/
554 /** To manage all different types the same **/
555 /*******************************************************************/
559 is_type(void *thing) {
562 kind = get_kind(thing);
563 if ( (kind == k_type_class)
564 || (kind == k_type_strct)
565 || (kind == k_type_method)
566 || (kind == k_type_union)
567 || (kind == k_type_array)
568 || (kind == k_type_enumeration)
569 || (kind == k_type_pointer)
570 || (kind == k_type_primitive))