renamed get_peculiarity_string() to get_peculiarity_name()
[libfirm] / ir / tr / type.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/type.h
4  * Purpose:     Representation of types.
5  * Author:      Goetz Lindenmaier
6  * Modified by: Michael Beck
7  * Created:
8  * Copyright:   (c) 2001-2003 Universität Karlsruhe
9  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
10  * CVS-ID:      $Id$
11  */
12
13 /**
14  * @file type.h
15  *
16  *  Datastructure to hold type information.
17  *
18  *  This module supplies a datastructure to represent all types
19  *  known in the compiled program.  This includes types specified
20  *  in the program as well as types defined by the language.  In the
21  *  view of the intermediate representation there is no difference
22  *  between these types.  Finally it specifies some auxiliary types.
23  *
24  *  There exist several kinds of types, arranged by the structure of
25  *  the type.  A type is described by a set of attributes.  Some of
26  *  these attributes are common to all types, others depend on the
27  *  kind of the type.
28  *
29  *  Types are different from the modes defined in irmode:  Types are
30  *  on the level of the programming language, modes at the level of
31  *  the target processor.
32  *
33  *  @see  tpop.h
34  */
35 #ifndef _FIRM_TR_TYPE_H_
36 #define _FIRM_TR_TYPE_H_
37
38 #include "firm_types.h"
39 #include "tpop.h"
40 #include "firm_common.h"
41 #include "dbginfo.h"
42
43 /**
44  *  An abstract data type to represent types.
45  *
46  *  This is the abstract data type with which any type known in the
47  *  compiled program can be represented.  This includes types specified
48  *  in the program as well as types defined by the language.  In the
49  *  view of the intermediate representation there is no difference
50  *  between these types.
51  *
52  *  There exist several kinds of types, arranged by the structure of
53  *  the type.  These are distinguished by a type opcode.
54  *  A type is described by a set of attributes.  Some of these attributes
55  *  are common to all types, others depend on the kind of the type.
56  *
57  *  The following describes the common attributes.  They can only be
58  *  accessed by the functions given below.
59  *
60  *  The common fields are:
61  *
62  *  - firm_kind: A firm_kind tag containing k_type.  This is useful
63  *               for dynamically checking whether a node is a type node.
64  *  - type_op:   A tp_op specifying the kind of the type.
65  *  - mode:      The mode to be used to represent the type on a machine.
66  *  - name:      An identifier specifying the name of the type.  To be
67  *               set by the frontend.
68  *  - size:      The size of the type, i.e. an entity of this type will
69  *               occupy size bits in memory.  In several cases this is
70  *               determined when fixing the layout of this type (class,
71  *               struct, union, array, enumeration).
72  *  - alignment  The alignment of the type, i.e. an entity of this type will
73  *               be allocated an an address in memory with this alignment.
74  *               In several cases this is determined when fixing the layout
75  *               of this type (class, struct, union, array)
76  *  - state:     The state of the type.  The state represents whether the
77  *               layout of the type is undefined or fixed (values: layout_undefined
78  *               or layout_fixed).  Compound types can have an undefined
79  *               layout.  The layout of the basic types primitive and pointer
80  *               is always layout_fixed.  If the layout of
81  *               compound types is fixed all entities must have an offset
82  *               and the size of the type must be set.
83  *               A fixed layout for enumeration types means that each enumeration
84  *               is associated with an implementation value.
85  *  - visit:     A counter for walks of the type information.
86  *  - link:      A void* to associate some additional information with the type.
87  *
88  *  These fields can only be accessed via access functions.
89  *
90  *  Depending on the value of @c type_op, i.e., depending on the kind of the
91  *  type the adt contains further attributes.  These are documented below.
92  *
93  *  @see
94  *
95  *  @link class_type class @endlink, @link struct_type struct @endlink,
96  *  @link method_type method @endlink, @link union_type union @endlink,
97  *  @link array_type array @endlink, @link enumeration_type enumeration @endlink,
98  *  @link pointer_type pointer @endlink, @link primitive_type primitive @endlink
99  *
100  *  @todo
101  *      mode maybe not global field??
102  */
103 #ifndef _IR_TYPE_TYPEDEF_
104 #define _IR_TYPE_TYPEDEF_
105 typedef struct ir_type ir_type;
106 #endif
107
108 # include "type_or_entity.h"
109
110 /** frees all entities associated with a type.
111     Does not free array entity.
112     Warning: make sure these entities are not referenced anywhere else.
113 */
114 void        free_type_entities(ir_type *tp);
115
116 /** Frees the memory used by the type.
117  *
118  * Removes the type from the type list. Does not free the entities
119  * belonging to the type, except for the array element entity.  Does
120  * not free if tp is "none" or "unknown".  Frees entities in value
121  * param subtypes of method types!!! Make sure these are not
122  * referenced any more.  Further make sure there is no pointer type
123  * that refers to this type.                           */
124 void        free_type(ir_type *tp);
125
126 const tp_op*get_type_tpop(const ir_type *tp);
127 ident*      get_type_tpop_nameid(const ir_type *tp);
128 const char* get_type_tpop_name(const ir_type *tp);
129 tp_opcode   get_type_tpop_code(const ir_type *tp);
130
131 ident*      get_type_ident(const ir_type *tp);
132 void        set_type_ident(ir_type *tp, ident* id);
133 const char* get_type_name(const ir_type *tp);
134
135 /** This enumeration flags the visibility of entities and types.
136  *
137  * This is necessary for partial compilation.
138  * We rely on the ordering of the flags.
139  */
140 typedef enum {
141   visibility_local,              /**< The entity is only visible locally.  This is the default for
142                                       entities.
143                                       The type is only visible locally.  All instances are allocated
144                                       locally, and no pointer to entities of this type are passed
145                                       out of this compilation unit. */
146   visibility_external_visible,   /**< The entity is visible to other external program parts, but
147                                       it is defined here.  It may not be optimized away.  The entity must
148                                       be static_allocated.
149                                       For types:  entities of this type can be accessed externally.  No
150                                       instances of this type are allocated externally.  */
151   visibility_external_allocated  /**< The entity is defined and allocated externally.  This compilation
152                                       must not allocate memory for this entity. The entity must
153                                       be static_allocated.  This can also be an external defined
154                                       method.
155                                       For types:  entities of this type are allocated and accessed from
156                                       external code.  Default for types.  */
157 } visibility;
158
159 /** The visibility of a type.
160  *
161  *  The visibility of a type indicates, whether entities of this type
162  *  are accessed or allocated in external code.
163  *
164  *  An entity of a type is allocated in external code, if the external
165  *  code declares a variable of this type, or dynamically allocates
166  *  an entity of this type.  If the external code declares a (compound)
167  *  type, that contains entities of this type, the visibility also
168  *  must be external_allocated.
169  *
170  *  The visibility must be higher than that of all entities, if the
171  *  type is a compound.  Here it is questionable, what happens with
172  *  static entities.  If these are accessed external by direct reference,
173  *  (a static call to a method, that is also in the dispatch table)
174  *  it should not affect the visibility of the type.
175  *
176  *
177  * @@@ Do we need a visibility for types?
178  * I change the layout of types radically when doing type splitting.
179  * I need to know, which fields of classes are accessed in the RTS,
180  * e.g., [_length.  I may not move [_length to the split part.
181  * The layout though, is a property of the type.
182  *
183  * One could also think of changing the mode of a type ...
184  *
185  * But, we could also output macros to access the fields, e.g.,
186  *  ACCESS_[_length (X)   X->length              // conventional
187  *  ACCESS_[_length (X)   X->_split_ref->length  // with type splitting
188  *
189  * For now I implement this function, that returns the visibility
190  * based on the visibility of the entities of a compound ...
191  *
192  * This function returns visibility_external_visible if one or more
193  * entities of a compound type have visibility_external_visible.
194  * Entities of types are never visibility_external_allocated (right?).
195  * Else returns visibility_local.
196  */
197 visibility get_type_visibility (const ir_type *tp);
198 void       set_type_visibility (ir_type *tp, visibility v);
199
200
201
202 /** The state of the type layout. */
203 typedef enum {
204   layout_undefined,    /**< The layout of this type is not defined.
205               Address computation to access fields is not
206               possible, fields must be accessed by Sel
207               nodes.  This is the default value except for
208               pointer, primitive and method types. */
209   layout_fixed         /**< The layout is fixed, all component/member entities
210               have an offset assigned.  Size of the type is known.
211               Arrays can be accessed by explicit address
212               computation. Default for pointer, primitive and method
213               types.  */
214 } type_state;
215
216 /** Returns a human readable string for the enum entry. */
217 const char *get_type_state_name(type_state s);
218
219 /** Returns the type layout state of a type. */
220 type_state  get_type_state(const ir_type *tp);
221
222 /** Sets the type layout state of a type.
223  *
224  * For primitives, pointer and method types the layout is always fixed.
225  * This call is legal but has no effect.
226  */
227 void        set_type_state(ir_type *tp, type_state state);
228
229 /** Returns the mode of a type.
230  *
231  * Returns NULL for all non atomic types.
232  */
233 ir_mode*    get_type_mode(const ir_type *tp);
234
235 /** Sets the mode of a type.
236  *
237  * Only has an effect on primitive, enumeration and pointer types.
238  */
239 void        set_type_mode(ir_type *tp, ir_mode* m);
240
241 /** Returns the size of a type in bytes, returns -1 if the size is NOT
242  *  a byte size, i.e. not dividable by 8. */
243 int         get_type_size_bytes(const ir_type *tp);
244
245 /** Returns the size of a type in bits. */
246 int         get_type_size_bits(const ir_type *tp);
247
248 /** Sets the size of a type in bytes.
249  *
250  * For primitive, enumeration, pointer and method types the size
251  * is always fixed. This call is legal but has no effect.
252  */
253 void        set_type_size_bytes(ir_type *tp, int size);
254
255 /** Sets the size of a type in bits.
256  *
257  * For primitive, enumeration, pointer and method types the size
258  * is always fixed. This call is legal but has no effect.
259  */
260 void        set_type_size_bits(ir_type *tp, int size);
261
262 /** Returns the alignment of a type in bytes.
263  *
264  *  Returns -1 if the alignment is NOT
265  *  a byte size, i.e. not dividable by 8. Calls get_type_alignment_bits(). */
266 int         get_type_alignment_bytes(ir_type *tp);
267
268 /** Returns the alignment of a type in bits.
269  *
270  *  If the alignment of a type is
271  *  not set, it is calculated here according to the following rules:
272  *  -#.) if a type has a mode, the alignment is the mode size.
273  *  -#.) compound types have the alignment of there biggest member.
274  *  -#.) array types have the alignment of there element type.
275  *  -#.) method types return 0 here.
276  *  -#.) all other types return 8 here (i.e. aligned at byte).
277  */
278 int         get_type_alignment_bits(ir_type *tp);
279
280 /** Sets the alignment of a type in bytes. */
281 void        set_type_alignment_bytes(ir_type *tp, int size);
282
283 /** Sets the alignment of a type in bits.
284  *
285  * For method types the alignment is always fixed.
286  * This call is legal but has no effect.
287  */
288 void        set_type_alignment_bits(ir_type *tp, int size);
289
290 unsigned long get_type_visited(const ir_type *tp);
291 void          set_type_visited(ir_type *tp, unsigned long num);
292 /* Sets visited field in type to type_visited. */
293 void          mark_type_visited(ir_type *tp);
294 int           type_visited(const ir_type *tp);
295 int           type_not_visited(const ir_type *tp);
296
297 /** Returns the associated link field of a type. */
298 void*         get_type_link(const ir_type *tp);
299 /** Sets the associated link field of a type. */
300 void          set_type_link(ir_type *tp, void *l);
301
302 /**
303  * Visited flag to traverse the type information.
304  *
305  * Increase this flag by one before traversing the type information
306  * using inc_master_type_visited().
307  * Mark type nodes as visited by mark_type_visited(ir_type).
308  * Check whether node was already visited by type_visited(ir_type)
309  * and type_not_visited(ir_type).
310  * Or use the function to walk all types.
311  *
312  * @see  typewalk
313  */
314 void          set_master_type_visited(unsigned long val);
315 unsigned long get_master_type_visited(void);
316 void          inc_master_type_visited(void);
317
318 /**
319  * Checks whether a pointer points to a type.
320  *
321  * @param thing     an arbitrary pointer
322  *
323  * @return
324  *     true if the thing is a type, else false
325  */
326 int is_type  (const void *thing);
327
328 /**
329  *   Checks whether two types are structurally equal.
330  *
331  *   @param typ1  the first type
332  *   @param typ2  the second type
333  *
334  *   @return
335  *    true if the types are equal, else false.
336  *
337  *   Types are equal if :
338  *    - they are the same type kind
339  *    - they have the same name
340  *    - they have the same mode (if applicable)
341  *    - they have the same type_state and, ev., the same size
342  *    - they are class types and have:
343  *      - the same members (see same_entity in entity.h)
344  *      - the same supertypes -- the C-pointers are compared --> no recursive call.
345  *      - the same number of subtypes.  Subtypes are not compared,
346  *        as this could cause a cyclic test.
347  *      - the same peculiarity
348  *    - they are structure types and have the same members
349  *    - they are method types and have
350  *      - the same parameter types
351  *      - the same result types
352  *    - they are union types and have the same members
353  *    - they are array types and have
354  *      - the same number of dimensions
355  *      - the same dimension bounds
356  *      - the same dimension order
357  *      - the same element type
358  *    - they are enumeration types and have the same enumerator names
359  *    - they are pointer types and have the identical points_to type
360  *      (i.e., the same C-struct to represent the type, type_id is skipped.
361  *       This is to avoid endless recursions; with pointer types cyclic
362  *       type graphs are possible.)
363  */
364 int equal_type(ir_type *typ1, ir_type *typ2);
365
366 /**
367  *   Checks whether two types are structural comparable.
368  *
369  *   @param st pointer type
370  *   @param lt pointer type
371  *
372  *   @return
373  *    true if type st is smaller than type lt, i.e. whenever
374  *    lt is expected a st can be used.
375  *    This is true if
376  *    - they are the same type kind
377  *    - mode(st) < mode (lt)  (if applicable)
378  *    - they are class types and st is (transitive) subtype of lt,
379  *    - they are structure types and
380  *       - the members of st have exactly one counterpart in lt with the same name,
381  *       - the counterpart has a bigger type.
382  *    - they are method types and have
383  *      - the same number of parameter and result types,
384  *      - the parameter types of st are smaller than those of lt,
385  *      - the result types of st are smaller than those of lt
386  *    - they are union types and have the members of st have exactly one
387  *      @return counterpart in lt and the type is smaller
388  *    - they are array types and have
389  *      - the same number of dimensions
390  *      - all bounds of lt are bound of st
391  *      - the same dimension order
392  *      - the same element type
393  *      @return or
394  *      - the element type of st is smaller than that of lt
395  *      - the element types have the same size and fixed layout.
396  *    - they are enumeration types and have the same enumerator names
397  *    - they are pointer types and have the points_to type of st is
398  *      @return smaller than the points_to type of lt.
399  *
400  */
401 int smaller_type (ir_type *st, ir_type *lt);
402
403 /**
404  *  @page class_type    Representation of a class type
405  *
406  *  If the type opcode is set to type_class the type represents class
407  *  types.  A list of fields and methods is associated with a class.
408  *  Further a class can inherit from and bequest to other classes.
409  *
410  *  The following attributes are private to this type kind:
411  *  - member:     All entities belonging to this class.  This are method entities
412  *                which have type_method or fields that can have any of the
413  *                following type kinds: type_class, type_struct, type_union,
414  *                type_array, type_enumeration, type_pointer, type_primitive.
415  *
416  *  The following two are dynamic lists that can be grown with an "add_" function,
417  *  but not shrinked:
418  *
419  *  - subtypes:    A list of direct subclasses.
420  *
421  *  - supertypes:  A list of direct superclasses.
422  *
423  *  - peculiarity: The peculiarity of this class.  If the class is of peculiarity
424  *                 "description" it only is a description of requirements to a class,
425  *                 as, e.g., a Java interface.  The class will never be allocated.
426  *                 Peculiarity inherited is only possible for entities.  An entity
427  *                 is of peculiarity inherited if the compiler generated the entity
428  *                 to explicitly resolve inheritance.  An inherited method entity has
429  *                 no value for irg.
430  *                 Values: description, existent, inherited.  Default: existent.
431  *
432  *  - type_info:   An entity representing the type information of this class.
433  *                 This entity can be of arbitrari type, Firm did not use it yet.
434  *                 It allows to express the coupling of a type with an entity
435  *                 representing this type.  This information is useful for lowering
436  *                 of InstOf and TypeChk nodes.  Default: NULL
437  *
438  *  - vtable_size: The size of this class virtual function table.
439  *                 Default:  0
440  *
441  *  - final:       A final class is always a leaf in the class hierarchy.  Final
442  *                 classes cannot be super classes of other ones.  As this information
443  *                 can only be computed in whole world compilations, we allow to
444  *                 set this flag.  It is used in optimizations if get_opt_closed_world()
445  *                 is false.  Default:  false
446  *
447  *  - interface:   The class represents an interface.  This flag can be set to distinguish
448  *                 between interfaces, abstract classes and other classes that all may
449  *                 have the peculiarity peculiarity_description.  Depending on this flag
450  *                 the lowering might do different actions.  Default:  false
451  *
452  *  - abstract :   The class represents an abstract class.  This flag can be set to distinguish
453  *                 between interfaces, abstract classes and other classes that all may
454  *                 have the peculiarity peculiarity_description.  Depending on this flag
455  *                 the lowering might do different actions.  Default:  false
456  */
457
458 /** Creates a new class type. */
459 ir_type *new_type_class (ident *name);
460
461 /** Creates a new class type with debug information. */
462 ir_type *new_d_type_class (ident *name, dbg_info *db);
463
464 /* --- manipulate private fields of class type  --- */
465
466 /** Adds the entity as member of the class.  */
467 void    add_class_member   (ir_type *clss, entity *member);
468
469 /** Returns the number of members of this class. */
470 int     get_class_n_members (const ir_type *clss);
471
472 /** Returns the member at position pos, 0 <= pos < n_member */
473 entity *get_class_member   (const ir_type *clss, int pos);
474
475 /** Returns index of mem in clss, -1 if not contained. */
476 int     get_class_member_index(const ir_type *clss, entity *mem);
477
478 /** Finds the member with name 'name'. If several members with the same
479  *  name returns one of them.  Returns NULL if no member found. */
480 entity *get_class_member_by_name(ir_type *clss, ident *name);
481
482 /** Overwrites the member at position pos, 0 <= pos < n_member with
483  *  the passed entity. */
484 void    set_class_member   (ir_type *clss, entity *member, int pos);
485
486 /** Replaces complete member list in class type by the list passed.
487  *
488  *  Copies the list passed. This function is necessary to reduce the number of members.
489  *  members is an array of entities, num the size of this array.  Sets all
490  *  owners of the members passed to clss. */
491 void    set_class_members  (ir_type *clss, entity *members[], int arity);
492
493 /** Finds member in the list of members and removes it.
494  *
495  *  Shrinks the member list, so iterate from the end!!!
496  *  Does not deallocate the entity.  */
497 void    remove_class_member(ir_type *clss, entity *member);
498
499
500 /** Adds subtype as subtype to clss.
501  *
502  *  Checks whether clss is a supertype of subtype.  If not
503  *  adds also clss as supertype to subtype.  */
504 void    add_class_subtype   (ir_type *clss, ir_type *subtype);
505
506 /** Returns the number of subtypes */
507 int     get_class_n_subtypes (const ir_type *clss);
508
509 /** Gets the subtype at position pos, 0 <= pos < n_subtype. */
510 ir_type *get_class_subtype   (ir_type *clss, int pos);
511
512 /** Returns the index to access subclass as subtype of class.
513  *
514  *  If subclass is no direct subtype of class returns -1.
515  */
516 int get_class_subtype_index(ir_type *clss, const ir_type *subclass);
517
518 /** Sets the subtype at position pos, 0 <= pos < n_subtype.
519  *
520  *  Does not set the corresponding supertype relation for subtype: this might
521  *  be a different position! */
522 void    set_class_subtype   (ir_type *clss, ir_type *subtype, int pos);
523
524 /** Finds subtype in the list of subtypes and removes it  */
525 void    remove_class_subtype(ir_type *clss, ir_type *subtype);
526
527 /* Convenience macros */
528 #define add_class_derived_type(clss, drvtype)       add_class_subtype(clss, drvtype)
529 #define get_class_n_derived_types(clss)             get_class_n_subtypes(clss)
530 #define get_class_derived_type(clss, pos)           get_class_subtype(clss, pos)
531 #define get_class_derived_type_index(clss, drvtype) get_class_subtype_index(clss, drvtype)
532 #define set_class_derived_type(clss, drvtype, pos)  set_class_subtype(clss, drvtype, pos)
533 #define remove_class_derived_type(clss, drvtype)    remove_class_subtype(clss, drvtype)
534
535 /** Adds supertype as supertype to class.
536  *
537  *  Checks whether clss is a subtype of supertype.  If not
538  *  adds also clss as subtype to supertype.  */
539 void    add_class_supertype   (ir_type *clss, ir_type *supertype);
540
541 /** Returns the number of supertypes */
542 int     get_class_n_supertypes (const ir_type *clss);
543
544 /** Returns the index to access superclass as supertype of class.
545  *
546  *  If superclass is no direct supertype of class returns -1.
547  */
548 int     get_class_supertype_index(ir_type *clss, ir_type *super_clss);
549
550 /** Gets the supertype at position pos,  0 <= pos < n_supertype. */
551 ir_type *get_class_supertype   (ir_type *clss, int pos);
552
553 /** Sets the supertype at position pos, 0 <= pos < n_supertype.
554  *
555  *  Does not set the corresponding subtype relation for supertype: this might
556  *  be at a different position! */
557 void    set_class_supertype   (ir_type *clss, ir_type *supertype, int pos);
558
559 /** Finds supertype in the list of supertypes and removes it */
560 void    remove_class_supertype(ir_type *clss, ir_type *supertype);
561
562 /** Convenience macro */
563 #define add_class_base_type(clss, basetype)  add_class_supertype(clss, basetype)
564 #define get_class_n_base_types(clss)  get_class_n_supertypes(clss)
565 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
566 #define get_class_base_type(clss, pos)  get_class_supertype(clss, pos)
567 #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos)
568 #define remove_class_base_type(clss, basetype)  remove_class_supertype(clss, basetype)
569
570 /** Convenience macro */
571 #define add_class_base_type(clss, basetype)        add_class_supertype(clss, basetype)
572 #define get_class_n_base_types(clss)               get_class_n_supertypes(clss)
573 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
574 #define get_class_base_type(clss, pos)             get_class_supertype(clss, pos)
575 #define set_class_base_type(clss, basetype, pos)   set_class_supertype(clss, basetype, pos)
576 #define remove_class_base_type(clss, basetype)     remove_class_supertype(clss, basetype)
577
578 /** This enumeration flags the peculiarity of entities and types. */
579 typedef enum peculiarity {
580   peculiarity_description,     /**< Represents only a description.  The entity/type is never
581                             allocated, no code/data exists for this entity/type.
582                         @@@ eventually rename to descriptive (adjective as the others!)*/
583   peculiarity_inherited,       /**< Describes explicitly that other entities are
584                             inherited to the owner of this entity.
585                             Overwrites must refer to at least one other
586                             entity.  If this is a method entity there exists
587                             no irg for this entity, only for one of the
588                             overwritten ones.
589                         Only for entity. */
590   peculiarity_existent         /**< The entity/type (can) exist.
591                     @@@ eventually rename to 'real' i.e., 'echt'
592                         This serves better as opposition to description _and_ inherited.*/
593 } peculiarity;
594
595 /** Returns a human readable string for a peculiarity. */
596 const char *get_peculiarity_name(peculiarity p);
597
598 /** Returns the peculiarity of the class. */
599 peculiarity get_class_peculiarity (const ir_type *clss);
600 /** Sets the peculiarity of the class. */
601 void        set_class_peculiarity (ir_type *clss, peculiarity pec);
602
603 /** Returns the type info entity of a class. */
604 entity *get_class_type_info(const ir_type *clss);
605
606 /** Set a type info entity for the class. */
607 void set_class_type_info(ir_type *clss, entity *ent);
608
609 /** Returns the size of the virtual function table. */
610 unsigned get_class_vtable_size(const ir_type *clss);
611
612 /** Sets a new size of the virtual function table. */
613 void set_class_vtable_size(ir_type *clss, unsigned size);
614
615 /** Returns non-zero if a class is final. */
616 int is_class_final(const ir_type *clss);
617
618 /** Sets the class final flag. */
619 void set_class_final(ir_type *clss, int flag);
620
621 /** Return non-zero if a class is an interface */
622 int is_class_interface(const ir_type *clss);
623
624 /** Sets the class interface flag. */
625 void set_class_interface(ir_type *clss, int flag);
626
627 /** Return non-zero if a class is an abstract class. */
628 int is_class_abstract(const ir_type *clss);
629
630 /** Sets the class abstract flag. */
631 void set_class_abstract(ir_type *clss, int flag);
632
633 /** Set and get a class' dfn --
634    @todo This is an undocumented field, subject to change! */
635 void set_class_dfn (ir_type *clss, int dfn);
636 int  get_class_dfn (const ir_type *clss);
637
638 /** Returns true if a type is a class type. */
639 int is_Class_type(const ir_type *clss);
640
641 /**
642  *  @page struct_type   Representation of a struct type
643  *
644  *  A struct type represents aggregate types that consist of a list
645  *  of fields.
646  *
647  *  The following attributes are private to this type kind:
648  *  - member:  All entities belonging to this class.  This are the fields
649  *             that can have any of the following types:  type_class,
650  *             type_struct, type_union, type_array, type_enumeration,
651  *             type_pointer, type_primitive.
652  *             This is a dynamic list that can be grown with an "add_" function,
653  *             but not shrinked.
654  *             This is a dynamic list that can be grown with an "add_" function,
655  *             but not shrinked.
656  */
657 /** Creates a new type struct */
658 ir_type *new_type_struct (ident *name);
659 /** Creates a new type struct with debug information. */
660 ir_type *new_d_type_struct (ident *name, dbg_info* db);
661
662 /* --- manipulate private fields of struct --- */
663
664 /** Adds the entity as member of the struct.  */
665 void    add_struct_member   (ir_type *strct, entity *member);
666
667 /** Returns the number of members of this struct. */
668 int     get_struct_n_members (const ir_type *strct);
669
670 /** Returns the member at position pos, 0 <= pos < n_member */
671 entity *get_struct_member   (const ir_type *strct, int pos);
672
673 /** Returns index of member in strct, -1 if not contained. */
674 int     get_struct_member_index(const ir_type *strct, entity *member);
675
676 /** Overwrites the member at position pos, 0 <= pos < n_member with
677    the passed entity. */
678 void    set_struct_member   (ir_type *strct, int pos, entity *member);
679
680 /** Finds member in the list of members and removes it. */
681 void    remove_struct_member (ir_type *strct, entity *member);
682
683 /** Returns true if a type is a struct type. */
684 int     is_Struct_type(const ir_type *strct);
685
686 /**
687  * @page method_type    Representation of a method type
688  *
689  * A method type represents a method, function or procedure type.
690  * It contains a list of the parameter and result types, as these
691  * are part of the type description.  These lists should not
692  * be changed by a optimization, as a change creates a new method
693  * type.  Therefore optimizations should allocated new method types.
694  * The set_ routines are only for construction by a frontend.
695  *
696  * - n_params:   Number of parameters to the procedure.
697  *               A procedure in FIRM has only call by value parameters.
698  *
699  * - param_type: A list with the types of parameters.  This list is ordered.
700  *               The nth type in this list corresponds to the nth element
701  *               in the parameter tuple that is a result of the start node.
702  *               (See ircons.h for more information.)
703  *
704  * - value_param_ents
705  *               A list of entities (whose owner is a struct private to the
706  *               method type) that represent parameters passed by value.
707  *
708  * - n_res:      The number of results of the method.  In general, procedures
709  *               have zero results, functions one.
710  *
711  * - res_type:   A list with the types of parameters.  This list is ordered.
712  *               The nth type in this list corresponds to the nth input to
713  *               Return nodes.  (See ircons.h for more information.)
714  *
715  * - value_res_ents
716  *               A list of entities (whose owner is a struct private to the
717  *               method type) that represent results passed by value.
718  */
719
720 /* These macros define the suffixes for the types and entities used
721    to represent value parameters / results. */
722 #define VALUE_PARAMS_SUFFIX  "val_param"
723 #define VALUE_RESS_SUFFIX    "val_res"
724
725 /** Create a new method type.
726  *
727  * @param name      the name (ident) of this type
728  * @param n_param   the number of parameters
729  * @param n_res     the number of results
730  *
731  * The arrays for the parameter and result types are not initialized by
732  * the constructor.
733  */
734 ir_type *new_type_method (ident *name, int n_param, int n_res);
735
736 /** Create a new method type with debug information.
737  *
738  * @param name      the name (ident) of this type
739  * @param n_param   the number of parameters
740  * @param n_res     the number of results
741  * @param db        user defined debug information
742  *
743  * The arrays for the parameter and result types are not initialized by
744  * the constructor.
745  */
746 ir_type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db);
747
748 /* -- manipulate private fields of method. -- */
749
750 /** Returns the number of parameters of this method. */
751 int   get_method_n_params  (const ir_type *method);
752
753 /** Returns the type of the parameter at position pos of a method. */
754 ir_type *get_method_param_type(ir_type *method, int pos);
755 /** Sets the type of the parameter at position pos of a method.
756     Also changes the type in the pass-by-value representation by just
757     changing the type of the corresponding entity if the representation is constructed. */
758 void  set_method_param_type(ir_type *method, int pos, ir_type *tp);
759 /** Returns an entity that represents the copied value argument.  Only necessary
760    for compounds passed by value. This information is constructed only on demand. */
761 entity *get_method_value_param_ent(ir_type *method, int pos);
762 /**
763  * Returns a type that represents the copied value arguments.
764  */
765 ir_type *get_method_value_param_type(const ir_type *method);
766
767 /** Returns the number of results of a method type. */
768 int   get_method_n_ress   (const ir_type *method);
769 /** Returns the return type of a method type at position pos. */
770 ir_type *get_method_res_type(ir_type *method, int pos);
771 /** Sets the type of the result at position pos of a method.
772     Also changes the type in the pass-by-value representation by just
773     changing the type of the corresponding entity if the representation is constructed. */
774 void  set_method_res_type(ir_type *method, int pos, ir_type *tp);
775 /** Returns an entity that represents the copied value result.  Only necessary
776    for compounds passed by value. This information is constructed only on demand. */
777 entity *get_method_value_res_ent(ir_type *method, int pos);
778
779 /**
780  * Returns a type that represents the copied value results.
781  */
782 ir_type *get_method_value_res_type(const ir_type *method);
783
784 /**
785  * This enum flags the variadicity of methods (methods with a
786  * variable amount of arguments (e.g. C's printf). Default is
787  * non_variadic.
788  */
789 typedef enum variadicity {
790   variadicity_non_variadic, /**< non variadic */
791   variadicity_variadic      /**< variadic */
792 } variadicity;
793
794 /** Returns the null-terminated name of this variadicity. */
795 const char *get_variadicity_name(variadicity vari);
796
797 /** Returns the variadicity of a method. */
798 variadicity get_method_variadicity(const ir_type *method);
799
800 /** Sets the variadicity of a method. */
801 void set_method_variadicity(ir_type *method, variadicity vari);
802
803 /**
804  * Returns the first variadic parameter index of a type.
805  * If this index was NOT set, the index of the last parameter
806  * of the method type plus one is returned for variadic functions.
807  * Non-variadic function types always return -1 here.
808  */
809 int get_method_first_variadic_param_index(const ir_type *method);
810
811 /**
812  * Sets the first variadic parameter index. This allows to specify
813  * a complete call type (containing the type of all parameters)
814  * but still have the knowledge, which parameter must be passed as
815  * variadic one.
816  */
817 void set_method_first_variadic_param_index(ir_type *method, int index);
818
819 /**
820  * Additional method type properties:
821  * Tell about special properties of a method type. Some
822  * of these may be discovered by analyses.
823  */
824 typedef enum {
825   mtp_no_property        = 0x00000000, /**< no additional properties, default */
826   mtp_property_const     = 0x00000001, /**< This method did not access memory and calculates
827                                          its return values solely from its parameters.
828                                          GCC: __attribute__((const)). */
829   mtp_property_pure      = 0x00000002, /**< This method did NOT write to memory and calculates
830                                          its return values solely from its parameters and
831                                          the memory they points to (or global vars).
832                                          GCC: __attribute__((pure)). */
833   mtp_property_noreturn  = 0x00000004, /**< This method did not return due to an aborting system
834                                          call.
835                                          GCC: __attribute__((noreturn)). */
836   mtp_property_nothrow   = 0x00000008, /**< This method cannot throw an exception.
837                                          GCC: __attribute__((nothrow)). */
838   mtp_property_naked     = 0x00000010, /**< This method is naked.
839                                          GCC: __attribute__((naked)). */
840   mtp_property_malloc    = 0x00000020, /**< This method returns newly allocate memory.
841                                          GCC: __attribute__((malloc)). */
842   mtp_property_intrinsic = 0x00000040, /**< This method is intrinsic. It is expected that
843                                          a lowering phase will remove all calls to it. */
844   mtp_property_inherited = (1<<31)     /**< Internal. Used only in irg's, means property is
845                                          inherited from type. */
846 } mtp_additional_property;
847
848 /** Returns the mask of the additional graph properties. */
849 unsigned get_method_additional_properties(const ir_type *method);
850
851 /** Sets the mask of the additional graph properties. */
852 void set_method_additional_properties(ir_type *method, unsigned property_mask);
853
854 /** Sets one additional graph property. */
855 void set_method_additional_property(ir_type *method, mtp_additional_property flag);
856
857 /**
858  * Calling conventions: lower 24 bits are the number of register parameters,
859  * upper 8 encode the calling conventions.
860  */
861 typedef enum {
862   cc_reg_param        = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
863                                          This flag may be set as default on some architectures. */
864   cc_last_on_top      = 0x02000000, /**< The last non-register parameter is transmitted on top of
865                                          the stack. This is equivalent to the pascal
866                                          calling convention. If this flag is not set, the first
867                                          non-register parameter is used (stdcall or cdecl
868                                          calling convention) */
869   cc_callee_clear_stk = 0x04000000, /**< The callee clears the stack. This forbids variadic
870                                          function calls (stdcall). */
871   cc_this_call        = 0x08000000, /**< The first parameter is a this pointer and is transmitted
872                                          in a special way. */
873
874   cc_bits             = (0xFF << 24)  /**< the calling convention bits */
875 } calling_convention;
876
877 /* some often used cases: made as defines because firmjni cannot handle two
878    equal enum values. */
879
880 /** cdecl calling convention */
881 #define cc_cdecl_set    (0)
882 /** stdcall calling convention */
883 #define cc_stdcall_set  cc_callee_clear_stk
884 /** fastcall calling convention */
885 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
886
887 /** Returns the default calling convention for method types. */
888 unsigned get_default_cc_mask(void);
889
890 /**
891  * check for the CDECL calling convention
892  */
893 #define IS_CDECL(cc_mask)     (((cc_mask) & cc_bits) == cc_cdecl_set)
894
895 /**
896  * check for the STDCALL calling convention
897  */
898 #define IS_STDCALL(cc_mask)   (((cc_mask) & cc_bits) == cc_stdcall_set)
899
900 /**
901  * check for the FASTCALL calling convention
902  */
903 #define IS_FASTCALL(cc_mask)  (((cc_mask) & cc_bits) == cc_fastcall_set)
904
905 /**
906  * Sets the CDECL convention bits.
907  */
908 #define SET_CDECL(cc_mask)    (((cc_mask) & ~cc_bits) | cc_cdecl_set)
909
910 /**
911  * Set. the STDCALL convention bits.
912  */
913 #define SET_STDCALL(cc_mask)  (((cc_mask) & ~cc_bits) | cc_stdcall_set)
914
915 /**
916  * Sets the FASTCALL convention bits.
917  */
918 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
919
920 /** Returns the calling convention of an entities graph. */
921 unsigned get_method_calling_convention(const ir_type *method);
922
923 /** Sets the calling convention of an entities graph. */
924 void set_method_calling_convention(ir_type *method, unsigned cc_mask);
925
926 /** Returns the number of registers parameters, 0 means default. */
927 unsigned get_method_n_regparams(ir_type *method);
928
929 /** Sets the number of registers parameters, 0 means default. */
930 void set_method_n_regparams(ir_type *method, unsigned n_regs);
931
932 /** Returns true if a type is a method type. */
933 int   is_Method_type     (const ir_type *method);
934
935 /**
936  *   @page union_type   Representation of a union (variant) type.
937  *
938  *   The union type represents union types.  Note that this representation
939  *   resembles the C union type.  For tagged variant types like in Pascal or Modula
940  *   a combination of a struct and a union type must be used.
941  *
942  *   - n_types:     Number of unioned types.
943  *   - members:     Entities for unioned types.  Fixed length array.
944  *                  This is a dynamic list that can be grown with an "add_" function,
945  *                  but not shrinked.
946  */
947 /** Creates a new type union. */
948 ir_type   *new_type_union (ident *name);
949
950 /** Creates a new type union with debug information. */
951 ir_type   *new_d_type_union (ident *name, dbg_info* db);
952
953 /* --- manipulate private fields of struct --- */
954
955 /** Returns the number of unioned types of this union */
956 int     get_union_n_members      (const ir_type *uni);
957
958 /** Adds a new entity to a union type */
959 void    add_union_member (ir_type *uni, entity *member);
960
961 /** Returns the entity at position pos of a union */
962 entity *get_union_member (const ir_type *uni, int pos);
963
964 /** Returns index of member in uni, -1 if not contained. */
965 int     get_union_member_index(const ir_type *uni, entity *member);
966
967 /** Overwrites a entity at position pos in a union type. */
968 void    set_union_member (ir_type *uni, int pos, entity *member);
969
970 /** Finds member in the list of members and removes it. */
971 void    remove_union_member (ir_type *uni, entity *member);
972
973 /** Returns true if a type is a union type. */
974 int     is_Union_type          (const ir_type *uni);
975
976 /**
977  * @page array_type Representation of an array type
978  *
979  * The array type represents rectangular multi dimensional arrays.
980  * The constants representing the bounds must be allocated to
981  * get_const_code_irg() by setting current_ir_graph accordingly.
982  *
983  * - n_dimensions:    Number of array dimensions.
984  * - *lower_bound:    Lower bounds of dimensions.  Usually all 0.
985  * - *upper_bound:    Upper bounds or dimensions.
986  * - *element_type:   The type of the array elements.
987  * - *element_ent:    An entity for the array elements to be used for
988  *                      element selection with Sel.
989  * @todo
990  *   Do we need several entities?  One might want
991  *   to select a dimension and not a single element in case of multi
992  *   dimensional arrays.
993  */
994
995 /** Create a new type array.
996  *
997  * Sets n_dimension to dimension and all dimension entries to NULL.
998  * Initializes order to the order of the dimensions.
999  * The entity for array elements is built automatically.
1000  * Set dimension sizes after call to constructor with set_* routines.
1001  */
1002 ir_type *new_type_array         (ident *name, int n_dimensions,
1003                   ir_type *element_type);
1004
1005 /** Create a new type array with debug information.
1006  *
1007  * Sets n_dimension to dimension and all dimension entries to NULL.
1008  * Initializes order to the order of the dimensions.
1009  * The entity for array elements is built automatically.
1010  * Set dimension sizes after call to constructor with set_* routines.
1011  * A legal array type must have at least one dimension set.
1012  */
1013 ir_type *new_d_type_array         (ident *name, int n_dimensions,
1014                   ir_type *element_type, dbg_info* db);
1015
1016 /* --- manipulate private fields of array type --- */
1017
1018 /** Returns the number of array dimensions of this type. */
1019 int   get_array_n_dimensions (const ir_type *array);
1020
1021 /**
1022  * Allocates Const nodes of mode_Is for one array dimension.
1023  * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1024  */
1025 void  set_array_bounds_int   (ir_type *array, int dimension, int lower_bound,
1026                                                           int upper_bound);
1027 /**
1028  * Sets the bounds for one array dimension.
1029  * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1030  */
1031 void  set_array_bounds       (ir_type *array, int dimension, ir_node *lower_bound,
1032                                                           ir_node *upper_bound);
1033 /** Sets the lower bound for one array dimension, i.e. [lower,upper[ */
1034 void  set_array_lower_bound  (ir_type *array, int dimension, ir_node *lower_bound);
1035
1036 /** Allocates Const nodes of mode_Is for the lower bound of an array
1037     dimension, i.e. [lower,upper[ */
1038 void  set_array_lower_bound_int (ir_type *array, int dimension, int lower_bound);
1039
1040 /** Sets the upper bound for one array dimension, i.e. [lower,upper[ */
1041 void  set_array_upper_bound  (ir_type *array, int dimension, ir_node *upper_bound);
1042
1043 /** Allocates Const nodes of mode_Is for the upper bound of an array
1044     dimension, i.e. [lower,upper[. */
1045 void  set_array_upper_bound_int (ir_type *array, int dimension, int upper_bound);
1046
1047 /** Returns true if lower bound != Unknown. */
1048 int       has_array_lower_bound     (const ir_type *array, int dimension);
1049 /** Returns the lower bound of an array. */
1050 ir_node * get_array_lower_bound     (const ir_type *array, int dimension);
1051 /** Works only if bound is Const node with tarval that can be converted to long. */
1052 long      get_array_lower_bound_int (const ir_type *array, int dimension);
1053 /** returns true if lower bound != Unknown */
1054 int       has_array_upper_bound     (const ir_type *array, int dimension);
1055 /** Returns the upper bound of an array. */
1056 ir_node * get_array_upper_bound     (const ir_type *array, int dimension);
1057 /** Works only if bound is Const node with tarval that can be converted to long. */
1058 long      get_array_upper_bound_int (const ir_type *array, int dimension);
1059
1060 /** Sets an array dimension to a specific order. */
1061 void set_array_order (ir_type *array, int dimension, int order);
1062
1063 /** Returns the order of an array dimension. */
1064 int  get_array_order (const ir_type *array, int dimension);
1065
1066 /** Find the array dimension that is placed at order ord. */
1067 int find_array_dimension(const ir_type *array, int order);
1068
1069 /** Sets the array element type. */
1070 void  set_array_element_type (ir_type *array, ir_type* tp);
1071
1072 /** Gets the array element type. */
1073 ir_type *get_array_element_type (ir_type *array);
1074
1075 /** Sets the array element entity. */
1076 void  set_array_element_entity (ir_type *array, entity *ent);
1077
1078 /** Get the array element entity. */
1079 entity *get_array_element_entity (const ir_type *array);
1080
1081 /** Returns true if a type is an array type. */
1082 int    is_Array_type(const ir_type *array);
1083
1084 /**
1085  * @page enumeration_type   Representation of an enumeration type
1086  *
1087  * Enumeration types need not necessarily be represented explicitly
1088  * by Firm types, as the frontend can lower them to integer constants as
1089  * well.  For debugging purposes or similar tasks this information is useful.
1090  *
1091  * - *enum:         The target values representing the constants used to
1092  *                  represent individual enumerations.
1093  * - *enum_nameid:  Idents containing the source program name of the enumeration
1094  *                  constants
1095  */
1096 /** Create a new type enumeration -- set the enumerators independently. */
1097 ir_type   *new_type_enumeration    (ident *name, int n_enums);
1098
1099 /** Create a new type enumeration with debug information -- set the enumerators independently. */
1100 ir_type   *new_d_type_enumeration    (ident *name, int n_enums, dbg_info *db);
1101
1102 /* --- manipulate fields of enumeration type. --- */
1103
1104 /** Returns the number of enumeration values of this enumeration */
1105 int     get_enumeration_n_enums (const ir_type *enumeration);
1106
1107 /** Sets the enumeration value at a given position. */
1108 void    set_enumeration_enum    (ir_type *enumeration, int pos, tarval *con);
1109
1110 /** Returns the enumeration value at a given position. */
1111 tarval *get_enumeration_enum    (const ir_type *enumeration, int pos);
1112
1113 /** Assign an ident to an enumeration value at a given position. */
1114 void    set_enumeration_nameid  (ir_type *enumeration, int pos, ident *id);
1115
1116 /** Returns the assigned ident of an enumeration value at a given position. */
1117 ident  *get_enumeration_nameid  (const ir_type *enumeration, int pos);
1118
1119 /** Returns the assigned name of an enumeration value at a given position. */
1120 const char *get_enumeration_name(const ir_type *enumeration, int pos);
1121
1122 /** Returns true if a type is a enumeration type. */
1123 int     is_Enumeration_type     (const ir_type *enumeration);
1124
1125 /**
1126  * @page pointer_type   Representation of a pointer type
1127  *
1128  * The mode of the pointer type must be a reference mode.
1129  *
1130  * Pointer types:
1131  * - points_to:      The type of the entity this pointer points to.
1132  */
1133
1134 /** Creates a new type pointer. */
1135 ir_type *new_type_pointer           (ident *name, ir_type *points_to, ir_mode *ptr_mode);
1136
1137 /** Creates a new type pointer with debug information. */
1138 ir_type *new_d_type_pointer         (ident *name, ir_type *points_to, ir_mode *ptr_mode, dbg_info* db);
1139
1140 /* --- manipulate fields of type_pointer --- */
1141
1142 /** Sets the type to which a pointer points to. */
1143 void  set_pointer_points_to_type (ir_type *pointer, ir_type *tp);
1144
1145 /** Returns the type to which a pointer points to. */
1146 ir_type *get_pointer_points_to_type (ir_type *pointer);
1147
1148 /** Returns true if a type is a pointer type. */
1149 int   is_Pointer_type            (const ir_type *pointer);
1150
1151 /** Returns the first pointer type that has as points_to tp.
1152  *  Not efficient: O(#types).
1153  *  If not found returns firm_unknown_type. */
1154 ir_type *find_pointer_type_to_type (ir_type *tp);
1155
1156 /**
1157  * @page primitive_type Representation of a primitive type
1158  *
1159  * Primitive types are types that represent atomic data values that
1160  * map directly to modes.  They don't have private attributes.  The
1161  * important information they carry is held in the common mode field.
1162  */
1163 /** Creates a new primitive type. */
1164 ir_type *new_type_primitive (ident *name, ir_mode *mode);
1165
1166 /** Creates a new primitive type with debug information. */
1167 ir_type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db);
1168
1169 /** Returns true if a type is a primitive type. */
1170 int  is_Primitive_type  (const ir_type *primitive);
1171
1172
1173 /**
1174  * @page none_type The None type
1175  *
1176  *  This type is an auxiliary type dedicated to support type analyses.
1177  *
1178  *  The none type represents that there is no type.  The type can be used to
1179  *  initialize fields of type* that actually can not contain a type or that
1180  *  are initialized for an analysis. There exists exactly one type none.
1181  *  This type is not on the type list in ir_prog. It is
1182  *  allocated when initializing the type module.
1183  *
1184  *  The following values are set:
1185  *    - mode:  mode_BAD
1186  *    - name:  "type_none"
1187  *    - state: layout_fixed
1188  *    - size:  0
1189  */
1190 /** A variable that contains the only none type. */
1191 extern ir_type *firm_none_type;
1192
1193 /** Returns the none type. */
1194 ir_type *get_none_type(void);
1195
1196 /**
1197  * @page unknown_type
1198  *
1199  *  This type is an auxiliary type dedicated to support type analyses.
1200  *
1201  *  The unknown type represents that there could be a type, but it is not
1202  *  known.  This type can be used to initialize fields before an analysis (not known
1203  *  yet) or to represent the top of a lattice (could not be determined).  There exists
1204  *  exactly one type unknown. This type is not on the type list in ir_prog.  It is
1205  *  allocated when initializing the type module.
1206  *
1207  *  The following values are set:
1208  *    - mode:  mode_ANY
1209  *    - name:  "type_unknown"
1210  *    - state: layout_fixed
1211  *    - size:  0
1212  */
1213 /** A variable that contains the only unknown type. */
1214 extern ir_type *firm_unknown_type;
1215
1216 /** Returns the unknown type. */
1217 ir_type *get_unknown_type(void);
1218
1219
1220 /**
1221  *  Checks whether a type is atomic.
1222  *  @param tp   any type
1223  *  @return true if type is primitive, pointer or enumeration
1224  */
1225 int is_atomic_type(const ir_type *tp);
1226
1227 /* --- Support for compound types --- */
1228
1229 /**
1230  * Gets the number of elements in a Firm compound type.
1231  *
1232  * This is just a comfortability function, because structs and
1233  * classes can often be treated be the same code, but they have
1234  * different access functions to their members.
1235  *
1236  * @param tp  The type (must be struct, union or class).
1237  *
1238  * @return Number of members in the compound type.
1239  */
1240 int get_compound_n_members(const ir_type *tp);
1241
1242 /**
1243  * Gets the member of a Firm compound type at position pos.
1244  *
1245  * @param tp  The type (must be struct, union or class).
1246  * @param pos The number of the member.
1247  *
1248  * @return The member entity at position pos.
1249  *
1250  * @see get_compound_n_members() for justification of existence.
1251  */
1252 entity *get_compound_member(const ir_type *tp, int pos);
1253
1254 /** Returns index of member in tp, -1 if not contained. */
1255 int     get_compound_member_index(const ir_type *tp, entity *member);
1256
1257 /**
1258  * Checks whether a type is a compound type.
1259  *
1260  * @param tp - any type
1261  *
1262  * @return true if the type is class, structure, union or array type.
1263  */
1264 int is_compound_type(const ir_type *tp);
1265
1266 /**
1267  * Checks, whether a type is a frame type.
1268  */
1269 int is_frame_type(const ir_type *tp);
1270
1271 /**
1272  * Checks, whether a type is a lowered type.
1273  */
1274 int is_lowered_type(const ir_type *tp);
1275
1276 /**
1277  * Makes a new frame type. Frame types are class types,
1278  * so all class access functions work.
1279  * Frame types are not in the global list of types.
1280  */
1281 ir_type *new_type_frame(ident *name);
1282
1283 /**
1284  * Sets a lowered type for a type. This sets both associations
1285  * and marks lowered_type as a "lowered" one.
1286  */
1287 void set_lowered_type(ir_type *tp, ir_type *lowered_type);
1288
1289 /**
1290  * Gets the lowered/unlowered type of a type or NULL if this type
1291  * has no lowered/unlowered one.
1292  */
1293 ir_type *get_associated_type(const ir_type *tp);
1294
1295 /**
1296  * Allocate an area of size bytes aligned at alignment
1297  * at the start or the end of a frame type.
1298  * The frame type must already have a fixed layout.
1299  *
1300  * @param frame_type a frame type
1301  * @param size       the size of the entity
1302  * @param alignment  the alignment of the entity
1303  * @param at_start   if true, put the area at the frame type's start, else at end
1304  *
1305  * @return the entity representing the area
1306  */
1307 entity *frame_alloc_area(type *frame_type, int size, int alignment, int at_start);
1308
1309 /*-----------------------------------------------------------------*/
1310 /** Debug aides                                                   **/
1311 /*-----------------------------------------------------------------*/
1312
1313 /**
1314  *  Outputs a unique number for this type if libfirm is compiled for
1315  *  debugging, (configure with --enable-debug) else returns the address
1316  *  of the type cast to long.
1317  */
1318 long get_type_nr(const ir_type *tp);
1319
1320 #endif /* _FIRM_TR_TYPE_H_ */