3 * File name: ir/tr/type_t.h
4 * Purpose: Representation of types -- private header.
5 * Author: Goetz Lindenmaier
6 * Modified by: Michael Beck
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
13 #ifndef _FIRM_TR_TYPE_T_H_
14 #define _FIRM_TR_TYPE_T_H_
16 #include "firm_config.h"
25 * This file contains the datatypes hidden in type.h.
27 * @author Goetz Lindenmaier
28 * @see type.h tpop_t.h tpop.h
33 cf_none = 0, /**< No flags. */
34 cf_final_class = 1, /**< Set if a class is an final class */
35 cf_interface_class = 2, /**< Set if a class is an "interface" */
36 cf_absctract_class = 4, /**< Set if a class is "abstract" */
39 /** Class type attributes. */
41 ir_entity **members; /**< Array containing the fields and methods of this class. */
42 ir_type **subtypes; /**< Array containing the direct subtypes. */
43 ir_type **supertypes; /**< Array containing the direct supertypes */
44 ir_peculiarity peculiarity; /**< The peculiarity of this class. */
45 ir_entity *type_info; /**< An ir_entity representing this class, used for type info. */
46 int dfn; /**< A number that can be used for 'instanceof' operator. */
47 unsigned vtable_size; /**< The size of the vtable for this class. */
48 unsigned clss_flags; /**< Additional class flags. */
51 /** Struct type attributes. */
53 ir_entity **members; /**< Fields of this struct. No method entities allowed. */
56 /** A (type, ir_entity) pair. */
58 ir_type *tp; /**< A type. */
59 ir_entity *ent; /**< An ir_entity. */
60 ident *param_name; /**< For debugging purposes: the name of the parameter */
63 /** Method type attributes. */
65 int n_params; /**< Number of parameters. */
66 tp_ent_pair *params; /**< Array of parameter type/value entities pairs. */
67 ir_type *value_params; /**< A type whose entities represent copied value arguments. */
68 int n_res; /**< Number of results. */
69 tp_ent_pair *res_type; /**< Array of result type/value ir_entity pairs. */
70 ir_type *value_ress; /**< A type whose entities represent copied value results. */
71 variadicity variadicity; /**< The variadicity of the method. */
72 int first_variadic_param; /**< The index of the first variadic parameter or -1 if non-variadic .*/
73 unsigned additional_properties; /**< Set of additional method properties. */
74 unsigned irg_calling_conv; /**< A set of calling convention flags. */
77 /** Union type attributes. */
79 ir_entity **members; /**< Fields of this union. No method entities allowed. */
82 /** Array type attributes. */
84 int n_dimensions; /**< Number of array dimensions. */
85 ir_node **lower_bound; /**< Lower bounds of dimensions. Usually all 0. */
86 ir_node **upper_bound; /**< Upper bounds or dimensions. */
87 int *order; /**< Ordering of dimensions. */
88 ir_type *element_type; /**< The type of the array elements. */
89 ir_entity *element_ent; /**< entity for the array elements, to be used for
90 element selection with a Sel node. */
93 /** An enumerator constant. */
94 struct ir_enum_const {
95 tarval *value; /**< The constants that represents this enumerator identifier. */
96 ident *nameid; /**< The name of the enumerator identifier. */
97 ir_type *owner; /**< owner type of this enumerator constant. */
100 /** Enum type attributes. */
102 ir_enum_const *enumer; /**< Contains all enumerator constants that represent a member
103 of the enum -- enumerators. */
106 /** Pointer type attributes. */
108 ir_type *points_to; /**< The type of the ir_entity the pointer points to. */
112 typedef struct { * No private attr yet! *
117 typedef struct { * No private attr, must be smaller than others! *
121 /** General type attributes. */
123 cls_attr ca; /**< Attributes of a class type */
124 stc_attr sa; /**< Attributes of a struct type */
125 mtd_attr ma; /**< Attributes of a method type */
126 uni_attr ua; /**< Attributes of an union type */
127 arr_attr aa; /**< Attributes of an array type */
128 enm_attr ea; /**< Attributes of an enumeration type */
129 ptr_attr pa; /**< Attributes of a pointer type */
132 /** Additional type flags. */
134 tf_none = 0, /**< No flags. */
135 tf_frame_type = 1, /**< Set if this is a frame type. */
136 tf_value_param_type = 2, /**< Set if this is a value param type. */
137 tf_lowered_type = 4, /**< Set if this is a lowered type. */
138 tf_layout_fixed = 8, /**< Set if the layout of a type is fixed */
139 tf_global_type = 16, /**< Set only for the global type */
140 tf_tls_type = 32, /**< Set only for the tls type */
143 /** The structure of a type. */
145 firm_kind kind; /**< the firm kind, must be k_type */
146 const tp_op *type_op; /**< the type operation of the type */
147 ident *name; /**< The name of the type */
148 ir_visibility visibility;/**< Visibility of entities of this type. */
149 unsigned flags; /**< Type flags, a bitmask of enum type_flags. */
150 int size; /**< Size of an ir_entity of this type. This is determined
151 when fixing the layout of this class. Size must be
153 int align; /**< Alignment of an ir_entity of this type. This should be
154 set according to the source language needs. If not set it's
155 calculated automatically by get_type_alignment().
156 Alignment must be given in bits. */
157 ir_mode *mode; /**< The mode for atomic types */
158 unsigned long visit; /**< visited counter for walks of the type information */
159 void *link; /**< holds temporary data - like in irnode_t.h */
160 struct dbg_info *dbi; /**< A pointer to information for debug support. */
161 ir_type *assoc_type; /**< The associated lowered/unlowered type */
163 /* ------------- fields for analyses ---------------*/
166 long nr; /**< An unique node number for each node to make output
169 tp_attr attr; /**< Type kind specific fields. This must be the last
170 entry in this struct! Varying size! */
174 * Creates a new type representation:
176 * @param type_op the kind of this type. May not be type_id.
177 * @param mode the mode to be used for this type, may be NULL
178 * @param name an ident for the name of this type.
179 * @param db debug info
181 * @return A new type of the given type. The remaining private attributes are not
182 * initialized. The type is in state layout_undefined.
185 new_type(tp_op *type_op, ir_mode *mode, ident *name, dbg_info *db);
186 void free_type_attrs (ir_type *tp);
188 void free_class_entities (ir_type *clss);
189 void free_struct_entities (ir_type *strct);
190 void free_method_entities (ir_type *method);
191 void free_union_entities (ir_type *uni);
192 void free_array_entities (ir_type *array);
193 void free_enumeration_entities(ir_type *enumeration);
194 void free_pointer_entities (ir_type *pointer);
196 void free_array_automatic_entities(ir_type *array);
198 void free_class_attrs (ir_type *clss);
199 void free_struct_attrs (ir_type *strct);
200 void free_method_attrs (ir_type *method);
201 void free_union_attrs (ir_type *uni);
202 void free_array_attrs (ir_type *array);
203 void free_enumeration_attrs(ir_type *enumeration);
204 void free_pointer_attrs (ir_type *pointer);
206 void set_class_mode(ir_type *tp, ir_mode *mode);
207 void set_struct_mode(ir_type *tp, ir_mode *mode);
208 void set_pointer_mode(ir_type *tp, ir_mode *mode);
209 void set_primitive_mode(ir_type *tp, ir_mode *mode);
210 void set_enumeration_mode(ir_type *tp, ir_mode *mode);
212 void set_class_size_bits(ir_type *tp, int bits);
213 void set_struct_size_bits(ir_type *tp, int bits);
214 void set_union_size_bits(ir_type *tp, int bits);
215 void set_array_size_bits(ir_type *tp, int size);
216 void set_default_size_bits(ir_type *tp, int size);
219 * Initialize the type module.
221 * @param builtin_db debug info for built-in objects
222 * @param default_cc_mask default calling conventions for methods
224 void firm_init_type(dbg_info *builtin_db, unsigned default_cc_mask);
227 /* ------------------- *
229 * ------------------- */
231 extern unsigned long firm_type_visited;
233 static INLINE void _set_master_type_visited(unsigned long val) { firm_type_visited = val; }
234 static INLINE unsigned long _get_master_type_visited(void) { return firm_type_visited; }
235 static INLINE void _inc_master_type_visited(void) { ++firm_type_visited; }
238 _get_type_link(const ir_type *tp) {
239 assert(tp && tp->kind == k_type);
244 _set_type_link(ir_type *tp, void *l) {
245 assert(tp && tp->kind == k_type);
249 static INLINE const tp_op*
250 _get_type_tpop(const ir_type *tp) {
251 assert(tp && tp->kind == k_type);
256 _get_type_tpop_nameid(const ir_type *tp) {
257 assert(tp && tp->kind == k_type);
258 return get_tpop_ident(tp->type_op);
261 static INLINE tp_opcode
262 _get_type_tpop_code(const ir_type *tp) {
263 assert(tp && tp->kind == k_type);
264 return get_tpop_code(tp->type_op);
267 static INLINE ir_mode *
268 _get_type_mode(const ir_type *tp) {
269 assert(tp && tp->kind == k_type);
273 static INLINE ident *
274 _get_type_ident(const ir_type *tp) {
275 assert(tp && tp->kind == k_type);
280 _set_type_ident(ir_type *tp, ident* id) {
281 assert(tp && tp->kind == k_type);
286 _get_type_size_bits(const ir_type *tp) {
287 assert(tp && tp->kind == k_type);
292 _get_type_size_bytes(const ir_type *tp) {
293 int size = _get_type_size_bits(tp);
296 if ((size & 7) != 0) {
297 assert(0 && "cannot take byte size of this type");
303 static INLINE type_state
304 _get_type_state(const ir_type *tp) {
305 assert(tp && tp->kind == k_type);
306 return tp->flags & tf_layout_fixed ? layout_fixed : layout_undefined;
309 static INLINE unsigned long
310 _get_type_visited(const ir_type *tp) {
311 assert(tp && tp->kind == k_type);
316 _set_type_visited(ir_type *tp, unsigned long num) {
317 assert(tp && tp->kind == k_type);
322 _mark_type_visited(ir_type *tp) {
323 assert(tp && tp->kind == k_type);
324 assert(tp->visit < firm_type_visited);
325 tp->visit = firm_type_visited;
329 _type_visited(const ir_type *tp) {
330 assert(tp && tp->kind == k_type);
331 return tp->visit >= firm_type_visited;
335 _type_not_visited(const ir_type *tp) {
336 assert(tp && tp->kind == k_type);
337 return tp->visit < firm_type_visited;
341 _is_type(const void *thing) {
342 return (get_kind(thing) == k_type);
346 _is_class_type(const ir_type *clss) {
348 return (clss->type_op == type_class);
352 _get_class_n_members (const ir_type *clss) {
353 assert(clss && (clss->type_op == type_class));
354 return (ARR_LEN (clss->attr.ca.members));
357 static INLINE ir_entity *
358 _get_class_member (const ir_type *clss, int pos) {
359 assert(clss && (clss->type_op == type_class));
360 assert(pos >= 0 && pos < _get_class_n_members(clss));
361 return clss->attr.ca.members[pos];
364 static INLINE unsigned
365 _get_class_vtable_size(const ir_type *clss) {
366 assert(clss && (clss->type_op == type_class));
367 return clss->attr.ca.vtable_size;
371 _set_class_vtable_size(ir_type *clss, unsigned vtable_size) {
372 assert(clss && (clss->type_op == type_class));
373 clss->attr.ca.vtable_size = vtable_size;
377 _is_class_final(const ir_type *clss) {
378 assert(clss && (clss->type_op == type_class));
379 return clss->attr.ca.clss_flags & cf_final_class;
383 _set_class_final(ir_type *clss, int final) {
384 assert(clss && (clss->type_op == type_class));
386 clss->attr.ca.clss_flags |= cf_final_class;
388 clss->attr.ca.clss_flags &= ~cf_final_class;
392 _is_class_interface(const ir_type *clss) {
393 assert(clss && (clss->type_op == type_class));
394 return clss->attr.ca.clss_flags & cf_interface_class;
398 _set_class_interface(ir_type *clss, int final) {
399 assert(clss && (clss->type_op == type_class));
401 clss->attr.ca.clss_flags |= cf_interface_class;
403 clss->attr.ca.clss_flags &= ~cf_interface_class;
407 _is_class_abstract(const ir_type *clss) {
408 assert(clss && (clss->type_op == type_class));
409 return clss->attr.ca.clss_flags & cf_absctract_class;
413 _set_class_abstract(ir_type *clss, int final) {
414 assert(clss && (clss->type_op == type_class));
416 clss->attr.ca.clss_flags |= cf_absctract_class;
418 clss->attr.ca.clss_flags &= ~cf_absctract_class;
422 _is_struct_type(const ir_type *strct) {
424 return (strct->type_op == type_struct);
428 _is_method_type(const ir_type *method) {
430 return (method->type_op == type_method);
434 _is_union_type(const ir_type *uni) {
436 return (uni->type_op == type_union);
440 _is_array_type(const ir_type *array) {
442 return (array->type_op == type_array);
446 _is_enumeration_type(const ir_type *enumeration) {
448 return (enumeration->type_op == type_enumeration);
452 _is_pointer_type(const ir_type *pointer) {
454 return (pointer->type_op == type_pointer);
457 /** Returns true if a type is a primitive type. */
459 _is_primitive_type(const ir_type *primitive) {
460 assert(primitive && primitive->kind == k_type);
461 return (primitive->type_op == type_primitive);
465 _is_atomic_type(const ir_type *tp) {
466 assert(tp && tp->kind == k_type);
467 return (_is_primitive_type(tp) || _is_pointer_type(tp) ||
468 _is_enumeration_type(tp));
472 _get_method_n_params(const ir_type *method) {
473 assert(method && (method->type_op == type_method));
474 return method->attr.ma.n_params;
478 _get_method_n_ress(const ir_type *method) {
479 assert(method && (method->type_op == type_method));
480 return method->attr.ma.n_res;
483 static INLINE unsigned
484 _get_method_additional_properties(const ir_type *method) {
485 assert(method && (method->type_op == type_method));
486 return method->attr.ma.additional_properties;
490 _set_method_additional_properties(ir_type *method, unsigned mask) {
491 assert(method && (method->type_op == type_method));
493 /* do not allow to set the mtp_property_inherited flag or
494 * the automatic inheritance of flags will not work */
495 method->attr.ma.additional_properties = mask & ~mtp_property_inherited;
499 _set_method_additional_property(ir_type *method, mtp_additional_property flag) {
500 assert(method && (method->type_op == type_method));
502 /* do not allow to set the mtp_property_inherited flag or
503 * the automatic inheritance of flags will not work */
504 method->attr.ma.additional_properties |= flag & ~mtp_property_inherited;
507 static INLINE unsigned
508 _get_method_calling_convention(const ir_type *method) {
509 assert(method && (method->type_op == type_method));
510 return method->attr.ma.irg_calling_conv;
514 _set_method_calling_convention(ir_type *method, unsigned cc_mask) {
515 assert(method && (method->type_op == type_method));
516 method->attr.ma.irg_calling_conv = cc_mask;
519 #define set_master_type_visited(val) _set_master_type_visited(val)
520 #define get_master_type_visited() _get_master_type_visited()
521 #define inc_master_type_visited() _inc_master_type_visited()
522 #define get_type_link(tp) _get_type_link(tp)
523 #define set_type_link(tp, l) _set_type_link(tp, l)
524 #define get_type_tpop(tp) _get_type_tpop(tp)
525 #define get_type_tpop_nameid(tp) _get_type_tpop_nameid(tp)
526 #define get_type_tpop_code(tp) _get_type_tpop_code(tp)
527 #define get_type_mode(tp) _get_type_mode(tp)
528 #define get_type_ident(tp) _get_type_ident(tp)
529 #define set_type_ident(tp, id) _set_type_ident(tp, id)
530 #define get_type_size_bits(tp) _get_type_size_bits(tp)
531 #define get_type_size_bytes(tp) _get_type_size_bytes(tp)
532 #define get_type_state(tp) _get_type_state(tp)
533 #define get_type_visited(tp) _get_type_visited(tp)
534 #define set_type_visited(tp, num) _set_type_visited(tp, num)
535 #define mark_type_visited(tp) _mark_type_visited(tp)
536 #define type_visited(tp) _type_visited(tp)
537 #define type_not_visited(tp) _type_not_visited(tp)
538 #define is_type(thing) _is_type(thing)
539 #define is_Class_type(clss) _is_class_type(clss)
540 #define get_class_n_members(clss) _get_class_n_members(clss)
541 #define get_class_member(clss, pos) _get_class_member(clss, pos)
542 #define get_class_vtable_size(clss) _get_class_vtable_size(clss)
543 #define set_class_vtable_size(clss, size) _set_class_vtable_size(clss, size)
544 #define is_class_final(clss) _is_class_final(clss)
545 #define set_class_final(clss, flag) _set_class_final(clss, flag)
546 #define is_class_interface(clss) _is_class_interface(clss)
547 #define set_class_interface(clss, flag) _set_class_interface(clss, flag)
548 #define is_class_abstract(clss) _is_class_abstract(clss)
549 #define set_class_abstract(clss, flag) _set_class_abstract(clss, flag)
550 #define is_Struct_type(strct) _is_struct_type(strct)
551 #define is_Method_type(method) _is_method_type(method)
552 #define is_Union_type(uni) _is_union_type(uni)
553 #define is_Array_type(array) _is_array_type(array)
554 #define is_Enumeration_type(enumeration) _is_enumeration_type(enumeration)
555 #define is_Pointer_type(pointer) _is_pointer_type(pointer)
556 #define is_Primitive_type(primitive) _is_primitive_type(primitive)
557 #define is_atomic_type(tp) _is_atomic_type(tp)
558 #define get_method_n_params(method) _get_method_n_params(method)
559 #define get_method_n_ress(method) _get_method_n_ress(method)
560 #define get_method_additional_properties(method) _get_method_additional_properties(method)
561 #define set_method_additional_properties(method, mask) _set_method_additional_properties(method, mask)
562 #define set_method_additional_property(method, flag) _set_method_additional_property(method, flag)
563 #define get_method_calling_convention(method) _get_method_calling_convention(method)
564 #define set_method_calling_convention(method, cc_mask) _set_method_calling_convention(method, cc_mask)
566 #endif /* _FIRM_TR_TYPE_T_H_ */