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