2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Representation of types -- private header.
23 * @author Goetz Lindenmaier, Michael Beck
25 * @see type.h tpop_t.h tpop.h
27 #ifndef FIRM_TR_TYPE_T_H
28 #define FIRM_TR_TYPE_T_H
30 #include "firm_config.h"
39 cf_none = 0, /**< No flags. */
40 cf_final_class = 1, /**< Set if a class is an final class */
41 cf_interface_class = 2, /**< Set if a class is an "interface" */
42 cf_absctract_class = 4, /**< Set if a class is "abstract" */
45 /** Class type attributes. */
47 ir_entity **members; /**< Array containing the fields and methods of this class. */
48 ir_type **subtypes; /**< Array containing the direct subtypes. */
49 ir_type **supertypes; /**< Array containing the direct supertypes */
50 ir_peculiarity peculiarity; /**< The peculiarity of this class. */
51 ir_entity *type_info; /**< An ir_entity representing this class, used for type info. */
52 int dfn; /**< A number that can be used for 'instanceof' operator. */
53 unsigned vtable_size; /**< The size of the vtable for this class. */
54 unsigned clss_flags; /**< Additional class flags. */
57 /** Struct type attributes. */
59 ir_entity **members; /**< Fields of this struct. No method entities allowed. */
62 /** A (type, ir_entity) pair. */
64 ir_type *tp; /**< A type. */
65 ir_entity *ent; /**< An ir_entity. */
66 ident *param_name; /**< For debugging purposes: the name of the parameter */
69 /** Method type attributes. */
71 int n_params; /**< Number of parameters. */
72 tp_ent_pair *params; /**< Array of parameter type/value entities pairs. */
73 ir_type *value_params; /**< A type whose entities represent copied value arguments. */
74 int n_res; /**< Number of results. */
75 tp_ent_pair *res_type; /**< Array of result type/value ir_entity pairs. */
76 ir_type *value_ress; /**< A type whose entities represent copied value results. */
77 variadicity variadicity; /**< The variadicity of the method. */
78 int first_variadic_param; /**< The index of the first variadic parameter or -1 if non-variadic .*/
79 unsigned additional_properties; /**< Set of additional method properties. */
80 unsigned irg_calling_conv; /**< A set of calling convention flags. */
83 /** Union type attributes. */
85 ir_entity **members; /**< Fields of this union. No method entities allowed. */
88 /** Array type attributes. */
90 int n_dimensions; /**< Number of array dimensions. */
91 ir_node **lower_bound; /**< Lower bounds of dimensions. Usually all 0. */
92 ir_node **upper_bound; /**< Upper bounds or dimensions. */
93 int *order; /**< Ordering of dimensions. */
94 ir_type *element_type; /**< The type of the array elements. */
95 ir_entity *element_ent; /**< entity for the array elements, to be used for
96 element selection with a Sel node. */
99 /** An enumerator constant. */
100 struct ir_enum_const {
101 tarval *value; /**< The constants that represents this enumerator identifier. */
102 ident *nameid; /**< The name of the enumerator identifier. */
103 ir_type *owner; /**< owner type of this enumerator constant. */
106 /** Enum type attributes. */
108 ir_enum_const *enumer; /**< Contains all enumerator constants that represent a member
109 of the enum -- enumerators. */
112 /** Pointer type attributes. */
114 ir_type *points_to; /**< The type of the ir_entity the pointer points to. */
118 typedef struct { * No private attr yet! *
123 typedef struct { * No private attr, must be smaller than others! *
127 /** General type attributes. */
129 cls_attr ca; /**< Attributes of a class type */
130 stc_attr sa; /**< Attributes of a struct type */
131 mtd_attr ma; /**< Attributes of a method type */
132 uni_attr ua; /**< Attributes of an union type */
133 arr_attr aa; /**< Attributes of an array type */
134 enm_attr ea; /**< Attributes of an enumeration type */
135 ptr_attr pa; /**< Attributes of a pointer type */
138 /** Additional type flags. */
140 tf_none = 0, /**< No flags. */
141 tf_frame_type = 1, /**< Set if this is a frame type. */
142 tf_value_param_type = 2, /**< Set if this is a value param type. */
143 tf_lowered_type = 4, /**< Set if this is a lowered type. */
144 tf_layout_fixed = 8, /**< Set if the layout of a type is fixed */
145 tf_global_type = 16, /**< Set only for the global type */
146 tf_tls_type = 32, /**< Set only for the tls type */
149 /** The structure of a type. */
151 firm_kind kind; /**< the firm kind, must be k_type */
152 const tp_op *type_op; /**< the type operation of the type */
153 ident *name; /**< The name of the type */
154 ir_visibility visibility;/**< Visibility of entities of this type. */
155 unsigned flags; /**< Type flags, a bitmask of enum type_flags. */
156 int size; /**< Size of an ir_entity of this type. This is determined
157 when fixing the layout of this class. Size must be
159 int align; /**< Alignment of an ir_entity of this type. This should be
160 set according to the source language needs. If not set it's
161 calculated automatically by get_type_alignment().
162 Alignment must be given in bits. */
163 ir_mode *mode; /**< The mode for atomic types */
164 unsigned long visit; /**< visited counter for walks of the type information */
165 void *link; /**< holds temporary data - like in irnode_t.h */
166 struct dbg_info *dbi; /**< A pointer to information for debug support. */
167 ir_type *assoc_type; /**< The associated lowered/unlowered type */
169 /* ------------- fields for analyses ---------------*/
172 long nr; /**< An unique node number for each node to make output
175 tp_attr attr; /**< Type kind specific fields. This must be the last
176 entry in this struct! Varying size! */
180 * Creates a new type representation:
182 * @param type_op the kind of this type. May not be type_id.
183 * @param mode the mode to be used for this type, may be NULL
184 * @param name an ident for the name of this type.
185 * @param db debug info
187 * @return A new type of the given type. The remaining private attributes are not
188 * initialized. The type is in state layout_undefined.
191 new_type(tp_op *type_op, ir_mode *mode, ident *name, dbg_info *db);
192 void free_type_attrs (ir_type *tp);
194 void free_class_entities (ir_type *clss);
195 void free_struct_entities (ir_type *strct);
196 void free_method_entities (ir_type *method);
197 void free_union_entities (ir_type *uni);
198 void free_array_entities (ir_type *array);
199 void free_enumeration_entities(ir_type *enumeration);
200 void free_pointer_entities (ir_type *pointer);
202 void free_array_automatic_entities(ir_type *array);
204 void free_class_attrs (ir_type *clss);
205 void free_struct_attrs (ir_type *strct);
206 void free_method_attrs (ir_type *method);
207 void free_union_attrs (ir_type *uni);
208 void free_array_attrs (ir_type *array);
209 void free_enumeration_attrs(ir_type *enumeration);
210 void free_pointer_attrs (ir_type *pointer);
212 void set_class_mode(ir_type *tp, ir_mode *mode);
213 void set_struct_mode(ir_type *tp, ir_mode *mode);
214 void set_pointer_mode(ir_type *tp, ir_mode *mode);
215 void set_primitive_mode(ir_type *tp, ir_mode *mode);
216 void set_enumeration_mode(ir_type *tp, ir_mode *mode);
218 void set_class_size_bits(ir_type *tp, int bits);
219 void set_struct_size_bits(ir_type *tp, int bits);
220 void set_union_size_bits(ir_type *tp, int bits);
221 void set_array_size_bits(ir_type *tp, int size);
222 void set_default_size_bits(ir_type *tp, int size);
225 * Initialize the type module.
227 * @param builtin_db debug info for built-in objects
228 * @param default_cc_mask default calling conventions for methods
230 void firm_init_type(dbg_info *builtin_db, unsigned default_cc_mask);
233 /* ------------------- *
235 * ------------------- */
237 extern unsigned long firm_type_visited;
239 static INLINE void _set_master_type_visited(unsigned long val) { firm_type_visited = val; }
240 static INLINE unsigned long _get_master_type_visited(void) { return firm_type_visited; }
241 static INLINE void _inc_master_type_visited(void) { ++firm_type_visited; }
244 _get_type_link(const ir_type *tp) {
245 assert(tp && tp->kind == k_type);
250 _set_type_link(ir_type *tp, void *l) {
251 assert(tp && tp->kind == k_type);
255 static INLINE const tp_op*
256 _get_type_tpop(const ir_type *tp) {
257 assert(tp && tp->kind == k_type);
262 _get_type_tpop_nameid(const ir_type *tp) {
263 assert(tp && tp->kind == k_type);
264 return get_tpop_ident(tp->type_op);
267 static INLINE tp_opcode
268 _get_type_tpop_code(const ir_type *tp) {
269 assert(tp && tp->kind == k_type);
270 return get_tpop_code(tp->type_op);
273 static INLINE ir_mode *
274 _get_type_mode(const ir_type *tp) {
275 assert(tp && tp->kind == k_type);
279 static INLINE ident *
280 _get_type_ident(const ir_type *tp) {
281 assert(tp && tp->kind == k_type);
286 _set_type_ident(ir_type *tp, ident* id) {
287 assert(tp && tp->kind == k_type);
292 _get_type_size_bits(const ir_type *tp) {
293 assert(tp && tp->kind == k_type);
298 _get_type_size_bytes(const ir_type *tp) {
299 int size = _get_type_size_bits(tp);
302 if ((size & 7) != 0) {
303 assert(0 && "cannot take byte size of this type");
309 static INLINE type_state
310 _get_type_state(const ir_type *tp) {
311 assert(tp && tp->kind == k_type);
312 return tp->flags & tf_layout_fixed ? layout_fixed : layout_undefined;
315 static INLINE unsigned long
316 _get_type_visited(const ir_type *tp) {
317 assert(tp && tp->kind == k_type);
322 _set_type_visited(ir_type *tp, unsigned long num) {
323 assert(tp && tp->kind == k_type);
328 _mark_type_visited(ir_type *tp) {
329 assert(tp && tp->kind == k_type);
330 assert(tp->visit < firm_type_visited);
331 tp->visit = firm_type_visited;
335 _type_visited(const ir_type *tp) {
336 assert(tp && tp->kind == k_type);
337 return tp->visit >= firm_type_visited;
341 _type_not_visited(const ir_type *tp) {
342 assert(tp && tp->kind == k_type);
343 return tp->visit < firm_type_visited;
347 _is_type(const void *thing) {
348 return (get_kind(thing) == k_type);
352 _is_class_type(const ir_type *clss) {
354 return (clss->type_op == type_class);
358 _get_class_n_members (const ir_type *clss) {
359 assert(clss && (clss->type_op == type_class));
360 return (ARR_LEN (clss->attr.ca.members));
363 static INLINE ir_entity *
364 _get_class_member (const ir_type *clss, int pos) {
365 assert(clss && (clss->type_op == type_class));
366 assert(pos >= 0 && pos < _get_class_n_members(clss));
367 return clss->attr.ca.members[pos];
370 static INLINE unsigned
371 _get_class_vtable_size(const ir_type *clss) {
372 assert(clss && (clss->type_op == type_class));
373 return clss->attr.ca.vtable_size;
377 _set_class_vtable_size(ir_type *clss, unsigned vtable_size) {
378 assert(clss && (clss->type_op == type_class));
379 clss->attr.ca.vtable_size = vtable_size;
383 _is_class_final(const ir_type *clss) {
384 assert(clss && (clss->type_op == type_class));
385 return clss->attr.ca.clss_flags & cf_final_class;
389 _set_class_final(ir_type *clss, int final) {
390 assert(clss && (clss->type_op == type_class));
392 clss->attr.ca.clss_flags |= cf_final_class;
394 clss->attr.ca.clss_flags &= ~cf_final_class;
398 _is_class_interface(const ir_type *clss) {
399 assert(clss && (clss->type_op == type_class));
400 return clss->attr.ca.clss_flags & cf_interface_class;
404 _set_class_interface(ir_type *clss, int final) {
405 assert(clss && (clss->type_op == type_class));
407 clss->attr.ca.clss_flags |= cf_interface_class;
409 clss->attr.ca.clss_flags &= ~cf_interface_class;
413 _is_class_abstract(const ir_type *clss) {
414 assert(clss && (clss->type_op == type_class));
415 return clss->attr.ca.clss_flags & cf_absctract_class;
419 _set_class_abstract(ir_type *clss, int final) {
420 assert(clss && (clss->type_op == type_class));
422 clss->attr.ca.clss_flags |= cf_absctract_class;
424 clss->attr.ca.clss_flags &= ~cf_absctract_class;
428 _is_struct_type(const ir_type *strct) {
430 return (strct->type_op == type_struct);
434 _is_method_type(const ir_type *method) {
436 return (method->type_op == type_method);
440 _is_union_type(const ir_type *uni) {
442 return (uni->type_op == type_union);
446 _is_array_type(const ir_type *array) {
448 return (array->type_op == type_array);
452 _is_enumeration_type(const ir_type *enumeration) {
454 return (enumeration->type_op == type_enumeration);
458 _is_pointer_type(const ir_type *pointer) {
460 return (pointer->type_op == type_pointer);
463 /** Returns true if a type is a primitive type. */
465 _is_primitive_type(const ir_type *primitive) {
466 assert(primitive && primitive->kind == k_type);
467 return (primitive->type_op == type_primitive);
471 _is_atomic_type(const ir_type *tp) {
472 assert(tp && tp->kind == k_type);
473 return (_is_primitive_type(tp) || _is_pointer_type(tp) ||
474 _is_enumeration_type(tp));
478 _get_method_n_params(const ir_type *method) {
479 assert(method && (method->type_op == type_method));
480 return method->attr.ma.n_params;
484 _get_method_n_ress(const ir_type *method) {
485 assert(method && (method->type_op == type_method));
486 return method->attr.ma.n_res;
489 static INLINE unsigned
490 _get_method_additional_properties(const ir_type *method) {
491 assert(method && (method->type_op == type_method));
492 return method->attr.ma.additional_properties;
496 _set_method_additional_properties(ir_type *method, unsigned mask) {
497 assert(method && (method->type_op == type_method));
499 /* do not allow to set the mtp_property_inherited flag or
500 * the automatic inheritance of flags will not work */
501 method->attr.ma.additional_properties = mask & ~mtp_property_inherited;
505 _set_method_additional_property(ir_type *method, mtp_additional_property flag) {
506 assert(method && (method->type_op == type_method));
508 /* do not allow to set the mtp_property_inherited flag or
509 * the automatic inheritance of flags will not work */
510 method->attr.ma.additional_properties |= flag & ~mtp_property_inherited;
513 static INLINE unsigned
514 _get_method_calling_convention(const ir_type *method) {
515 assert(method && (method->type_op == type_method));
516 return method->attr.ma.irg_calling_conv;
520 _set_method_calling_convention(ir_type *method, unsigned cc_mask) {
521 assert(method && (method->type_op == type_method));
522 method->attr.ma.irg_calling_conv = cc_mask;
525 #define set_master_type_visited(val) _set_master_type_visited(val)
526 #define get_master_type_visited() _get_master_type_visited()
527 #define inc_master_type_visited() _inc_master_type_visited()
528 #define get_type_link(tp) _get_type_link(tp)
529 #define set_type_link(tp, l) _set_type_link(tp, l)
530 #define get_type_tpop(tp) _get_type_tpop(tp)
531 #define get_type_tpop_nameid(tp) _get_type_tpop_nameid(tp)
532 #define get_type_tpop_code(tp) _get_type_tpop_code(tp)
533 #define get_type_mode(tp) _get_type_mode(tp)
534 #define get_type_ident(tp) _get_type_ident(tp)
535 #define set_type_ident(tp, id) _set_type_ident(tp, id)
536 #define get_type_size_bits(tp) _get_type_size_bits(tp)
537 #define get_type_size_bytes(tp) _get_type_size_bytes(tp)
538 #define get_type_state(tp) _get_type_state(tp)
539 #define get_type_visited(tp) _get_type_visited(tp)
540 #define set_type_visited(tp, num) _set_type_visited(tp, num)
541 #define mark_type_visited(tp) _mark_type_visited(tp)
542 #define type_visited(tp) _type_visited(tp)
543 #define type_not_visited(tp) _type_not_visited(tp)
544 #define is_type(thing) _is_type(thing)
545 #define is_Class_type(clss) _is_class_type(clss)
546 #define get_class_n_members(clss) _get_class_n_members(clss)
547 #define get_class_member(clss, pos) _get_class_member(clss, pos)
548 #define get_class_vtable_size(clss) _get_class_vtable_size(clss)
549 #define set_class_vtable_size(clss, size) _set_class_vtable_size(clss, size)
550 #define is_class_final(clss) _is_class_final(clss)
551 #define set_class_final(clss, flag) _set_class_final(clss, flag)
552 #define is_class_interface(clss) _is_class_interface(clss)
553 #define set_class_interface(clss, flag) _set_class_interface(clss, flag)
554 #define is_class_abstract(clss) _is_class_abstract(clss)
555 #define set_class_abstract(clss, flag) _set_class_abstract(clss, flag)
556 #define is_Struct_type(strct) _is_struct_type(strct)
557 #define is_Method_type(method) _is_method_type(method)
558 #define is_Union_type(uni) _is_union_type(uni)
559 #define is_Array_type(array) _is_array_type(array)
560 #define is_Enumeration_type(enumeration) _is_enumeration_type(enumeration)
561 #define is_Pointer_type(pointer) _is_pointer_type(pointer)
562 #define is_Primitive_type(primitive) _is_primitive_type(primitive)
563 #define is_atomic_type(tp) _is_atomic_type(tp)
564 #define get_method_n_params(method) _get_method_n_params(method)
565 #define get_method_n_ress(method) _get_method_n_ress(method)
566 #define get_method_additional_properties(method) _get_method_additional_properties(method)
567 #define set_method_additional_properties(method, mask) _set_method_additional_properties(method, mask)
568 #define set_method_additional_property(method, flag) _set_method_additional_property(method, flag)
569 #define get_method_calling_convention(method) _get_method_calling_convention(method)
570 #define set_method_calling_convention(method, cc_mask) _set_method_calling_convention(method, cc_mask)
572 #endif /* FIRM_TR_TYPE_T_H */