3 * File name: ir/tr/type_t.h
4 * Purpose: Representation of types -- private header.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 # include "firm_config.h"
24 * This file contains the datatypes hidden in type.h.
26 * @author Goetz Lindenmaier
27 * @see type.h tpop_t.h tpop.h
30 /** class attributes */
32 entity **members; /**< fields and methods of this class */
33 type **subtypes; /**< direct subtypes */
34 type **supertypes; /**< direct supertypes */
35 peculiarity peculiarity;
36 int dfn; /**< number used for 'instanceof' operator */
39 /** struct attributes */
41 entity **members; /**< fields of this struct. No method entities allowed. */
44 /** A (type, entity) pair */
46 type *tp; /**< a type */
47 entity *ent; /**< an entity */
50 /** method attributes */
52 int n_params; /**< number of parameters */
53 tp_ent_pair *param_type; /**< array of parameter type/value entities pairs */
54 type *value_params; /**< A type whose entities represent copied value arguments. */
55 int n_res; /**< number of results */
56 tp_ent_pair *res_type; /**< array of result type/value entity pairs */
57 type *value_ress; /**< A type whose entities represent copied value results. */
58 variadicity variadicity; /**< variadicity of the method. */
59 int first_variadic_param; /**< index of the first variadic param or -1 if non-variadic .*/
62 /** union attributes */
64 entity **members; /**< fields of this union. No method entities allowed. */
67 /** array attributes */
69 int n_dimensions; /**< Number of array dimensions. */
70 ir_node **lower_bound; /**< Lower bounds of dimensions. Usually all 0. */
71 ir_node **upper_bound; /**< Upper bounds or dimensions. */
72 int *order; /**< Ordering of dimensions. */
73 type *element_type; /**< The type of the array elements. */
74 entity *element_ent; /**< Entity for the array elements, to be used for
75 element selection with Sel. */
78 /** enum attributes */
80 int n_enums; /**< Number of enumerators. */
81 tarval **enumer; /**< Contains all constants that represent a member
82 of the enum -- enumerators. */
83 ident **enum_nameid;/**< Contains the names of the enum fields as specified by
87 /** pointer attributes */
89 type *points_to; /**< The type of the entity the pointer points to. */
93 typedef struct { * No private attr yet! *
98 typedef struct { * No private attr, must be smaller than others! *
102 /** General type attributes. */
104 cls_attr ca; /**< attributes of a class type */
105 stc_attr sa; /**< attributes of a struct type */
106 mtd_attr ma; /**< attributes of a method type */
107 uni_attr ua; /**< attributes of an union type */
108 arr_attr aa; /**< attributes of an array type */
109 enm_attr ea; /**< attributes of an enumeration type */
110 ptr_attr pa; /**< attributes of a pointer type */
113 /** the structure of a type */
115 firm_kind kind; /**< the firm kind, must be k_type */
116 const tp_op *type_op; /**< the type operation of the type */
117 ident *name; /**< The name of the type */
118 visibility visibility; /**< Visibility of entities of this type. */
119 char frame_type; /**< True if this is a frame type, false else */
120 type_state state; /**< Represents the types state: layout undefined or
122 int size; /**< Size of an entity of this type. This is determined
123 when fixing the layout of this class. Size must be
125 int align; /**< Alignment of an entity of this type. This should be
126 set according to the source language needs. If not set it's
127 calculated automatically by get_type_alignment().
128 Alignment must be given in bits. */
129 ir_mode *mode; /**< The mode for atomic types */
130 unsigned long visit; /**< visited counter for walks of the type information */
131 void *link; /**< holds temporary data - like in irnode_t.h */
132 struct dbg_info *dbi; /**< A pointer to information for debug support. */
134 /* ------------- fields for analyses ---------------*/
137 int nr; /**< a unique node number for each node to make output
140 tp_attr attr; /* type kind specific fields. This must be the last
141 entry in this struct! Varying size! */
145 * Creates a new type representation:
147 * @param type_op the kind of this type. May not be type_id.
148 * @param mode the mode to be used for this type, may be NULL
149 * @param name an ident for the name of this type.
150 * @param db debug info
152 * @return A new type of the given type. The remaining private attributes are not
153 * initialized. The type is in state layout_undefined.
156 new_type(tp_op *type_op, ir_mode *mode, ident *name, dbg_info *db);
157 void free_type_attrs (type *tp);
159 void free_class_entities (type *clss);
160 void free_struct_entities (type *strct);
161 void free_method_entities (type *method);
162 void free_union_entities (type *uni);
163 void free_array_entities (type *array);
164 void free_enumeration_entities(type *enumeration);
165 void free_pointer_entities (type *pointer);
167 void free_array_automatic_entities(type *array);
169 void free_class_attrs (type *clss);
170 void free_struct_attrs (type *strct);
171 void free_method_attrs (type *method);
172 void free_union_attrs (type *uni);
173 void free_array_attrs (type *array);
174 void free_enumeration_attrs(type *enumeration);
175 void free_pointer_attrs (type *pointer);
177 void set_class_mode(type *tp, ir_mode *mode);
178 void set_struct_mode(type *tp, ir_mode *mode);
179 void set_pointer_mode(type *tp, ir_mode *mode);
180 void set_primitive_mode(type *tp, ir_mode *mode);
181 void set_enumeration_mode(type *tp, ir_mode *mode);
183 void set_class_size_bits(type *tp, int bits);
184 void set_struct_size_bits(type *tp, int bits);
185 void set_union_size_bits(type *tp, int bits);
186 void set_array_size_bits(type *tp, int size);
187 void set_default_size_bits(type *tp, int size);
190 * Initialize the type module.
192 * @param builtin_db debug info for builtin objects
194 void firm_init_type(dbg_info *builtin_db);
197 /* ------------------- *
199 * ------------------- */
201 extern unsigned long firm_type_visited;
203 static INLINE void _set_master_type_visited(unsigned long val) { firm_type_visited = val; }
204 static INLINE unsigned long _get_master_type_visited(void) { return firm_type_visited; }
205 static INLINE void _inc_master_type_visited(void) { ++firm_type_visited; }
208 _get_type_link(const type *tp) {
209 assert(tp && tp->kind == k_type);
214 _set_type_link(type *tp, void *l) {
215 assert(tp && tp->kind == k_type);
219 static INLINE const tp_op*
220 _get_type_tpop(const type *tp) {
221 assert(tp && tp->kind == k_type);
226 _get_type_tpop_nameid(const type *tp) {
227 assert(tp && tp->kind == k_type);
228 return get_tpop_ident(tp->type_op);
231 static INLINE tp_opcode
232 _get_type_tpop_code(const type *tp) {
233 assert(tp && tp->kind == k_type);
234 return get_tpop_code(tp->type_op);
237 static INLINE ir_mode *
238 _get_type_mode(const type *tp) {
239 assert(tp && tp->kind == k_type);
243 static INLINE ident *
244 _get_type_ident(const type *tp) {
245 assert(tp && tp->kind == k_type);
250 _set_type_ident(type *tp, ident* id) {
251 assert(tp && tp->kind == k_type);
256 _get_type_size_bits(const type *tp) {
257 assert(tp && tp->kind == k_type);
262 _get_type_size_bytes(const type *tp) {
263 int size = _get_type_size_bits(tp);
266 if ((size & 7) != 0) {
267 assert(0 && "cannot take byte size of this type");
273 static INLINE type_state
274 _get_type_state(const type *tp) {
275 assert(tp && tp->kind == k_type);
279 static INLINE unsigned long
280 _get_type_visited(const type *tp) {
281 assert(tp && tp->kind == k_type);
286 _set_type_visited(type *tp, unsigned long num) {
287 assert(tp && tp->kind == k_type);
292 _mark_type_visited(type *tp) {
293 assert(tp && tp->kind == k_type);
294 assert(tp->visit < firm_type_visited);
295 tp->visit = firm_type_visited;
299 _type_visited(const type *tp) {
300 assert(tp && tp->kind == k_type);
301 return tp->visit >= firm_type_visited;
305 _type_not_visited(const type *tp) {
306 assert(tp && tp->kind == k_type);
307 return tp->visit < firm_type_visited;
311 _is_type(const void *thing) {
312 return (get_kind(thing) == k_type);
316 _is_class_type(const type *clss) {
318 return (clss->type_op == type_class);
322 _get_class_n_members (const type *clss) {
323 assert(clss && (clss->type_op == type_class));
324 return (ARR_LEN (clss->attr.ca.members));
327 static INLINE entity *
328 _get_class_member (const type *clss, int pos) {
329 assert(clss && (clss->type_op == type_class));
330 assert(pos >= 0 && pos < _get_class_n_members(clss));
331 return clss->attr.ca.members[pos];
335 _is_struct_type(const type *strct) {
337 return (strct->type_op == type_struct);
341 _is_method_type(const type *method) {
343 return (method->type_op == type_method);
347 _is_union_type(const type *uni) {
349 return (uni->type_op == type_union);
353 _is_array_type(const type *array) {
355 return (array->type_op == type_array);
359 _is_enumeration_type(const type *enumeration) {
361 return (enumeration->type_op == type_enumeration);
365 _is_pointer_type(const type *pointer) {
367 return (pointer->type_op == type_pointer);
370 /** Returns true if a type is a primitive type. */
372 _is_primitive_type(const type *primitive) {
373 assert(primitive && primitive->kind == k_type);
374 return (primitive->type_op == type_primitive);
378 _is_atomic_type(const type *tp) {
379 assert(tp && tp->kind == k_type);
380 return (_is_primitive_type(tp) || _is_pointer_type(tp) ||
381 _is_enumeration_type(tp));
385 _get_method_n_params(const type *method) {
386 assert(method && (method->type_op == type_method));
387 return method->attr.ma.n_params;
391 _get_method_n_ress(const type *method) {
392 assert(method && (method->type_op == type_method));
393 return method->attr.ma.n_res;
397 #define set_master_type_visited(val) _set_master_type_visited(val)
398 #define get_master_type_visited() _get_master_type_visited()
399 #define inc_master_type_visited() _inc_master_type_visited()
400 #define get_type_link(tp) _get_type_link(tp)
401 #define set_type_link(tp, l) _set_type_link(tp, l)
402 #define get_type_tpop(tp) _get_type_tpop(tp)
403 #define get_type_tpop_nameid(tp) _get_type_tpop_nameid(tp)
404 #define get_type_tpop_code(tp) _get_type_tpop_code(tp)
405 #define get_type_mode(tp) _get_type_mode(tp)
406 #define get_type_ident(tp) _get_type_ident(tp)
407 #define set_type_ident(tp, id) _set_type_ident(tp, id)
408 #define get_type_size(tp) _get_type_size(tp)
409 #define get_type_state(tp) _get_type_state(tp)
410 #define get_type_visited(tp) _get_type_visited(tp)
411 #define set_type_visited(tp, num) _set_type_visited(tp, num)
412 #define mark_type_visited(tp) _mark_type_visited(tp)
413 #define type_visited(tp) _type_visited(tp)
414 #define type_not_visited(tp) _type_not_visited(tp)
415 #define is_type(thing) _is_type(thing)
416 #define is_Class_type(clss) _is_class_type(clss)
417 #define get_class_n_members(clss) _get_class_n_members(clss)
418 #define get_class_member(clss, pos) _get_class_member(clss, pos)
419 #define is_Struct_type(strct) _is_struct_type(strct)
420 #define is_Method_type(method) _is_method_type(method)
421 #define is_Union_type(uni) _is_union_type(uni)
422 #define is_Array_type(array) _is_array_type(array)
423 #define is_Enumeration_type(enumeration) _is_enumeration_type(enumeration)
424 #define is_Pointer_type(pointer) _is_pointer_type(pointer)
425 #define is_Primitive_type(primitive) _is_primitive_type(primitive)
426 #define is_atomic_type(tp) _is_atomic_type(tp)
427 #define get_method_n_params(method) _get_method_n_params(method)
428 #define get_method_n_ress(method) _get_method_n_ress(method)
430 # endif /* _TYPE_T_H_ */