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