857425da757f6fef312a433466b1bb94f75f02c6
[libfirm] / ir / tr / type.c
1 /****h* libfirm/type.c
2  *
3  * NAME
4  *   file type.c - implementation of the datastructure to hold
5  *   type information.
6  * COPYRIGHT
7  *  (C) 2001 by Universitaet Karlsruhe
8  * AUTHORS
9  *  Martin Trapp, Christian Schaefer, Goetz Lindenmaier
10  *
11  * NOTES
12  *  This module supplies a datastructure to represent all types
13  *  known in the compiled program.  This includes types specified
14  *  in the program as well as types defined by the language.  In the
15  *  view of the intermediate representation there is no difference
16  *  between these types.
17  *
18  *  There exist several kinds of types, arranged by the structure of
19  *  the type.  A type is described by a set of attributes.  Some of
20  *  these attributes are common to all types, others depend on the
21  *  kind of the type.
22  *
23  *  Types are different from the modes defined in irmode:  Types are
24  *  on the level of the programming language, modes at the level of
25  *  the target processor.
26  *
27  * SEE ALSO
28  *   type_t.h type tpop
29  *****
30  */
31
32 /* $Id$ */
33
34 # include <stdlib.h>
35 # include <stddef.h>
36 # include "type_t.h"
37 # include "tpop_t.h"
38 # include "typegmod_t.h"
39 # include "array.h"
40
41 /*******************************************************************/
42 /** TYPE                                                          **/
43 /*******************************************************************/
44
45 unsigned long type_visited;
46
47 inline type *
48 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
49   type *res;
50   int node_size ;
51
52   assert(type_op != type_id);
53
54   node_size = offsetof (type, attr) +  type_op->attr_size;
55   res = (type *) xmalloc (node_size);
56   add_irp_type(res);   /* Remember the new type global. */
57
58   res->kind = k_type;
59   res->type_op = type_op;
60   res->mode = mode;
61   res->name = name;
62   res->state = layout_undefined;
63   res->size = -1;
64   res->visit = 0;
65   res -> link = NULL;
66
67   return res;
68 }
69
70 void free_type_attrs(type *tp) {
71   switch(get_type_tpop_code(tp)) {
72   case tpo_class:       { free_class_attrs(tp);       } break;
73   case tpo_struct:      { free_struct_attrs(tp);      } break;
74   case tpo_method:      { free_method_attrs(tp);      } break;
75   case tpo_union:       { free_union_attrs(tp);       } break;
76   case tpo_array:       { free_array_attrs(tp);       } break;
77   case tpo_enumeration: { free_enumeration_attrs(tp); } break;
78   case tpo_pointer:     { free_pointer_attrs(tp);     } break;
79   case tpo_primitive:   { free_primitive_attrs(tp);   } break;
80   default: break;
81   }
82 }
83
84 /* set/get the link field */
85 void *get_type_link(type *tp)
86 {
87   assert(tp);
88   return(tp -> link);
89 }
90
91 void set_type_link(type *tp, void *l)
92 {
93   assert(tp);
94   tp -> link = l;
95 }
96
97 tp_op*      get_type_tpop(type *tp) {
98   assert(tp);
99   return tp->type_op;
100 }
101
102 ident*      get_type_tpop_nameid(type *tp) {
103   assert(tp);
104   return tp->type_op->name;
105 }
106
107 const char* get_type_tpop_name(type *tp) {
108   assert(tp);
109   return id_to_str(tp->type_op->name);
110 }
111
112 tp_opcode    get_type_tpop_code(type *tp) {
113   assert(tp);
114   return tp->type_op->code;
115 }
116
117 ir_mode*    get_type_mode(type *tp) {
118   assert(tp);
119   return tp->mode;
120 }
121
122 void        set_type_mode(type *tp, ir_mode* m) {
123   assert(tp);
124   tp->mode = m;
125   /* For pointer and primitive size depends on the mode. */
126   if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive))
127     tp->size == get_mode_size(m);
128 }
129
130 ident*      get_type_ident(type *tp) {
131   assert(tp);
132   return tp->name;
133 }
134
135 void        set_type_ident(type *tp, ident* id) {
136   assert(tp);
137   tp->name = id;
138 }
139
140 const char* get_type_name(type *tp) {
141   assert(tp);
142   return id_to_str(tp->name);
143 }
144
145 int         get_type_size(type *tp) {
146   assert(tp);
147   return tp->size;
148 }
149
150 void
151 set_type_size(type *tp, int size) {
152   assert(tp);
153   /* For pointer and primitive size depends on the mode. */
154   if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive))
155     tp->size = size;
156 }
157
158 type_state
159 get_type_state(type *tp) {
160   assert(tp);
161   return tp->state;
162 }
163
164 void
165 set_type_state(type *tp, type_state state) {
166   assert(tp);
167   /* For pointer and primitive always fixed. */
168   if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive)) {
169     /* @@@ assert that the layout really is fixed!!! */
170     tp->state = state;
171   }
172 }
173
174 unsigned long get_type_visited(type *tp) {
175   assert(tp);
176   return tp->visit;
177 }
178
179 void        set_type_visited(type *tp, unsigned long num) {
180   assert(tp);
181   tp->visit = num;
182 }
183 /* Sets visited field in type to type_visited. */
184 void        mark_type_visited(type *tp) {
185   assert(tp);
186   assert(tp->visit < type_visited);
187   tp->visit = type_visited;
188 }
189
190 int is_type            (void *thing) {
191   assert(thing);
192   if (get_kind(thing) == k_type)
193     return 1;
194   else
195     return 0;
196 }
197
198 /*******************************************************************/
199 /** TYPE_CLASS                                                    **/
200 /*******************************************************************/
201
202 /* create a new class type */
203 type   *new_type_class (ident *name) {
204   type *res;
205
206   res = new_type(type_class, NULL, name);
207
208   res->attr.ca.members    = NEW_ARR_F (entity *, 1);
209   res->attr.ca.subtypes   = NEW_ARR_F (type *, 1);
210   res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
211
212   return res;
213 }
214 inline void free_class_attrs(type *clss) {
215   assert(clss && (clss->type_op == type_class));
216   DEL_ARR_F(clss->attr.ca.members);
217   DEL_ARR_F(clss->attr.ca.subtypes);
218   DEL_ARR_F(clss->attr.ca.supertypes);
219 }
220 /* manipulate private fields of class type  */
221 void    add_class_member   (type *clss, entity *member) {
222   assert(clss && (clss->type_op == type_class));
223   ARR_APP1 (entity *, clss->attr.ca.members, member);
224 }
225 int     get_class_n_member (type *clss) {
226   assert(clss && (clss->type_op == type_class));
227   return (ARR_LEN (clss->attr.ca.members))-1;
228 }
229 entity *get_class_member   (type *clss, int pos) {
230   assert(clss && (clss->type_op == type_class));
231   return clss->attr.ca.members[pos+1];
232 }
233 void    set_class_member   (type *clss, entity *member, int pos) {
234   assert(clss && (clss->type_op == type_class));
235   clss->attr.ca.members[pos+1] = member;
236 }
237 void    remove_class_member(type *clss, entity *member) {
238   int i;
239   assert(clss && (clss->type_op == type_class));
240   for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++)
241     if (clss->attr.ca.members[i+1] == member) {
242       for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
243         clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
244       ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
245       break;
246     }
247 }
248
249 void    add_class_subtype   (type *clss, type *subtype) {
250   int i;
251   assert(clss && (clss->type_op == type_class));
252   ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
253   for (i = 0; i < get_class_n_supertype(subtype); i++)
254     if (get_class_supertype(subtype, i) == clss)
255       /* Class already registered */
256       return;
257   ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
258 }
259 int     get_class_n_subtype (type *clss) {
260   assert(clss && (clss->type_op == type_class));
261   return (ARR_LEN (clss->attr.ca.subtypes))-1;
262 }
263 type   *get_class_subtype   (type *clss, int pos) {
264   assert(clss && (clss->type_op == type_class));
265   return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
266 }
267 void    set_class_subtype   (type *clss, type *subtype, int pos) {
268   assert(clss && (clss->type_op == type_class));
269   clss->attr.ca.subtypes[pos+1] = subtype;
270 }
271 void    remove_class_subtype(type *clss, type *subtype) {
272   int i;
273   assert(clss && (clss->type_op == type_class));
274   for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
275     if (clss->attr.ca.subtypes[i+1] == subtype) {
276       for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
277         clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
278       ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
279       break;
280     }
281 }
282
283 void    add_class_supertype   (type *clss, type *supertype) {
284   int i;
285   assert(clss && (clss->type_op == type_class));
286   assert(supertype && (supertype -> type_op == type_class));
287   ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
288   for (i = 0; i < get_class_n_subtype(supertype); i++)
289     if (get_class_subtype(supertype, i) == clss)
290       /* Class already registered */
291       return;
292   ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
293 }
294 int     get_class_n_supertype (type *clss) {
295   assert(clss && (clss->type_op == type_class));
296   return (ARR_LEN (clss->attr.ca.supertypes))-1;
297 }
298 type   *get_class_supertype   (type *clss, int pos) {
299   assert(clss && (clss->type_op == type_class));
300   return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
301 }
302 void    set_class_supertype   (type *clss, type *supertype, int pos) {
303   assert(clss && (clss->type_op == type_class));
304   clss->attr.ca.supertypes[pos+1] = supertype;
305 }
306 void    remove_class_supertype(type *clss, type *supertype) {
307   int i;
308   assert(clss && (clss->type_op == type_class));
309   for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
310     if (clss->attr.ca.supertypes[i+1] == supertype) {
311       for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
312         clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
313       ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
314       break;
315     }
316 }
317 /* typecheck */
318 bool    is_class_type(type *clss) {
319   assert(clss);
320   if (clss->type_op == type_class) return 1; else return 0;
321 }
322
323 /*******************************************************************/
324 /** TYPE_STRUCT                                                   **/
325 /*******************************************************************/
326
327 /* create a new type struct */
328 type   *new_type_struct (ident *name) {
329   type *res;
330   res = new_type(type_struct, NULL, name);
331   res->attr.sa.members = NEW_ARR_F (entity *, 1);
332   return res;
333 }
334 inline void free_struct_attrs (type *strct) {
335   assert(strct && (strct->type_op == type_struct));
336   DEL_ARR_F(strct->attr.sa.members);
337 }
338 /* manipulate private fields of struct */
339 void    add_struct_member   (type *strct, entity *member) {
340   assert(strct && (strct->type_op == type_struct));
341   ARR_APP1 (entity *, strct->attr.sa.members, member);
342 }
343 int     get_struct_n_member (type *strct) {
344   assert(strct && (strct->type_op == type_struct));
345   return (ARR_LEN (strct->attr.sa.members))-1;
346 }
347 entity *get_struct_member   (type *strct, int pos) {
348   assert(strct && (strct->type_op == type_struct));
349   return strct->attr.sa.members[pos+1];
350 }
351 void    set_struct_member   (type *strct, int pos, entity *member) {
352   assert(strct && (strct->type_op == type_struct));
353   strct->attr.sa.members[pos+1] = member;
354 }
355 void    remove_struct_member(type *strct, entity *member) {
356   int i;
357   assert(strct && (strct->type_op == type_struct));
358   for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
359     if (strct->attr.sa.members[i+1] == member) {
360       for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
361         strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
362       ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
363       break;
364     }
365 }
366 /* typecheck */
367 bool    is_struct_type(type *strct) {
368   assert(strct);
369   if (strct->type_op == type_struct) return 1; else return 0;
370 }
371
372 /*******************************************************************/
373 /** TYPE_METHOD                                                   **/
374 /*******************************************************************/
375
376 /* Create a new method type.
377    N_param is the number of parameters, n_res the number of results.  */
378 type *new_type_method (ident *name, int n_param, int n_res) {
379   type *res;
380   res = new_type(type_method, NULL, name);
381   res->attr.ma.n_params   = n_param;
382   res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
383   res->attr.ma.n_res      = n_res;
384   res->attr.ma.res_type   = (type **) xmalloc (sizeof (type *) * n_res);
385   return res;
386 }
387 inline void free_method_attrs(type *method) {
388   assert(method && (method->type_op == type_method));
389   free(method->attr.ma.param_type);
390   free(method->attr.ma.res_type);
391 }
392 /* manipulate private fields of method. */
393 int   get_method_n_params  (type *method) {
394   assert(method && (method->type_op == type_method));
395   return method->attr.ma.n_params;
396 }
397 type *get_method_param_type(type *method, int pos) {
398   assert(method && (method->type_op == type_method));
399   return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
400 }
401 void  set_method_param_type(type *method, int pos, type* type) {
402   assert(method && (method->type_op == type_method));
403   method->attr.ma.param_type[pos] = type;
404 }
405
406 int   get_method_n_res   (type *method) {
407   assert(method && (method->type_op == type_method));
408   return method->attr.ma.n_res;
409 }
410 type *get_method_res_type(type *method, int pos) {
411   assert(method && (method->type_op == type_method));
412   return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
413 }
414 void  set_method_res_type(type *method, int pos, type* type) {
415   assert(method && (method->type_op == type_method));
416   method->attr.ma.res_type[pos] = type;
417 }
418
419 /* typecheck */
420 bool  is_method_type     (type *method) {
421   assert(method);
422   if (method->type_op == type_method) return 1; else return 0;
423 }
424 /*****/
425
426 /*******************************************************************/
427 /** TYPE_UNION                                                    **/
428 /*******************************************************************/
429
430 /* create a new type uni */
431 type  *new_type_uni (ident *name) {
432   type *res;
433   res = new_type(type_union, NULL, name);
434   /*res->attr.ua.unioned_type = (type **)  xmalloc (sizeof (type *)  * n_types);
435     res->attr.ua.delim_names  = (ident **) xmalloc (sizeof (ident *) * n_types); */
436   res->attr.ua.members = NEW_ARR_F (entity *, 1);
437   return res;
438 }
439 inline void free_union_attrs (type *uni) {
440   assert(uni && (uni->type_op == type_union));
441   DEL_ARR_F(uni->attr.ua.members);
442 }
443 /* manipulate private fields of struct */
444 #if 0
445 int    get_union_n_types      (type *uni) {
446   assert(uni && (uni->type_op == type_union));
447   return uni->attr.ua.n_types;
448 }
449 type  *get_union_unioned_type (type *uni, int pos) {
450   assert(uni && (uni->type_op == type_union));
451   return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
452 }
453 void   set_union_unioned_type (type *uni, int pos, type *type) {
454   assert(uni && (uni->type_op == type_union));
455   uni->attr.ua.unioned_type[pos] = type;
456 }
457 ident *get_union_delim_nameid (type *uni, int pos) {
458   assert(uni && (uni->type_op == type_union));
459   return uni->attr.ua.delim_names[pos];
460 }
461 const char *get_union_delim_name (type *uni, int pos) {
462   assert(uni && (uni->type_op == type_union));
463   return id_to_str(uni->attr.ua.delim_names[pos]);
464 }
465 void   set_union_delim_nameid (type *uni, int pos, ident *id) {
466   assert(uni && (uni->type_op == type_union));
467   uni->attr.ua.delim_names[pos] = id;
468 }
469 #endif
470 int    get_union_n_members      (type *uni) {
471   assert(uni && (uni->type_op == type_union));
472   return (ARR_LEN (uni->attr.ua.members))-1;
473 }
474 void    add_union_member   (type *uni, entity *member) {
475   assert(uni && (uni->type_op == type_union));
476   ARR_APP1 (entity *, uni->attr.ua.members, member);
477 }
478 entity  *get_union_member (type *uni, int pos) {
479   assert(uni && (uni->type_op == type_union));
480   return uni->attr.ua.members[pos+1];
481 }
482 void   set_union_member (type *uni, int pos, entity *member) {
483   assert(uni && (uni->type_op == type_union));
484   uni->attr.ua.members[pos+1] = member;
485 }
486 void   remove_union_member(type *uni, entity *member) {
487   int i;
488   assert(uni && (uni->type_op == type_union));
489   for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
490     if (uni->attr.ua.members[i+1] == member) {
491       for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
492         uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
493       ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
494       break;
495     }
496 }
497
498 /* typecheck */
499 bool   is_union_type         (type *uni) {
500   assert(uni);
501   if (uni->type_op == type_union) return 1; else return 0;
502 }
503
504 /*******************************************************************/
505 /** TYPE_ARRAY                                                    **/
506 /*******************************************************************/
507
508
509 /* create a new type array -- set dimension sizes independently */
510 type *new_type_array         (ident *name, int n_dimensions,
511                               type *element_type) {
512   type *res;
513   res = new_type(type_array, NULL, name);
514   res->attr.aa.n_dimensions = n_dimensions;
515   res->attr.aa.lower_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
516   res->attr.aa.upper_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
517   res->attr.aa.element_type = element_type;
518   new_entity(res, mangle(name, id_from_str("elem_ent", 8)), element_type);
519   return res;
520 }
521 inline void free_array_attrs (type *array) {
522   assert(array && (array->type_op == type_array));
523   free(array->attr.aa.lower_bound);
524   free(array->attr.aa.upper_bound);
525 }
526
527 /* manipulate private fields of array type */
528 int   get_array_n_dimensions (type *array) {
529   assert(array && (array->type_op == type_array));
530   return array->attr.aa.n_dimensions;
531 }
532 void  set_array_bounds       (type *array, int dimension, ir_node * lower_bound,
533                                                           ir_node * upper_bound) {
534   assert(array && (array->type_op == type_array));
535   array->attr.aa.lower_bound[dimension] = lower_bound;
536   array->attr.aa.upper_bound[dimension] = upper_bound;
537 }
538 void  set_array_lower_bound  (type *array, int dimension, ir_node * lower_bound) {
539   assert(array && (array->type_op == type_array));
540   array->attr.aa.lower_bound[dimension] = lower_bound;
541 }
542 void  set_array_upper_bound  (type *array, int dimension, ir_node * upper_bound) {
543   assert(array && (array->type_op == type_array));
544   array->attr.aa.upper_bound[dimension] = upper_bound;
545 }
546 ir_node * get_array_lower_bound  (type *array, int dimension) {
547   assert(array && (array->type_op == type_array));
548   return array->attr.aa.lower_bound[dimension];
549 }
550 ir_node * get_array_upper_bound  (type *array, int dimension) {
551   assert(array && (array->type_op == type_array));
552   return array->attr.aa.upper_bound[dimension];
553 }
554 void  set_array_element_type (type *array, type *type) {
555   assert(array && (array->type_op == type_array));
556   array->attr.aa.element_type = type;
557 }
558 type *get_array_element_type (type *array) {
559   assert(array && (array->type_op == type_array));
560   return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
561 }
562 void  set_array_element_entity (type *array, entity *ent) {
563   assert(array && (array->type_op == type_array));
564   array->attr.aa.element_ent = ent;
565 }
566 entity *get_array_element_entity (type *array) {
567   assert(array && (array->type_op == type_array));
568   return array->attr.aa.element_ent;
569 }
570
571 /* typecheck */
572 bool   is_array_type         (type *array) {
573   assert(array);
574   if (array->type_op == type_array) return 1; else return 0;
575 }
576
577 /*******************************************************************/
578 /** TYPE_ENUMERATION                                              **/
579 /*******************************************************************/
580
581 /* create a new type enumeration -- set the enumerators independently */
582 type   *new_type_enumeration    (ident *name, int n_enums) {
583   type *res;
584   res = new_type(type_enumeration, NULL, name);
585   res->attr.ea.n_enums     = n_enums;
586   res->attr.ea.enumer      = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
587   res->attr.ea.enum_nameid = (ident  **) xmalloc (sizeof (ident  *) * n_enums);
588   return res;
589 }
590 inline void free_enumeration_attrs(type *enumeration) {
591   assert(enumeration && (enumeration->type_op == type_enumeration));
592   free(enumeration->attr.ea.enumer);
593   free(enumeration->attr.ea.enum_nameid);
594 }
595
596 /* manipulate fields of enumeration type. */
597 int     get_enumeration_n_enums (type *enumeration) {
598   assert(enumeration && (enumeration->type_op == type_enumeration));
599   return enumeration->attr.ea.n_enums;
600 }
601 void    set_enumeration_enum    (type *enumeration, int pos, tarval *con) {
602   assert(enumeration && (enumeration->type_op == type_enumeration));
603   enumeration->attr.ea.enumer[pos] = con;
604 }
605 tarval *get_enumeration_enum    (type *enumeration, int pos) {
606   assert(enumeration && (enumeration->type_op == type_enumeration));
607   return enumeration->attr.ea.enumer[pos];
608 }
609 void    set_enumeration_nameid  (type *enumeration, int pos, ident *id) {
610   assert(enumeration && (enumeration->type_op == type_enumeration));
611   enumeration->attr.ea.enum_nameid[pos] = id;
612 }
613 ident  *get_enumeration_nameid  (type *enumeration, int pos) {
614   assert(enumeration && (enumeration->type_op == type_enumeration));
615   return enumeration->attr.ea.enum_nameid[pos];
616 }
617 const char *get_enumeration_name(type *enumeration, int pos) {
618   assert(enumeration && (enumeration->type_op == type_enumeration));
619   return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
620 }
621
622 /* typecheck */
623 bool    is_enumeration_type     (type *enumeration) {
624   assert(enumeration);
625   if (enumeration->type_op == type_enumeration) return 1; else return 0;
626 }
627
628 /*******************************************************************/
629 /** TYPE_POINTER                                                  **/
630 /*******************************************************************/
631
632 /* Create a new type pointer */
633 type *new_type_pointer           (ident *name, type *points_to) {
634   type *res;
635   res = new_type(type_pointer, mode_p, name);
636   res->attr.pa.points_to = points_to;
637   res->size = get_mode_size(res->mode);
638   res->state = layout_fixed;
639   return res;
640 }
641 inline void free_pointer_attrs (type *pointer) {
642   assert(pointer && (pointer->type_op == type_pointer));
643 }
644 /* manipulate fields of type_pointer */
645 void  set_pointer_points_to_type (type *pointer, type *type) {
646   assert(pointer && (pointer->type_op == type_pointer));
647   pointer->attr.pa.points_to = type;
648 }
649 type *get_pointer_points_to_type (type *pointer) {
650   assert(pointer && (pointer->type_op == type_pointer));
651   return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
652 }
653
654 /* typecheck */
655 bool  is_pointer_type            (type *pointer) {
656   assert(pointer);
657   if (pointer->type_op == type_pointer) return 1; else return 0;
658 }
659
660
661 /*******************************************************************/
662 /** TYPE_PRIMITIVE                                                **/
663 /*******************************************************************/
664
665 /* create a new type primitive */
666 type *new_type_primitive (ident *name, ir_mode *mode) {
667   type *res;
668   res = new_type(type_primitive, mode, name);
669   res->size = get_mode_size(mode);
670   res->state = layout_fixed;
671   return res;
672 }
673 inline void free_primitive_attrs (type *primitive) {
674   assert(primitive && (primitive->type_op == type_primitive));
675 }
676
677 /* typecheck */
678 bool  is_primitive_type  (type *primitive) {
679   assert(primitive);
680   if (primitive->type_op == type_primitive) return 1; else return 0;
681 }