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
14 unsigned long type_visited = 0;
21 /*******************************************************************/
23 /*******************************************************************/
26 new_type_class (ident *name)//, int members)
30 res = (type_class *) xmalloc (sizeof (type_class));
31 add_irp_type((type *) res); /* Remember the new type global. */
32 res->kind = k_type_class;
35 // res->n_members = 0;
36 // res->max_members = members;
37 // res->member = (entity **) xmalloc (sizeof (entity*) * members);
44 /* manipulate fields of type_class */
47 get_class_name (type_class *class) {
49 return ID_TO_STR(class->name);
54 get_class_ident (type_class *class) {
60 void set_class_name (type_class *class, char *name);
61 void set_class_ident (type_class *class, ident* ident);
65 /*******************************************************************/
67 /*******************************************************************/
70 new_type_strct (ident *name)//, int members)
74 res = (type_strct *) xmalloc (sizeof (type_strct));
75 add_irp_type((type *) res); /* Remember the new type global. */
76 res->kind = k_type_strct;
79 // res->n_members = 0;
80 // res->max_members = members;
81 // res->member = (entity **) xmalloc (sizeof (entity*) * members);
88 /* manipulate fields of type_strct */
91 get_strct_name (type_strct *strct) {
93 return ID_TO_STR(strct->name);
98 get_strct_ident (type_strct *strct) {
104 void set_strct_name (type_strct *strct, char *name);
105 void set_strct_ident (type_strct *strct, ident* ident);
109 /*******************************************************************/
111 /*******************************************************************/
113 /* create a new type_method */
115 new_type_method (ident *name, int arity, int n_res)
119 res = (type_method *) xmalloc (sizeof (type_method));
120 add_irp_type((type *) res); /* Remember the new type global. */
121 res->kind = k_type_method;
122 res->name = name; // do I need the name, or is the name in entity sufficient?
124 res->param_type = (type **) xmalloc (sizeof (type *) * arity);
126 res->res_type = (type **) xmalloc (sizeof (type *) * n_res);
133 /* manipulate fields of type_method */
136 get_method_name (type_method *method) {
138 return ID_TO_STR(method->name);
143 get_method_ident (type_method *method) {
149 void set_method_name (type_method *method, char *name);
150 void set_method_ident (type_method *method, ident* ident);
154 get_method_arity (type_method *method) {
155 return method->arity;
160 set_method_arity (type_method *method, int arity) {
161 method->arity = arity;
162 / change array size, somehow copy. *
167 get_method_param_type(type_method *method, int pos) {
168 return method->param_type[pos];
172 set_method_param_type(type_method *method, int pos, type* type) {
173 method->param_type[pos] = type;
178 get_method_n_res (type_method *method) {
179 return method->n_res;
184 set_method_n_res (type_method *method, int n_res) {
185 method->n_res = n_res;
190 get_method_res_type(type_method *method, int pos) {
191 return method->res_type[pos];
195 set_method_res_type(type_method *method, int pos, type* type) {
196 method->res_type[pos] = type;
200 /*******************************************************************/
202 /*******************************************************************/
204 /* create a new type_union -- set unioned types by hand. */
206 new_type_union (ident *name, int n_types)
210 res = (type_union *) xmalloc (sizeof (type_union));
211 add_irp_type((type *) res); /* Remember the new type global. */
212 res->kind = k_type_union;
213 res->name = name; // do I need a name?
214 res->n_types = n_types;
216 res->unioned_type = (int *) xmalloc (sizeof (int) * n_types);
224 /* manipulate fields of type_union */
227 get_union_name (type_union *uni) {
229 return ID_TO_STR(uni->name);
234 get_union_ident (type_union *uni) {
240 void set_union_name (type_union *union, char *name);
241 void set_union_ident (type_union *union, ident* ident);
244 int get_union_n_types (type_union *union);
245 void set_union_n_types (type_union *union, int n);
246 type *get_union_unioned_type (type_union *union, int pos);
247 void set_union_unioned_type (type_union *union, int pos, type *type);
250 /*******************************************************************/
252 /*******************************************************************/
254 /* create a new type_array */
256 new_type_array (ident *name, int n_dimensions)
260 res = (type_array *) xmalloc (sizeof (type_array));
261 add_irp_type((type *) res); /* Remember the new type global. */
262 res->kind = k_type_array;
264 res->n_dimensions = n_dimensions;
265 res->lower_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
266 res->upper_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
273 /* manipulate fields of type_array */
276 get_array_name (type_array *array) {
278 return ID_TO_STR(array->name);
283 get_array_ident (type_array *array) {
289 void set_array_name (type_array *array, char *name);
290 void set_array_ident (type_array *array, ident* ident);
294 set_array_dimensions (type_array* array, int n) {
295 array->n_dimensions = n;
299 get_array_dimensions (type_array* array) {
300 return array->n_dimensions;
304 set_array_bounds (type_array* array, int dimension, int lower_bound,
306 array->lower_bound[dimension-1] = lower_bound;
307 array->upper_bound[dimension-1] = upper_bound;
311 set_array_lower_bound (type_array* array, int dimension, int lower_bound) {
312 array->lower_bound[dimension-1] = lower_bound;
316 set_array_upper_bound (type_array* array, int dimension, int upper_bound) {
317 array->upper_bound[dimension-1] = upper_bound;
321 get_array_lower_bound (type_array* array, int dimension) {
322 return array->lower_bound[dimension-1];
326 get_array_upper_bound (type_array* array, int dimension) {
327 return array->upper_bound[dimension-1];
330 inline void set_array_element_type (type_array *array, type *type) {
331 array->element_type = type;
335 get_array_element_type (type_array *array) {
336 return array->element_type;
340 /*******************************************************************/
341 /** TYPE_ENUMERATION **/
342 /*******************************************************************/
344 /* create a new type enumeration -- set the enumerators independently */
346 new_type_enumeration (ident *name /* , int n_enums */)
348 type_enumeration *res;
350 res = (type_enumeration *) xmalloc (sizeof (type_enumeration));
351 add_irp_type((type *) res); /* Remember the new type global. */
352 res->kind = k_type_enumeration;
355 res->n_enums = n_enums;
356 res->enum = (int *) xmalloc (sizeof (int) * n_enums);
364 /* manipulate fields of type_enumeration */
367 get_enumeration_name (type_enumeration *enumeration) {
369 return ID_TO_STR(enumeration->name);
374 get_enumeration_ident (type_enumeration *enumeration) {
376 return enumeration->name;
380 void set_enumeration_name (type_enumeration *enumeration, char *name);
381 void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
384 void set_enumeration_n_enums (type_enumeration *enumeration, int n);
385 int *get_enumeration_n_enums (type_enumeration *enumeration);
386 void set_enumeration_enum (type_enumeration *enumeration, int pos,
388 ir_node *get_enumeration_enum (type_enumeration *enumeration, int pos);
392 /*******************************************************************/
394 /*******************************************************************/
396 /* create a new type pointer */
398 new_type_pointer (ident *name, type *points_to)
402 res = (type_pointer *) xmalloc (sizeof (type_pointer));
403 add_irp_type((type *) res); /* Remember the new type global. */
404 res->kind = k_type_pointer;
406 res->points_to = points_to;
413 /* manipulate fields of type_pointer */
416 get_pointer_name (type_pointer *pointer) {
418 return ID_TO_STR(pointer->name);
423 get_pointer_ident (type_pointer *pointer) {
425 return pointer->name;
429 void set_pointer_name (type_pointer *pointer, char *name);
430 void set_pointer_ident (type_pointer *pointer, ident* ident);
434 set_pointer_points_to_type (type_pointer *pointer, type* type) {
435 pointer->points_to = type;
439 get_pointer_points_to_type (type_pointer *pointer) {
440 return pointer->points_to;
444 /*******************************************************************/
445 /** TYPE_PRIMITIVE **/
446 /*******************************************************************/
448 /* create a new type_primitive */
449 inline type_primitive *
450 new_type_primitive (ident *name, ir_mode *mode)
454 res = (type_primitive *) xmalloc (sizeof (type_primitive));
455 add_irp_type((type *) res); /* Remember the new type global. */
456 res->kind = k_type_primitive;
465 /* manipulate fields of type_primitive */
469 get_primitive_name (type_primitive *primitive) {
471 return ID_TO_STR(primitive->name);
476 get_primitive_ident (type_primitive *primitive) {
478 return primitive->name;
481 void set_primitive_name (type_primitive *primitive, char *name);
482 void set_primitive_ident (type_primitive *primitive, ident* ident);
486 get_primitive_mode (type_primitive *primitive) {
487 return primitive->mode;
491 set_primitive_mode (type_primitive *primitive, ir_mode *mode) {
492 primitive->mode = mode;
498 /*******************************************************************/
499 /** To manage all different types the same **/
500 /*******************************************************************/
504 is_type(void *thing) {
507 kind = get_kind(thing);
508 if ( (kind == k_type_class)
509 || (kind == k_type_strct)
510 || (kind == k_type_method)
511 || (kind == k_type_union)
512 || (kind == k_type_array)
513 || (kind == k_type_enumeration)
514 || (kind == k_type_pointer)
515 || (kind == k_type_primitive))