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