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
15 unsigned long type_visited = 0;
22 /*******************************************************************/
24 /*******************************************************************/
27 new_type_class (ident *name)//, int members)
31 res = (type_class *) xmalloc (sizeof (type_class));
32 add_irp_type((type *) res); /* Remember the new type global. */
33 res->kind = k_type_class;
36 res->members = NEW_ARR_F (entity *, 1);
37 res->subtypes = NEW_ARR_F (type_class *, 1);
38 res->supertypes = NEW_ARR_F (type_class *, 1);
39 // res->n_members = 0;
40 // res->max_members = members;
41 // res->member = (entity **) xmalloc (sizeof (entity*) * members);
48 /* manipulate fields of type_class */
50 get_class_name (type_class *class) {
52 return ID_TO_STR(class->name);
57 get_class_ident (type_class *class) {
63 void set_class_name (type_class *class, char *name);
64 void set_class_ident (type_class *class, ident* ident);
69 add_class_member (type_class *class, entity *member)
71 ARR_APP1 (entity *, class->members, member);
75 get_class_member (type_class *class, int pos)
78 return class->members[pos+1];
82 set_class_member (type_class *class, entity *member, int pos)
84 class->members[pos+1] = member;
89 add_class_subtype (type_class *class, type_class *subtype)
91 ARR_APP1 (type_class *, class->subtypes, subtype);
95 get_class_subtype (type_class *class, int pos)
98 return class->subtypes[pos+1];
102 set_class_subtype (type_class *class, type_class *subtype, int pos)
104 class->subtypes[pos+1] = subtype;
107 /* field: supertype */
109 add_class_supertype (type_class *class, type_class *supertype)
111 ARR_APP1 (type_class *, class->supertypes, supertype);
115 get_class_supertype (type_class *class, int pos)
118 return class->supertypes[pos+1];
122 set_class_supertype (type_class *class, type_class *supertype, int pos)
124 class->supertypes[pos+1] = supertype;
127 /*******************************************************************/
129 /*******************************************************************/
132 new_type_strct (ident *name)//, int members)
136 res = (type_strct *) xmalloc (sizeof (type_strct));
137 add_irp_type((type *) res); /* Remember the new type global. */
138 res->kind = k_type_strct;
141 // res->n_members = 0;
142 // res->max_members = members;
143 // res->member = (entity **) xmalloc (sizeof (entity*) * members);
150 /* manipulate fields of type_strct */
153 get_strct_name (type_strct *strct) {
155 return ID_TO_STR(strct->name);
160 get_strct_ident (type_strct *strct) {
166 void set_strct_name (type_strct *strct, char *name);
167 void set_strct_ident (type_strct *strct, ident* ident);
171 /*******************************************************************/
173 /*******************************************************************/
175 /* create a new type_method */
177 new_type_method (ident *name, int arity, int n_res)
181 res = (type_method *) xmalloc (sizeof (type_method));
182 add_irp_type((type *) res); /* Remember the new type global. */
183 res->kind = k_type_method;
184 res->name = name; // do I need the name, or is the name in entity sufficient?
186 res->param_type = (type **) xmalloc (sizeof (type *) * arity);
188 res->res_type = (type **) xmalloc (sizeof (type *) * n_res);
195 /* manipulate fields of type_method */
198 get_method_name (type_method *method) {
200 return ID_TO_STR(method->name);
205 get_method_ident (type_method *method) {
211 void set_method_name (type_method *method, char *name);
212 void set_method_ident (type_method *method, ident* ident);
216 get_method_arity (type_method *method) {
217 return method->arity;
222 set_method_arity (type_method *method, int arity) {
223 method->arity = arity;
224 / change array size, somehow copy. *
229 get_method_param_type(type_method *method, int pos) {
230 return method->param_type[pos];
234 set_method_param_type(type_method *method, int pos, type* type) {
235 method->param_type[pos] = type;
240 get_method_n_res (type_method *method) {
241 return method->n_res;
246 set_method_n_res (type_method *method, int n_res) {
247 method->n_res = n_res;
252 get_method_res_type(type_method *method, int pos) {
253 return method->res_type[pos];
257 set_method_res_type(type_method *method, int pos, type* type) {
258 method->res_type[pos] = type;
262 /*******************************************************************/
264 /*******************************************************************/
266 /* create a new type_union -- set unioned types by hand. */
268 new_type_union (ident *name, int n_types)
272 res = (type_union *) xmalloc (sizeof (type_union));
273 add_irp_type((type *) res); /* Remember the new type global. */
274 res->kind = k_type_union;
275 res->name = name; // do I need a name?
276 res->n_types = n_types;
278 res->unioned_type = (int *) xmalloc (sizeof (int) * n_types);
286 /* manipulate fields of type_union */
289 get_union_name (type_union *uni) {
291 return ID_TO_STR(uni->name);
296 get_union_ident (type_union *uni) {
302 void set_union_name (type_union *union, char *name);
303 void set_union_ident (type_union *union, ident* ident);
306 int get_union_n_types (type_union *union);
307 void set_union_n_types (type_union *union, int n);
308 type *get_union_unioned_type (type_union *union, int pos);
309 void set_union_unioned_type (type_union *union, int pos, type *type);
312 /*******************************************************************/
314 /*******************************************************************/
316 /* create a new type_array */
318 new_type_array (ident *name, int n_dimensions)
322 res = (type_array *) xmalloc (sizeof (type_array));
323 add_irp_type((type *) res); /* Remember the new type global. */
324 res->kind = k_type_array;
326 res->n_dimensions = n_dimensions;
327 res->lower_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
328 res->upper_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
335 /* manipulate fields of type_array */
338 get_array_name (type_array *array) {
340 return ID_TO_STR(array->name);
345 get_array_ident (type_array *array) {
351 void set_array_name (type_array *array, char *name);
352 void set_array_ident (type_array *array, ident* ident);
356 set_array_dimensions (type_array* array, int n) {
357 array->n_dimensions = n;
361 get_array_dimensions (type_array* array) {
362 return array->n_dimensions;
366 set_array_bounds (type_array* array, int dimension, int lower_bound,
368 array->lower_bound[dimension-1] = lower_bound;
369 array->upper_bound[dimension-1] = upper_bound;
373 set_array_lower_bound (type_array* array, int dimension, int lower_bound) {
374 array->lower_bound[dimension-1] = lower_bound;
378 set_array_upper_bound (type_array* array, int dimension, int upper_bound) {
379 array->upper_bound[dimension-1] = upper_bound;
383 get_array_lower_bound (type_array* array, int dimension) {
384 return array->lower_bound[dimension-1];
388 get_array_upper_bound (type_array* array, int dimension) {
389 return array->upper_bound[dimension-1];
392 inline void set_array_element_type (type_array *array, type *type) {
393 array->element_type = type;
397 get_array_element_type (type_array *array) {
398 return array->element_type;
402 /*******************************************************************/
403 /** TYPE_ENUMERATION **/
404 /*******************************************************************/
406 /* create a new type enumeration -- set the enumerators independently */
408 new_type_enumeration (ident *name /* , int n_enums */)
410 type_enumeration *res;
412 res = (type_enumeration *) xmalloc (sizeof (type_enumeration));
413 add_irp_type((type *) res); /* Remember the new type global. */
414 res->kind = k_type_enumeration;
417 res->n_enums = n_enums;
418 res->enum = (int *) xmalloc (sizeof (int) * n_enums);
426 /* manipulate fields of type_enumeration */
429 get_enumeration_name (type_enumeration *enumeration) {
431 return ID_TO_STR(enumeration->name);
436 get_enumeration_ident (type_enumeration *enumeration) {
438 return enumeration->name;
442 void set_enumeration_name (type_enumeration *enumeration, char *name);
443 void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
446 void set_enumeration_n_enums (type_enumeration *enumeration, int n);
447 int *get_enumeration_n_enums (type_enumeration *enumeration);
448 void set_enumeration_enum (type_enumeration *enumeration, int pos,
450 ir_node *get_enumeration_enum (type_enumeration *enumeration, int pos);
454 /*******************************************************************/
456 /*******************************************************************/
458 /* create a new type pointer */
460 new_type_pointer (ident *name, type *points_to)
464 res = (type_pointer *) xmalloc (sizeof (type_pointer));
465 add_irp_type((type *) res); /* Remember the new type global. */
466 res->kind = k_type_pointer;
468 res->points_to = points_to;
475 /* manipulate fields of type_pointer */
478 get_pointer_name (type_pointer *pointer) {
480 return ID_TO_STR(pointer->name);
485 get_pointer_ident (type_pointer *pointer) {
487 return pointer->name;
491 void set_pointer_name (type_pointer *pointer, char *name);
492 void set_pointer_ident (type_pointer *pointer, ident* ident);
496 set_pointer_points_to_type (type_pointer *pointer, type* type) {
497 pointer->points_to = type;
501 get_pointer_points_to_type (type_pointer *pointer) {
502 return pointer->points_to;
506 /*******************************************************************/
507 /** TYPE_PRIMITIVE **/
508 /*******************************************************************/
510 /* create a new type_primitive */
511 inline type_primitive *
512 new_type_primitive (ident *name, ir_mode *mode)
516 res = (type_primitive *) xmalloc (sizeof (type_primitive));
517 add_irp_type((type *) res); /* Remember the new type global. */
518 res->kind = k_type_primitive;
527 /* manipulate fields of type_primitive */
531 get_primitive_name (type_primitive *primitive) {
533 return ID_TO_STR(primitive->name);
538 get_primitive_ident (type_primitive *primitive) {
540 return primitive->name;
543 void set_primitive_name (type_primitive *primitive, char *name);
544 void set_primitive_ident (type_primitive *primitive, ident* ident);
548 get_primitive_mode (type_primitive *primitive) {
549 return primitive->mode;
553 set_primitive_mode (type_primitive *primitive, ir_mode *mode) {
554 primitive->mode = mode;
560 /*******************************************************************/
561 /** To manage all different types the same **/
562 /*******************************************************************/
566 is_type(void *thing) {
569 kind = get_kind(thing);
570 if ( (kind == k_type_class)
571 || (kind == k_type_strct)
572 || (kind == k_type_method)
573 || (kind == k_type_union)
574 || (kind == k_type_array)
575 || (kind == k_type_enumeration)
576 || (kind == k_type_pointer)
577 || (kind == k_type_primitive))