2 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
3 ** All rights reserved.
5 ** Authors: Martin Trapp, Christian Schaefer &
8 ** type.c: datastructures to hold type information.
12 # include "irprog.h" /* So that constructors can add the type to global
17 unsigned long type_visited = 0;
24 /*******************************************************************/
26 /*******************************************************************/
29 new_type_class (ident *name)//, int members)
33 res = (type_class *) xmalloc (sizeof (type_class));
34 add_irp_type((type *) res); /* Remember the new type global. */
35 res->kind = k_type_class;
38 res->members = NEW_ARR_F (entity *, 1);
39 res->subtypes = NEW_ARR_F (type_class *, 1);
40 res->supertypes = NEW_ARR_F (type_class *, 1);
47 /* manipulate fields of type_class */
49 get_class_name (type_class *clss) {
51 return id_to_str(clss->name);
56 get_class_ident (type_class *clss) {
62 void set_class_name (type_class *clss, char *name);
63 void set_class_ident (type_class *clss, ident* ident);
68 add_class_member (type_class *clss, entity *member)
70 ARR_APP1 (entity *, clss->members, member);
74 get_class_member (type_class *clss, int pos)
77 return clss->members[pos+1];
81 set_class_member (type_class *clss, entity *member, int pos)
83 clss->members[pos+1] = member;
87 get_class_n_member (type_class *clss)
92 res = (ARR_LEN (clss->members))-1;
98 add_class_subtype (type_class *clss, type_class *subtype)
100 ARR_APP1 (type_class *, clss->subtypes, subtype);
104 get_class_subtype (type_class *clss, int pos)
107 return clss->subtypes[pos+1];
111 set_class_subtype (type_class *clss, type_class *subtype, int pos)
113 clss->subtypes[pos+1] = subtype;
117 get_class_n_subtype (type_class *clss)
120 return (ARR_LEN (clss->subtypes))-1;
123 /* field: supertype */
125 add_class_supertype (type_class *clss, type_class *supertype)
127 ARR_APP1 (type_class *, clss->supertypes, supertype);
131 get_class_supertype (type_class *clss, int pos)
134 return clss->supertypes[pos+1];
138 set_class_supertype (type_class *clss, type_class *supertype, int pos)
140 clss->supertypes[pos+1] = supertype;
144 get_class_n_supertype (type_class *clss)
147 return (ARR_LEN (clss->supertypes))-1;
151 get_class_size (type_class *clss) {
157 set_class_size (type_class *clss, int size) {
163 /*******************************************************************/
165 /*******************************************************************/
168 new_type_strct (ident *name)//, int members)
172 res = (type_strct *) xmalloc (sizeof (type_strct));
173 add_irp_type((type *) res); /* Remember the new type global. */
174 res->kind = k_type_strct;
177 res->members = NEW_ARR_F (entity *, 1);
183 /* manipulate fields of type_strct */
186 get_strct_name (type_strct *strct) {
188 return ID_TO_STR(strct->name);
193 get_strct_ident (type_strct *strct) {
199 get_strct_n_member (type_strct *strct)
204 res = (ARR_LEN (strct->members))-1;
209 add_strct_member (type_strct *strct, entity *member)
211 ARR_APP1 (type_strct *, strct->members, member);
215 get_strct_member (type_strct *strct, int pos)
218 return strct->members[pos+1];
222 set_strct_member (type_strct *strct, int pos, entity *member)
224 strct->members[pos+1] = member;
228 void set_strct_name (type_strct *strct, char *name);
229 void set_strct_ident (type_strct *strct, ident* ident);
233 /*******************************************************************/
235 /*******************************************************************/
237 /* create a new type_method */
239 new_type_method (ident *name, int arity, int n_res)
243 res = (type_method *) xmalloc (sizeof (type_method));
244 add_irp_type((type *) res); /* Remember the new type global. */
245 res->kind = k_type_method;
247 res->name = name; // do I need the name, or is the name in entity sufficient?
249 res->param_type = (type **) xmalloc (sizeof (type *) * arity);
251 res->res_type = (type **) xmalloc (sizeof (type *) * n_res);
258 /* manipulate fields of type_method */
260 get_method_name (type_method *method) {
262 return ID_TO_STR(method->name);
266 get_method_ident (type_method *method) {
272 void set_method_name (type_method *method, char *name);
273 void set_method_ident (type_method *method, ident* ident);
278 get_method_n_params (type_method *method) {
279 return method->arity;
283 get_method_arity (type_method *method) {
284 return method->arity;
289 set_method_arity (type_method *method, int arity) {
290 method->arity = arity;
291 / change array size, somehow copy. *
296 get_method_param_type(type_method *method, int pos) {
297 return method->param_type[pos];
301 set_method_param_type(type_method *method, int pos, type* type) {
302 method->param_type[pos] = type;
307 get_method_n_res (type_method *method) {
308 return method->n_res;
313 set_method_n_res (type_method *method, int n_res) {
314 method->n_res = n_res;
319 get_method_res_type(type_method *method, int pos) {
320 return method->res_type[pos];
324 set_method_res_type(type_method *method, int pos, type* type) {
325 method->res_type[pos] = type;
329 /*******************************************************************/
331 /*******************************************************************/
333 /* create a new type_union -- set unioned types by hand. */
335 new_type_union (ident *name, int n_types)
339 res = (type_union *) xmalloc (sizeof (type_union));
340 add_irp_type((type *) res); /* Remember the new type global. */
341 res->kind = k_type_union;
342 res->name = name; // do I need a name?
343 res->n_types = n_types;
345 res->unioned_type = (int *) xmalloc (sizeof (int) * n_types);
353 /* manipulate fields of type_union */
356 get_union_name (type_union *uni) {
358 return ID_TO_STR(uni->name);
363 get_union_ident (type_union *uni) {
369 void set_union_name (type_union *union, char *name);
370 void set_union_ident (type_union *union, ident* ident);
373 int get_union_n_types (type_union *union);
374 void set_union_n_types (type_union *union, int n);
375 type *get_union_unioned_type (type_union *union, int pos);
376 void set_union_unioned_type (type_union *union, int pos, type *type);
379 /*******************************************************************/
381 /*******************************************************************/
383 /* create a new type_array */
385 new_type_array (ident *name, int n_dimensions)
389 res = (type_array *) xmalloc (sizeof (type_array));
390 add_irp_type((type *) res); /* Remember the new type global. */
391 res->kind = k_type_array;
393 res->n_dimensions = n_dimensions;
394 res->lower_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
395 res->upper_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
402 /* manipulate fields of type_array */
405 get_array_name (type_array *array) {
407 return ID_TO_STR(array->name);
412 get_array_ident (type_array *array) {
418 void set_array_name (type_array *array, char *name);
419 void set_array_ident (type_array *array, ident* ident);
423 set_array_dimensions (type_array* array, int n) {
424 array->n_dimensions = n;
428 get_array_dimensions (type_array* array) {
429 return array->n_dimensions;
433 set_array_bounds (type_array* array, int dimension, int lower_bound,
435 array->lower_bound[dimension-1] = lower_bound;
436 array->upper_bound[dimension-1] = upper_bound;
440 set_array_lower_bound (type_array* array, int dimension, int lower_bound) {
441 array->lower_bound[dimension-1] = lower_bound;
445 set_array_upper_bound (type_array* array, int dimension, int upper_bound) {
446 array->upper_bound[dimension-1] = upper_bound;
450 get_array_lower_bound (type_array* array, int dimension) {
451 return array->lower_bound[dimension-1];
455 get_array_upper_bound (type_array* array, int dimension) {
456 return array->upper_bound[dimension-1];
459 inline void set_array_element_type (type_array *array, type *type) {
460 array->element_type = type;
464 get_array_element_type (type_array *array) {
465 return array->element_type;
469 /*******************************************************************/
470 /** TYPE_ENUMERATION **/
471 /*******************************************************************/
473 /* create a new type enumeration -- set the enumerators independently */
475 new_type_enumeration (ident *name /* , int n_enums */)
477 type_enumeration *res;
479 res = (type_enumeration *) xmalloc (sizeof (type_enumeration));
480 add_irp_type((type *) res); /* Remember the new type global. */
481 res->kind = k_type_enumeration;
484 res->n_enums = n_enums;
485 res->enum = (int *) xmalloc (sizeof (int) * n_enums);
493 /* manipulate fields of type_enumeration */
496 get_enumeration_name (type_enumeration *enumeration) {
498 return ID_TO_STR(enumeration->name);
503 get_enumeration_ident (type_enumeration *enumeration) {
505 return enumeration->name;
509 void set_enumeration_name (type_enumeration *enumeration, char *name);
510 void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
513 void set_enumeration_n_enums (type_enumeration *enumeration, int n);
514 int *get_enumeration_n_enums (type_enumeration *enumeration);
515 void set_enumeration_enum (type_enumeration *enumeration, int pos,
517 ir_node *get_enumeration_enum (type_enumeration *enumeration, int pos);
521 /*******************************************************************/
523 /*******************************************************************/
525 /* create a new type pointer */
527 new_type_pointer (ident *name, type *points_to)
531 res = (type_pointer *) xmalloc (sizeof (type_pointer));
532 add_irp_type((type *) res); /* Remember the new type global. */
533 res->kind = k_type_pointer;
535 res->points_to = points_to;
542 /* manipulate fields of type_pointer */
545 get_pointer_name (type_pointer *pointer) {
547 return ID_TO_STR(pointer->name);
552 get_pointer_ident (type_pointer *pointer) {
554 return pointer->name;
558 void set_pointer_name (type_pointer *pointer, char *name);
559 void set_pointer_ident (type_pointer *pointer, ident* ident);
563 set_pointer_points_to_type (type_pointer *pointer, type* type) {
564 pointer->points_to = type;
568 get_pointer_points_to_type (type_pointer *pointer) {
569 return pointer->points_to;
573 /*******************************************************************/
574 /** TYPE_PRIMITIVE **/
575 /*******************************************************************/
577 /* create a new type_primitive */
578 inline type_primitive *
579 new_type_primitive (ident *name, ir_mode *mode)
583 res = (type_primitive *) xmalloc (sizeof (type_primitive));
584 add_irp_type((type *) res); /* Remember the new type global. */
585 res->kind = k_type_primitive;
594 /* manipulate fields of type_primitive */
597 get_primitive_name (type_primitive *primitive) {
599 return ID_TO_STR(primitive->name);
604 get_primitive_ident (type_primitive *primitive) {
606 return primitive->name;
609 void set_primitive_name (type_primitive *primitive, char *name);
610 void set_primitive_ident (type_primitive *primitive, ident* ident);
614 get_primitive_mode (type_primitive *primitive) {
615 return primitive->mode;
619 set_primitive_mode (type_primitive *primitive, ir_mode *mode) {
620 primitive->mode = mode;
626 /*******************************************************************/
627 /** To manage all different types the same **/
628 /*******************************************************************/
632 is_type(void *thing) {
635 kind = get_kind(thing);
636 if ( (kind == k_type_class)
637 || (kind == k_type_strct)
638 || (kind == k_type_method)
639 || (kind == k_type_union)
640 || (kind == k_type_array)
641 || (kind == k_type_enumeration)
642 || (kind == k_type_pointer)
643 || (kind == k_type_primitive))
650 is_type_class(void *thing) {
651 if (get_kind(thing) == k_type_class) return 1;
656 is_type_strct(void *thing) {
657 if (get_kind(thing) == k_type_strct) return 1;
662 is_type_method(void *thing) {
663 if (get_kind(thing) == k_type_method) return 1;
668 is_type_union(void *thing) {
669 if (get_kind(thing) == k_type_union) return 1;
674 is_type_array(void *thing) {
675 if (get_kind(thing) == k_type_array) return 1;
680 is_type_pointer(void *thing) {
681 if (get_kind(thing) == k_type_pointer) return 1;
686 is_type_enumeration(void *thing) {
687 if (get_kind(thing) == k_type_enumeration) return 1;
692 is_type_primitive(void *thing) {
693 if (get_kind(thing) == k_type_primitive) return 1;