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