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