add a default_layout_compound_type; the backend layouts the frametype now if it hasn...
[libfirm] / include / libfirm / typerep.h
1 /*
2  * Copyright (C) 1995-2008 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
22  * @brief Declarations for functions and datastructures to represent types
23  */
24 #ifndef FIRM_TYPEREP_H
25 #define FIRM_TYPEREP_H
26
27 #include "firm_types.h"
28 #include <stdlib.h>
29
30 /**
31  * @page entity       Entity representation
32  *
33  * An entity is the representation of program known objects in Firm.
34  * The primary concept of entities is to represent members of complex
35  * types, i.e., fields and methods of classes.  As not all programming
36  * language model all variables and methods as members of some class,
37  * the concept of entities is extended to cover also local and global
38  * variables, and arbitrary procedures.
39  *
40  * An entity always specifies the type of the object it represents and
41  * the type of the object it is a part of, the owner of the entity.
42  * Originally this is the type of the class of which the entity is a
43  * member.
44  * The owner of local variables is the procedure they are defined in.
45  * The owner of global variables and procedures visible in the whole
46  * program is a universally defined class type "GlobalType".  The owner
47  * of procedures defined in the scope of an other procedure is the
48  * enclosing procedure.
49  *
50  * The type ir_entity is an abstract data type to represent program entities.
51  * If contains the following attributes:
52  *
53  *   - owner:      A compound type this entity is a part of.
54  *   - type:       The type of this entity.
55  *   - name:       The string that represents this entity in the source program.
56  *   - allocation: A flag saying whether the entity is dynamically or statically
57  *                 allocated (values: dynamic_allocated,  static_allocated,
58  *                 automatic_allocated).
59  *   - visibility: A flag indicating the visibility of this entity (values: local,
60  *                 external_visible,  external_allocated)
61  *   - variability: A flag indicating the variability of this entity (values:
62  *                  uninitialized, initialized, part_constant, constant)
63  *   - volatility: @@@
64  *   - offset:     The offset of the entity within the compound object in bytes.  Only set
65  *                 if the owner in the state "layout_fixed".
66  *   - offset_bits_remainder:   The offset bit remainder of a bitfield entity (in a compound)
67  *                 in bits.  Only set if the owner in the state "layout_fixed".
68  *   - overwrites: A list of entities overwritten by this entity.  This list is only
69  *                 existent if the owner of this entity is a class.  The members in
70  *                 this list must be entities of super classes.
71  *   - overwrittenby: A list of entities that overwrite this entity.  This list is only
72  *                 existent if the owner of this entity is a class.  The members in
73  *                 this list must be entities of sub classes.
74  *   - link:       A void* to associate some additional information with the entity.
75  *   - irg:        If the entity is a method this is the ir graph that represents the
76  *                 code of the method.
77  *   - peculiarity: The peculiarity of the entity.  If the entity is a method this
78  *                 indicates whether the entity represents
79  *                 a real method or whether it only exists to describe an interface.
80  *                 In that case there nowhere exists code for this entity and this entity
81  *                 is never dynamically used in the code.
82  *                 Values: description, existent.  Default: existent.
83  *   - visited:    visited flag.  Master flag is type_visited.
84  *
85  * These fields can only be accessed via access functions.
86  *
87  * @see  ir_type, ir_entity
88  */
89
90 /** This enumeration flags the visibility of entities and types.
91  *
92  * This is necessary for partial compilation.
93  * We rely on the ordering of the flags.
94  */
95 typedef enum {
96         visibility_local,              /**< The entity is only visible locally.  This is the default for
97                                             entities.
98                                             The type is only visible locally.  All instances are allocated
99                                             locally, and no pointer to entities of this type are passed
100                                             out of this compilation unit. */
101         visibility_external_visible,   /**< The entity is visible to other external program parts, but
102                                             it is defined here.  It may not be optimized away.  The entity must
103                                             be static_allocated.
104                                             For types:  entities of this type can be accessed externally.  No
105                                             instances of this type are allocated externally.  */
106         visibility_external_allocated  /**< The entity is defined and allocated externally.  This compilation
107                                             must not allocate memory for this entity. The entity must
108                                             be static_allocated.  This can also be an external defined
109                                             method.
110                                             For types:  entities of this type are allocated and accessed from
111                                             external code.  Default for types.  */
112 } ir_visibility;
113
114 /** This enumeration flags the peculiarity of entities and types. */
115 typedef enum {
116         peculiarity_description,     /**< Represents only a description.  The entity/type is never
117                                   allocated, no code/data exists for this entity/type.
118                               @@@ eventually rename to descriptive (adjective as the others!)*/
119         peculiarity_inherited,       /**< Describes explicitly that other entities are
120                                   inherited to the owner of this entity.
121                                   Overwrites must refer to at least one other
122                                   entity.  If this is a method entity there exists
123                                   no irg for this entity, only for one of the
124                                   overwritten ones.
125                               Only for entity. */
126         peculiarity_existent         /**< The entity/type (can) exist.
127                           @@@ eventually rename to 'real' i.e., 'echt'
128                               This serves better as opposition to description _and_ inherited.*/
129 } ir_peculiarity;
130
131 /**
132  * Creates a new entity.
133  *
134  * Automatically inserts the entity as a member of owner.
135  * Entity is automatic_allocated and uninitialized except if the type
136  * is type_method, then it is static_allocated and constant.  The constant
137  * value is a pointer to the method.
138  * Visibility is local, offset -1, and it is not volatile.
139  */
140 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp);
141
142 /**
143  * Creates a new entity.
144  *
145  * Automatically inserts the entity as a member of owner.
146  * The entity is automatic allocated and uninitialized except if the type
147  * is type_method, then it is static allocated and constant.  The constant
148  * value is a pointer to the method.
149  * Visibility is local, offset -1, and it is not volatile.
150  */
151 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp, dbg_info *db);
152
153 /**
154  * Copies the entity if the new_owner is different from the
155  * owner of the old entity,  else returns the old entity.
156  *
157  * Automatically inserts the new entity as a member of owner.
158  * Resets the overwrites/overwritten_by fields.
159  * Keeps the old atomic value.
160  *   @@@ Maybe we should change this.  If peculiarity of a method
161  *       is existent, we should add a new SymConst that points to
162  *       itself and not to the origin.  Right now we have to change
163  *       the peculiarity and then set a new atomic value by hand.
164  */
165 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner);
166
167 /**
168  * Copies the entity if the new_name is different from the
169  * name of the old entity, else returns the old entity.
170  *
171  * Automatically inserts the new entity as a member of owner.
172  * The mangled name ld_name is set to NULL.
173  * Overwrites relation is copied from old.
174  */
175 ir_entity *copy_entity_name(ir_entity *old, ident *new_name);
176
177 /**
178  * Frees the entity.
179  *
180  * The owner will still contain the pointer to this
181  * entity, as well as all other references!
182  */
183 void free_entity(ir_entity *ent);
184
185 /** Returns the name of an entity. */
186 const char *get_entity_name(const ir_entity *ent);
187
188 /** Returns the ident of an entity. */
189 ident *get_entity_ident(const ir_entity *ent);
190
191 /** Sets the ident of the entity. */
192 void set_entity_ident(ir_entity *ent, ident *id);
193
194 /** Returns the mangled name of the entity.
195  *
196  * If the mangled name is set it returns the existing name.
197  * Else it generates a name with mangle_entity()
198  * and remembers this new name internally.
199  */
200 ident *get_entity_ld_ident(ir_entity *ent);
201
202 /** Sets the mangled name of the entity. */
203 void set_entity_ld_ident(ir_entity *ent, ident *ld_ident);
204
205 /** Returns the mangled name of the entity as a string. */
206 const char *get_entity_ld_name(ir_entity *ent);
207
208 /** Returns the owner of the entity. */
209 ir_type *get_entity_owner(ir_entity *ent);
210
211 /** Sets the owner field in entity to owner.  Don't forget to add
212    ent to owner!! */
213 void set_entity_owner(ir_entity *ent, ir_type *owner);
214
215 /** Returns the type of an entity. */
216 ir_type *get_entity_type(ir_entity *ent);
217
218 /** Sets the type of an entity. */
219 void set_entity_type(ir_entity *ent, ir_type *tp);
220
221 /** The allocation type. */
222 typedef enum {
223         allocation_automatic, /**< The entity is allocated during runtime, implicitly
224                                    as component of a compound type.   This is the default. */
225         allocation_parameter, /**< The entity is a parameter.  It is also automatic allocated.
226                                    We distinguish the allocation of parameters from the allocation
227                                    of local variables as their placement depends on the calling
228                                    conventions. */
229         allocation_dynamic,   /**< The entity is allocated during runtime, explicitly
230                                    by an Alloc node. */
231         allocation_static     /**< The entity is allocated statically.  We can use a
232                                    Const as address of the entity.  This is the default for methods. */
233 } ir_allocation;
234
235 /** Returns the allocation type of an entity. */
236 ir_allocation get_entity_allocation(const ir_entity *ent);
237
238 /** Sets the allocation type of an entity. */
239 void set_entity_allocation(ir_entity *ent, ir_allocation al);
240
241 /** Return the name of the allocation type. */
242 const char *get_allocation_name(ir_allocation al);
243
244 /** Returns the visibility of an entity. */
245 ir_visibility get_entity_visibility(const ir_entity *ent);
246
247 /** Sets the visibility of an entity. */
248 void set_entity_visibility(ir_entity *ent, ir_visibility vis);
249
250 /** Return the name of the visibility */
251 const char *get_visibility_name(ir_visibility vis);
252
253 /** This enumeration flags the variability of entities. */
254 typedef enum {
255         variability_uninitialized,    /**< The content of the entity is completely unknown. Default. */
256         variability_initialized,      /**< After allocation the entity is initialized with the
257                                            value given somewhere in the entity. */
258         variability_part_constant,    /**< For entities of compound types.
259                                            The members of the entity are mixed constant,
260                                            initialized or uninitialized. */
261         variability_constant          /**< The entity is constant. */
262 } ir_variability;
263
264 /** Returns the variability of an entity. */
265 ir_variability get_entity_variability(const ir_entity *ent);
266
267 /** Sets the variability of an entity. */
268 void set_entity_variability(ir_entity *ent, ir_variability var);
269
270 /** Return the name of the variability. */
271 const char *get_variability_name(ir_variability var);
272
273 /** This enumeration flags the volatility of entities and Loads/Stores. */
274 typedef enum {
275         volatility_non_volatile,    /**< The entity is not volatile. Default. */
276         volatility_is_volatile      /**< The entity is volatile. */
277 } ir_volatility;
278
279 /** Returns the volatility of an entity. */
280 ir_volatility get_entity_volatility(const ir_entity *ent);
281
282 /** Sets the volatility of an entity. */
283 void set_entity_volatility(ir_entity *ent, ir_volatility vol);
284
285 /** Return the name of the volatility. */
286 const char *get_volatility_name(ir_volatility var);
287
288 /** Returns alignment of entity in bytes */
289 unsigned get_entity_alignment(const ir_entity *entity);
290
291 /** Sets alignment for entity in bytes */
292 void set_entity_alignment(ir_entity *entity, unsigned alignment);
293
294 /** This enumeration flags the align of Loads/Stores. */
295 typedef enum {
296         align_non_aligned,    /**< The entity is not aligned. */
297         align_is_aligned      /**< The entity is aligned. Default */
298 } ir_align;
299
300 /** Returns indication wether entity is aligned in memory. */
301 ir_align get_entity_aligned(const ir_entity *ent);
302
303 /** Sets indication wether entity is aligned in memory */
304 void set_entity_aligned(ir_entity *ent, ir_align a);
305
306 /** Return the name of the alignment. */
307 const char *get_align_name(ir_align a);
308
309 /** This enumeration flags the stickyness of an entity. */
310 typedef enum {
311         stickyness_unsticky,  /**< The entity can be removed from
312                                    the program, unless contraindicated
313                                    by other attributes. Default. */
314         stickyness_sticky     /**< The entity must remain in the
315                                    program in any case. There might be external
316                                    callers. */
317 } ir_stickyness;
318
319 /** Get the entity's stickyness. */
320 ir_stickyness get_entity_stickyness(const ir_entity *ent);
321
322 /** Set the entity's stickyness. */
323 void set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness);
324
325 /** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */
326 int get_entity_offset(const ir_entity *ent);
327
328 /** Sets the offset of an entity (in a compound) in bytes. */
329 void set_entity_offset(ir_entity *ent, int offset);
330
331 /** Returns the offset bit remainder of a bitfield entity (in a compound) in bits. Only set if layout = fixed. */
332 unsigned char get_entity_offset_bits_remainder(const ir_entity *ent);
333
334 /** Sets the offset bit remainder of a bitfield entity (in a compound) in bits. */
335 void set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset);
336
337 /** Returns the stored intermediate information. */
338 void *get_entity_link(const ir_entity *ent);
339
340 /** Stores new intermediate information. */
341 void set_entity_link(ir_entity *ent, void *l);
342
343 /* -- Fields of method entities -- */
344 /** The entity knows the corresponding irg if the entity is a method.
345    This allows to get from a Call to the called irg.
346    Only entities of peculiarity "existent" can have a corresponding irg,
347    else the field is fixed to NULL.  (Get returns NULL, set asserts.) */
348 ir_graph *get_entity_irg(const ir_entity *ent);
349 void set_entity_irg(ir_entity *ent, ir_graph *irg);
350
351 /** Gets the entity vtable number. */
352 unsigned get_entity_vtable_number(const ir_entity *ent);
353
354 /** Sets the entity vtable number. */
355 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number);
356
357 /** Return the peculiarity of an entity. */
358 ir_peculiarity get_entity_peculiarity(const ir_entity *ent);
359
360 /** Sets the peculiarity of an entity. */
361 void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec);
362
363 /** Checks if an entity cannot be overridden anymore. */
364 int is_entity_final(const ir_entity *ent);
365
366 /** Sets/resets the final flag of an entity. */
367 void set_entity_final(ir_entity *ent, int final);
368
369 /** Set label number of an entity with code type */
370 void set_entity_label(ir_entity *ent, ir_label_t label);
371 /** Return label number of an entity with code type */
372 ir_label_t get_entity_label(const ir_entity *ent);
373
374 /** Checks if an entity is compiler generated. */
375 int is_entity_compiler_generated(const ir_entity *ent);
376
377 /** Sets/resets the compiler generated flag. */
378 void set_entity_compiler_generated(ir_entity *ent, int flag);
379
380 /** Checks if an entity is marked by the backend. */
381 int is_entity_backend_marked(const ir_entity *ent);
382
383 /** Sets/resets the backend marker flag. */
384 void set_entity_backend_marked(ir_entity *ent, int flag);
385
386 /**
387  * Bitfield type indicating the way an entity is used.
388  */
389 typedef enum {
390         ir_usage_none             = 0,      /**< This entity is unused. */
391         ir_usage_address_taken    = 1 << 0, /**< The address of this entity was taken. */
392         ir_usage_write            = 1 << 1, /**< The entity was written to. */
393         ir_usage_read             = 1 << 2, /**< The entity was read. */
394         ir_usage_reinterpret_cast = 1 << 3, /**< The entity was read but with a wrong mode
395                                                  (an implicit reinterpret cast) */
396         /** Unknown access */
397         ir_usage_unknown
398                 = ir_usage_address_taken | ir_usage_write | ir_usage_read
399                 | ir_usage_reinterpret_cast
400 } ir_entity_usage;
401
402 /** Return the entity usage */
403 ir_entity_usage get_entity_usage(const ir_entity *ent);
404
405 /** Sets/resets the state of the address taken flag of an entity. */
406 void set_entity_usage(ir_entity *ent, ir_entity_usage flag);
407
408 /**
409  * Returns the debug information of an entity.
410  *
411  * @param ent The entity.
412  */
413 dbg_info *get_entity_dbg_info(const ir_entity *ent);
414
415 /**
416  * Sets the debug information of an entity.
417  *
418  * @param ent The entity.
419  * @param db  The debug info.
420  */
421 void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
422
423 /* -- Representation of constant values of entities -- */
424 /**
425  * Returns true if the the node is representable as code on
426  * const_code_irg.
427  *
428  * @deprecated This function is not used by libFirm and stays here
429  *             only as a helper for the old Jack frontend.
430  */
431 int is_irn_const_expression(ir_node *n);
432
433 /**
434  * Copies a Firm subgraph that complies to the restrictions for
435  * constant expressions to current_block in current_ir_graph.
436  *
437  * @param dbg  debug info for all newly created nodes
438  * @param n    the node
439  *
440  * Set current_ir_graph to get_const_code_irg() to generate a constant
441  * expression.
442  */
443 ir_node *copy_const_value(dbg_info *dbg, ir_node *n);
444
445 /* Set has no effect for existent entities of type method. */
446 ir_node *get_atomic_ent_value(ir_entity *ent);
447 void set_atomic_ent_value(ir_entity *ent, ir_node *val);
448
449 /** the kind (type) of an initializer */
450 typedef enum ir_initializer_kind_t {
451         /** initializer containing an ir_node from the const-code irg */
452         IR_INITIALIZER_CONST,
453         /** initializer containing a tarval */
454         IR_INITIALIZER_TARVAL,
455         /** initializes type with default values (usually 0) */
456         IR_INITIALIZER_NULL,
457         /** list of initializers used to initializer a compound or array type */
458         IR_INITIALIZER_COMPOUND
459 } ir_initializer_kind_t;
460
461 /** returns kind of an initializer */
462 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer);
463
464 /** Return the name of the initializer kind. */
465 const char *get_initializer_kind_name(ir_initializer_kind_t ini);
466
467 /**
468  * returns the null initializer (there's only one instance of it in a program )
469  */
470 ir_initializer_t *get_initializer_null(void);
471
472 /**
473  * creates an initializer containing a reference to a node on the const-code
474  * irg.
475  */
476 ir_initializer_t *create_initializer_const(ir_node *value);
477
478 /** creates an initializer containing a single tarval value */
479 ir_initializer_t *create_initializer_tarval(tarval *tv);
480
481 /** return value contained in a const initializer */
482 ir_node *get_initializer_const_value(const ir_initializer_t *initializer);
483
484 /** return value contained in a tarval initializer */
485 tarval *get_initializer_tarval_value(const ir_initializer_t *initialzier);
486
487 /** creates a compound initializer which holds @p n_entries entries */
488 ir_initializer_t *create_initializer_compound(unsigned n_entries);
489
490 /** returns the number of entries in a compound initializer */
491 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer);
492
493 /** sets entry with index @p index to the initializer @p value */
494 void set_initializer_compound_value(ir_initializer_t *initializer,
495                                     unsigned index, ir_initializer_t *value);
496
497 /** returns the value with index @p index of a compound initializer */
498 ir_initializer_t *get_initializer_compound_value(
499                 const ir_initializer_t *initializer, unsigned index);
500
501 /** Sets the new style initializers of an entity. */
502 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer);
503
504 /** Returns true, if an entity has new style initializers. */
505 int has_entity_initializer(const ir_entity *entity);
506
507 /** Return the new style initializers of an entity. */
508 ir_initializer_t *get_entity_initializer(const ir_entity *entity);
509
510 /* --- Fields of entities with a class type as owner --- */
511 /* Overwrites is a field that specifies that an access to the overwritten
512    entity in the supertype must use this entity.  It's a list as with
513    multiple inheritance several entities can be overwritten.  This field
514    is mostly useful for method entities.
515    If a Sel node selects an entity that is overwritten by other entities it
516    must return a pointer to the entity of the dynamic type of the pointer
517    that is passed to it.  Lowering of the Sel node must assure this.
518    Overwrittenby is the inverse of overwrites.  Both add routines add
519    both relations, they only differ in the order of arguments. */
520 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
521 int get_entity_n_overwrites(ir_entity *ent);
522 int get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten);
523 ir_entity *get_entity_overwrites(ir_entity *ent, int pos);
524 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten);
525 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
526
527 void add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
528 int get_entity_n_overwrittenby(ir_entity *ent);
529 int get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites);
530 ir_entity *get_entity_overwrittenby(ir_entity *ent, int pos);
531 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites);
532 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
533
534 /**
535  *   Checks whether a pointer points to an entity.
536  *
537  *   @param thing     an arbitrary pointer
538  *
539  *   @return
540  *       true if the thing is an entity, else false
541  */
542 int is_entity(const void *thing);
543
544 /** Returns true if the type of the entity is a primitive, pointer
545  * enumeration or method type.
546  *
547  * @note This is a different classification than from is_primitive_type().
548  */
549 int is_atomic_entity(ir_entity *ent);
550 /** Returns true if the type of the entity is a class, structure,
551    array or union type. */
552 int is_compound_entity(ir_entity *ent);
553 /** Returns true if the type of the entity is a Method type. */
554 int is_method_entity(ir_entity *ent);
555
556 /** Outputs a unique number for this entity if libfirm is compiled for
557  *  debugging, (configure with --enable-debug) else returns the address
558  *  of the type cast to long.
559  */
560 long get_entity_nr(const ir_entity *ent);
561
562 /** Returns the entities visited count. */
563 ir_visited_t get_entity_visited(ir_entity *ent);
564
565 /** Sets the entities visited count. */
566 void set_entity_visited(ir_entity *ent, ir_visited_t num);
567
568 /** Sets visited field in entity to entity_visited. */
569 void mark_entity_visited(ir_entity *ent);
570
571 /** Returns true if this entity was visited. */
572 int entity_visited(ir_entity *ent);
573
574 /** Returns true if this entity was not visited. */
575 int entity_not_visited(ir_entity *ent);
576
577 /**
578  * Returns the mask of the additional entity properties.
579  * The properties are automatically inherited from the irg if available
580  * or from the method type if they were not set using
581  * set_entity_additional_properties() or
582  * set_entity_additional_property().
583  */
584 unsigned get_entity_additional_properties(ir_entity *ent);
585
586 /** Sets the mask of the additional graph properties. */
587 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask);
588
589 /** Sets one additional graph property. */
590 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag);
591
592 /** Returns the class type that this type info entity represents or NULL
593     if ent is no type info entity. */
594 ir_type *get_entity_repr_class(const ir_entity *ent);
595
596 /**
597  * @page unknown_entity  The Unknown entity
598  *
599  *  This entity is an auxiliary entity dedicated to support analyses.
600  *
601  *  The unknown entity represents that there could be an entity, but it is not
602  *  known.  This entity can be used to initialize fields before an analysis (not known
603  *  yet) or to represent the top of a lattice (could not be determined).  There exists
604  *  exactly one entity unknown. This entity has as owner and as type the unknown type. It is
605  *  allocated when initializing the entity module.
606  *
607  *  The entity can take the role of any entity, also methods.  It returns default
608  *  values in these cases.
609  *
610  *  The following values are set:
611  *
612  * - name          = "unknown_entity"
613  * - ld_name       = "unknown_entity"
614  * - owner         = unknown_type
615  * - type          = unknown_type
616  * - allocation    = allocation_automatic
617  * - visibility    = visibility_external_allocated
618  * - offset        = -1
619  * - variability   = variability_uninitialized
620  * - value         = SymConst(unknown_entity)
621  * - values        = NULL
622  * - val_paths     = NULL
623  * - peculiarity   = peculiarity_existent
624  * - volatility    = volatility_non_volatile
625  * - stickyness    = stickyness_unsticky
626  * - ld_name       = NULL
627  * - overwrites    = NULL
628  * - overwrittenby = NULL
629  * - irg           = NULL
630  * - link          = NULL
631  */
632
633 /** A variable that contains the only unknown entity. */
634 extern ir_entity *unknown_entity;
635
636 /** Returns the @link unknown_entity unknown entity @endlink. */
637 ir_entity *get_unknown_entity(void);
638
639 /** Encodes how a pointer parameter is accessed. */
640 typedef enum acc_bits {
641         ptr_access_none  = 0,                                 /**< no access */
642         ptr_access_read  = 1,                                 /**< read access */
643         ptr_access_write = 2,                                 /**< write access */
644         ptr_access_rw    = ptr_access_read|ptr_access_write,  /**< read AND write access */
645         ptr_access_store = 4,                                 /**< the pointer is stored */
646         ptr_access_all   = ptr_access_rw|ptr_access_store     /**< all possible access */
647 } ptr_access_kind;
648
649 #define IS_READ(a)     ((a) & ptr_access_read)
650 #define IS_WRITTEN(a)  ((a) & ptr_access_write)
651 #define IS_STORED(a)   ((a) & ptr_access_store)
652
653 /**
654  * @page tyop  type operations
655  *  This module specifies the kinds of types available in firm.
656  *
657  *  They are called type opcodes. These include classes, structs, methods, unions,
658  *  arrays, enumerations, pointers and primitive types.
659  *  Special types with own opcodes are the id type, a type representing an unknown
660  *  type and a type used to specify that something has no type.
661  */
662
663 /**
664  *  An enum for the type kinds.
665  *  For each type kind exists a typecode to identify it.
666  */
667 typedef enum {
668         tpo_uninitialized = 0,   /* not a type opcode */
669         tpo_class,               /**< A class type. */
670         tpo_struct,              /**< A struct type. */
671         tpo_method,              /**< A method type. */
672         tpo_union,               /**< An union type. */
673         tpo_array,               /**< An array type. */
674         tpo_enumeration,         /**< An enumeration type. */
675         tpo_pointer,             /**< A pointer type. */
676         tpo_primitive,           /**< A primitive type. */
677         tpo_code,                /**< a piece of code (a basic block) */
678         tpo_none,                /**< Special type for the None type. */
679         tpo_unknown,             /**< Special code for the Unknown type. */
680         tpo_last = tpo_unknown   /* not a type opcode */
681 } tp_opcode;
682
683 /**
684  * A structure containing information about a kind of type.
685  * A structure containing information about a kind of type.  So far
686  * this is only the kind name, an enum for case-switching and some
687  * internal values.
688  *
689  * @see  get_tpop_name(), get_tpop_code()
690  */
691 typedef struct tp_op tp_op;
692
693
694 /**
695  * Returns the string for the type opcode.
696  *
697  * @param op  The type opcode to get the string from.
698  * @return a string.  (@todo Null terminated?)
699  */
700 const char *get_tpop_name(const tp_op *op);
701
702 /**
703  * Returns an enum for the type opcode.
704  *
705  * @param op   The type opcode to get the enum from.
706  * @return the enum.
707  */
708 tp_opcode get_tpop_code(const tp_op *op);
709
710 /**
711  * This type opcode marks that the corresponding type is a class type.
712  *
713  * Consequently the type refers to supertypes, subtypes and entities.
714  * Entities can be any fields, but also methods.
715  * @@@ value class or not???
716  * This struct is dynamically allocated but constant for the lifetime
717  * of the library.
718  */
719 extern const tp_op *type_class;
720 const tp_op *get_tpop_class(void);
721
722 /**
723  * This type opcode marks that the corresponding type is a compound type
724  * as a struct in C.
725  *
726  * Consequently the type refers to a list of entities
727  * which may not be methods (but pointers to methods).
728  * This struct is dynamically allocated but constant for the lifetime
729  * of the library.
730  */
731 extern const tp_op *type_struct;
732 const tp_op *get_tpop_struct(void);
733
734 /**
735  * This type opcode marks that the corresponding type is a method type.
736  *
737  * Consequently it refers to a list of arguments and results.
738  * This struct is dynamically allocated but constant for the lifetime
739  * of the library.
740  */
741 extern const tp_op *type_method;
742 const tp_op *get_tpop_method(void);
743
744 /**
745  * This type opcode marks that the corresponding type is a union type.
746  *
747  * Consequently it refers to a list of unioned types.
748  * This struct is dynamically allocated but constant for the lifetime
749  * of the library.
750  */
751 extern const tp_op *type_union;
752 const tp_op *get_tpop_union(void);
753
754 /**
755  * This type opcode marks that the corresponding type is an array type.
756  *
757  * Consequently it contains a list of dimensions (lower and upper bounds)
758  * and an element type.
759  * This struct is dynamically allocated but constant for the lifetime
760  * of the library.
761  */
762 extern const tp_op *type_array;
763 const tp_op *get_tpop_array(void);
764
765 /**
766  * This type opcode marks that the corresponding type is an enumeration type.
767  *
768  * Consequently it contains a list of idents for the enumeration identifiers
769  * and a list of target values that are the constants used to implement
770  * the enumerators.
771  * This struct is dynamically allocated but constant for the lifetime
772  * of the library.
773  */
774 extern const tp_op *type_enumeration;
775 const tp_op *get_tpop_enumeration(void);
776
777 /**
778  * This type opcode marks that the corresponding type is a pointer type.
779  *
780  * It contains a reference to the type the pointer points to.
781  * This struct is dynamically allocated but constant for the lifetime
782  * of the library.
783  */
784 extern const tp_op *type_pointer;
785 const tp_op *get_tpop_pointer(void);
786
787 /**
788  * This type opcode marks that the corresponding type is a primitive type.
789  *
790  * Primitive types are types that are directly mapped to target machine
791  * modes.
792  * This struct is dynamically allocated but constant for the lifetime
793  * of the library.
794  */
795 extern const tp_op *type_primitive;
796 const tp_op *get_tpop_primitive(void);
797
798 /**
799  * The code type is used to mark pieces of code (basic blocks)
800  */
801 extern const tp_op *tpop_code;
802 const tp_op *get_tpop_code_type(void);
803
804 /**
805  * This type opcode is an auxiliary opcode dedicated to support type analyses.
806  *
807  * Types with this opcode represents that there is no type.
808  * The type can be used to initialize fields of the type* that actually can not
809  * contain a type or that are initialized for an analysis. There exists exactly
810  * one type with this opcode.
811  */
812 extern const tp_op *tpop_none;
813 const tp_op *get_tpop_none(void);
814
815 /**
816  * This type opcode is an auxiliary opcode dedicated to support type analyses.
817  *
818  * Types with this opcode represents that there could be a type, but it is not
819  * known.  This type can be used to initialize fields before an analysis (not known
820  * yet) or to represent the top of a lattice (could not be determined).  There exists
821  * exactly one type with this opcode.
822  */
823 extern const tp_op *tpop_unknown;
824 const tp_op *get_tpop_unknown(void);
825
826 /* ----------------------------------------------------------------------- */
827 /* Classify pairs of types/entities in the inheritance relations.          */
828 /* ----------------------------------------------------------------------- */
829
830 /** Returns true if low is subclass of high.
831  *
832  *  Low is a subclass of high if low == high or if low is a subclass of
833  *  a subclass of high.  I.e, we search in all subtypes of high for low.
834  *  @@@ this can be implemented more efficient if we know the set of all
835  *  subclasses of high.  */
836 int is_SubClass_of(ir_type *low, ir_type *high);
837
838 /** Subclass check for pointers to classes.
839  *
840  *  Dereferences at both types the same amount of pointer types (as
841  *  many as possible).  If the remaining types are both class types
842  *  and subclasses, returns true, else false.  Can also be called with
843  *  two class types.  */
844 int is_SubClass_ptr_of(ir_type *low, ir_type *high);
845
846 /** Returns true if high is superclass of low.
847  *
848  *  Low is a subclass of high if low == high or if low is a subclass of
849  *  a subclass of high.  I.e, we search in all subtypes of high for low.
850  *  @@@ this can be implemented more efficient if we know the set of all
851  *  subclasses of high.  */
852 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
853
854 /** Superclass check for pointers to classes.
855  *
856  *  Dereferences at both types the same amount of pointer types (as
857  *  many as possible).  If the remaining types are both class types
858  *  and superclasses, returns true, else false.  Can also be called with
859  *  two class types.  */
860 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
861
862 /** Returns true if high is (transitive) overwritten by low.
863  *
864  *  Returns false if high == low. */
865 int is_overwritten_by(ir_entity *high, ir_entity *low);
866
867 /** Resolve polymorphism in the inheritance relation.
868  *
869  *  Returns the dynamically referenced entity if the static entity and the
870  *  dynamic type are given.
871  *  Searches downwards in overwritten tree. */
872 ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity* static_ent);
873
874 /* ----------------------------------------------------------------------- */
875 /* Resolve implicit inheritance.                                           */
876 /* ----------------------------------------------------------------------- */
877
878 /** Default name mangling for inherited entities.
879  *
880  *  Returns an ident that consists of the name of type followed by an
881  *  underscore and the name (not ld_name) of the entity. */
882 ident *default_mangle_inherited_name(const ir_entity *ent, const ir_type *clss);
883
884 /** Type of argument functions for inheritance resolver.
885  *
886  * @param ent     The entity in the super type that will be overwritten
887  *                by the newly generated entity, for which this name is
888  *                used.
889  * @param clss    The class type in which the new entity will be placed.
890  */
891 typedef ident *mangle_inherited_name_func(const ir_entity *ent, const ir_type *clss);
892
893 /** Resolve implicit inheritance.
894  *
895  *  Resolves the implicit inheritance supplied by firm.  Firm defines,
896  *  that each entity that is not overwritten in a subclass is
897  *  inherited to this subclass without change implicitly.  This
898  *  function generates entities that explicitly represent this
899  *  inheritance.  It generates for each entity overwriting entities in
900  *  all subclasses of the owner of the entity, if the entity is not
901  *  overwritten in that subclass.
902  *
903  *  The name of the new entity is generated with the function passed.
904  *  If the function is NULL, the default_mangle_inherited_name() is
905  *  used.
906  *
907  *  This function was moved here from firmlower 3/2005.
908  */
909 void resolve_inheritance(mangle_inherited_name_func *mfunc);
910
911
912 /* ----------------------------------------------------------------------- */
913 /* The transitive closure of the subclass/superclass and                   */
914 /* overwrites/overwrittenby relation.                                      */
915 /*                                                                         */
916 /* A walk over the ir (O(#types+#entities)) computes the transitive        */
917 /* closure.  Adding a new type/entity or changing the basic relations in   */
918 /* some other way invalidates the transitive closure, i.e., it is not      */
919 /* updated by the basic functions.                                         */
920 /*                                                                         */
921 /* The transitive edges are held in a set, not in an array as the          */
922 /* underlying relation.                                                    */
923 /*                                                                         */
924 /* Do the sets contain the node itself?  I assume NOT!                     */
925 /* ----------------------------------------------------------------------- */
926
927 /** The state of the transitive closure.
928  *
929  *  @todo: we could manage the state for each relation separately.  Invalidating
930  *  the entity relations does not mean invalidating the class relation. */
931 typedef enum {
932         inh_transitive_closure_none,       /**<  Closure is not computed, can not be accessed. */
933         inh_transitive_closure_valid,      /**<  Closure computed and valid. */
934         inh_transitive_closure_invalid,    /**<  Closure invalid, but can be accessed. */
935         inh_transitive_closure_max         /**<  Invalid value. */
936 } inh_transitive_closure_state;
937
938 void                         set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
939 void                         invalidate_irp_inh_transitive_closure_state(void);
940 inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
941
942
943 /** Compute transitive closure of the subclass/superclass and
944  * overwrites/overwrittenby relation.
945  *
946  * This function walks over the ir (O(\#types+\#entities)) to compute the
947  * transitive closure.    */
948 void compute_inh_transitive_closure(void);
949
950 /** Free memory occupied by the transitive closure information. */
951 void free_inh_transitive_closure(void);
952
953
954 /* - subtype ------------------------------------------------------------- */
955
956 /** Iterate over all transitive subtypes. */
957 ir_type *get_class_trans_subtype_first(const ir_type *tp);
958 ir_type *get_class_trans_subtype_next(const ir_type *tp);
959 int is_class_trans_subtype(const ir_type *tp, const ir_type *subtp);
960
961 /* - supertype ----------------------------------------------------------- */
962
963 /** Iterate over all transitive supertypes. */
964 ir_type *get_class_trans_supertype_first(const ir_type *tp);
965 ir_type *get_class_trans_supertype_next(const ir_type *tp);
966
967 /* - overwrittenby ------------------------------------------------------- */
968
969 /** Iterate over all entities that transitive overwrite this entities. */
970 ir_entity *get_entity_trans_overwrittenby_first(const ir_entity *ent);
971 ir_entity *get_entity_trans_overwrittenby_next(const ir_entity *ent);
972
973 /* - overwrites ---------------------------------------------------------- */
974
975 /** Iterate over all transitive overwritten entities. */
976 ir_entity *get_entity_trans_overwrites_first(const ir_entity *ent);
977 ir_entity *get_entity_trans_overwrites_next(const ir_entity *ent);
978
979
980 /* ----------------------------------------------------------------------- */
981 /** The state of Cast operations that cast class types or pointers to class
982  *  types.
983  *
984  * The state expresses, how far Cast operations conform with the class
985  * hierarchy.
986  *
987  *   class A {}
988  *   class B1 extends A {}
989  *   class B2 extends A {}
990  *   class C  extends B1 {}
991  * normalized:  Cast operations conform with the inheritance relation.
992  *   I.e., the type of the operand of a Cast is either a super= or a sub-
993  *   type of the type casted to. Example: (A)((B2) (new C())).
994  * transitive:  Cast operations conform with the transitive inheritance
995  *   relation. Example: (A)(new C()).
996  * any:  Cast operations do not conform with the transitive inheritance
997  *   relation.  Example: (B2)(new B1())
998  */
999 /* ----------------------------------------------------------------------- */
1000
1001 /** Flags for class cast state.
1002  *
1003  * The state in irp is always smaller or equal to the state of any
1004  * irg.
1005  *
1006  * We rely on the ordering of the enum. */
1007 typedef enum {
1008         ir_class_casts_any        = 0, /**< There are class casts that do not cast in conformance with
1009                                             the class hierarchy.  @@@ So far this does not happen in Firm. */
1010         ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */
1011         ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */
1012         ir_class_casts_state_max
1013 } ir_class_cast_state;
1014 const char *get_class_cast_state_string(ir_class_cast_state s);
1015
1016 void                set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s);
1017 ir_class_cast_state get_irg_class_cast_state(const ir_graph *irg);
1018 void                set_irp_class_cast_state(ir_class_cast_state s);
1019 ir_class_cast_state get_irp_class_cast_state(void);
1020
1021 /** Verify the class cast state of an irg.
1022  *
1023  *  Asserts if state is to high, outputs debug warning if state is to low
1024  *  and firm verbosity is set.
1025  */
1026 void verify_irg_class_cast_state(ir_graph *irg);
1027
1028 /**
1029  * possible trvrfy() error codes
1030  */
1031 enum trvrfy_error_codes {
1032         no_error = 0,                      /**< no error */
1033         error_ent_not_cont,                /**< overwritten entity not in superclass */
1034         error_null_mem,                    /**< compound contains NULL member */
1035         error_const_on_wrong_irg,          /**< constant placed on wrong IRG */
1036         error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */
1037         error_wrong_ent_overwrites,        /**< number of entity overwrites exceeds number of class overwrites */
1038         error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */
1039         error_glob_ent_allocation,         /**< wrong allocation of a global entity */
1040         error_ent_const_mode,              /**< Mode of constant in entity did not match entities type. */
1041         error_ent_wrong_owner              /**< Mode of constant in entity did not match entities type. */
1042 };
1043
1044 /**
1045  * Checks a type.
1046  *
1047  * @return
1048  *  0   if no error encountered
1049  */
1050 int check_type(ir_type *tp);
1051
1052 /**
1053  * Check an entity. Currently, we check only if initialized constants
1054  * are build on the const irg graph.
1055  *
1056  * @return
1057  *  0   if no error encountered
1058  *  != 0    a trvrfy_error_codes code
1059  */
1060 int check_entity(ir_entity *ent);
1061
1062 /**
1063  * Walks the type information and performs a set of sanity checks.
1064  *
1065  * Currently, the following checks are executed:
1066  * - values of initialized entities must be allocated on the constant IRG
1067  * - class types: doesn't have NULL members
1068  * - class types: all overwrites are existent in the super type
1069  *
1070  * @return
1071  *    0 if graph is correct
1072  *    else error code.
1073  */
1074 int tr_vrfy(void);
1075
1076 /**
1077  * If NDEBUG is defined performs nothing, else calls the tr_vrfy() function.
1078  */
1079 #ifdef NDEBUG
1080 #define TR_VRFY()       0
1081 #else
1082 #define TR_VRFY()       tr_vrfy()
1083 #endif
1084
1085 /**
1086  * @page type   representation of types
1087  *
1088  *  Datastructure to hold type information.
1089  *
1090  *  This module supplies a datastructure to represent all types
1091  *  known in the compiled program.  This includes types specified
1092  *  in the program as well as types defined by the language.  In the
1093  *  view of the intermediate representation there is no difference
1094  *  between these types.  Finally it specifies some auxiliary types.
1095  *
1096  *  There exist several kinds of types, arranged by the structure of
1097  *  the type.  A type is described by a set of attributes.  Some of
1098  *  these attributes are common to all types, others depend on the
1099  *  kind of the type.
1100  *
1101  *  Types are different from the modes defined in irmode:  Types are
1102  *  on the level of the programming language, modes at the level of
1103  *  the target processor.
1104  */
1105
1106 /** Frees all entities associated with a type.
1107  *  Does not free the array entity.
1108  *  Warning: ensure these entities are not referenced anywhere else.
1109  */
1110 void free_type_entities(ir_type *tp);
1111
1112 /** Frees the memory used by the type.
1113  *
1114  * Removes the type from the type list. Does not free the entities
1115  * belonging to the type, except for the array element entity.  Does
1116  * not free if tp is "none" or "unknown".  Frees entities in value
1117  * param subtypes of method types!!! Make sure these are not
1118  * referenced any more.  Further make sure there is no pointer type
1119  * that refers to this type.                           */
1120 void free_type(ir_type *tp);
1121
1122 const tp_op *get_type_tpop(const ir_type *tp);
1123 ident *get_type_tpop_nameid(const ir_type *tp);
1124 const char *get_type_tpop_name(const ir_type *tp);
1125 tp_opcode get_type_tpop_code(const ir_type *tp);
1126
1127 /**
1128  * construct a string representing the type.
1129  * This uses the info retrieved by the type_dbg_info if available.
1130  * Otherwise it tries to create an approximate textual representation of the
1131  * type.
1132  * Keep in mind that this representation is not unique for each type,
1133  * might abstract away some details. The main intention of this is creating
1134  * human redable strings giving an idea of the type.
1135  */
1136 void ir_print_type(char *buffer, size_t buffer_size, const ir_type *tp);
1137
1138 /** The visibility of a type.
1139  *
1140  *  The visibility of a type indicates, whether entities of this type
1141  *  are accessed or allocated in external code.
1142  *
1143  *  An entity of a type is allocated in external code, if the external
1144  *  code declares a variable of this type, or dynamically allocates
1145  *  an entity of this type.  If the external code declares a (compound)
1146  *  type, that contains entities of this type, the visibility also
1147  *  must be external_allocated.
1148  *
1149  *  The visibility must be higher than that of all entities, if the
1150  *  type is a compound.  Here it is questionable, what happens with
1151  *  static entities.  If these are accessed external by direct reference,
1152  *  (a static call to a method, that is also in the dispatch table)
1153  *  it should not affect the visibility of the type.
1154  *
1155  *
1156  * @@@ Do we need a visibility for types?
1157  * I change the layout of types radically when doing type splitting.
1158  * I need to know, which fields of classes are accessed in the RTS,
1159  * e.g., [_length.  I may not move [_length to the split part.
1160  * The layout though, is a property of the type.
1161  *
1162  * One could also think of changing the mode of a type ...
1163  *
1164  * But, we could also output macros to access the fields, e.g.,
1165  *  ACCESS_[_length (X)   X->length              // conventional
1166  *  ACCESS_[_length (X)   X->_split_ref->length  // with type splitting
1167  *
1168  * For now I implement this function, that returns the visibility
1169  * based on the visibility of the entities of a compound ...
1170  *
1171  * This function returns visibility_external_visible if one or more
1172  * entities of a compound type have visibility_external_visible.
1173  * Entities of types are never visibility_external_allocated (right?).
1174  * Else returns visibility_local.
1175  */
1176 ir_visibility get_type_visibility(const ir_type *tp);
1177 void          set_type_visibility(ir_type *tp, ir_visibility v);
1178
1179
1180
1181 /** The state of the type layout. */
1182 typedef enum {
1183         layout_undefined,    /**< The layout of this type is not defined.
1184                                   Address computation to access fields is not
1185                                   possible, fields must be accessed by Sel
1186                                   nodes.  Enumeration constants might be undefined.
1187                                   This is the default value except for
1188                                   pointer, primitive and method types. */
1189         layout_fixed         /**< The layout is fixed, all component/member entities
1190                                   have an offset assigned.  Size of the type is known.
1191                                   Arrays can be accessed by explicit address
1192                                   computation.  Enumeration constants must be defined.
1193                                   Default for pointer, primitive and method types. */
1194 } ir_type_state;
1195
1196 /** Returns a human readable string for the enum entry. */
1197 const char *get_type_state_name(ir_type_state s);
1198
1199 /** Returns the type layout state of a type. */
1200 ir_type_state get_type_state(const ir_type *tp);
1201
1202 /** Sets the type layout state of a type.
1203  *
1204  * For primitives, pointer and method types the layout is always fixed.
1205  * This call is legal but has no effect.
1206  */
1207 void set_type_state(ir_type *tp, ir_type_state state);
1208
1209 /** Returns the mode of a type.
1210  *
1211  * Returns NULL for all non atomic types.
1212  */
1213 ir_mode *get_type_mode(const ir_type *tp);
1214
1215 /** Sets the mode of a type.
1216  *
1217  * Only has an effect on primitive, enumeration and pointer types.
1218  */
1219 void set_type_mode(ir_type *tp, ir_mode* m);
1220
1221 /** Returns the size of a type in bytes. */
1222 unsigned get_type_size_bytes(const ir_type *tp);
1223
1224 /** Sets the size of a type in bytes.
1225  *
1226  * For primitive, enumeration, pointer and method types the size
1227  * is always fixed. This call is legal but has no effect.
1228  */
1229 void set_type_size_bytes(ir_type *tp, unsigned size);
1230
1231 /** Returns the alignment of a type in bytes. */
1232 unsigned get_type_alignment_bytes(ir_type *tp);
1233
1234 /** Returns the alignment of a type in bits.
1235  *
1236  *  If the alignment of a type is
1237  *  not set, it is calculated here according to the following rules:
1238  *  -#.) if a type has a mode, the alignment is the mode size.
1239  *  -#.) compound types have the alignment of there biggest member.
1240  *  -#.) array types have the alignment of there element type.
1241  *  -#.) method types return 0 here.
1242  *  -#.) all other types return 1 here (i.e. aligned at byte).
1243  */
1244 void set_type_alignment_bytes(ir_type *tp, unsigned align);
1245
1246 /** Returns the visited count of a type. */
1247 ir_visited_t get_type_visited(const ir_type *tp);
1248 /** Sets the visited count of a type to num. */
1249 void set_type_visited(ir_type *tp, ir_visited_t num);
1250 /** Sets visited field in type to type_visited. */
1251 void mark_type_visited(ir_type *tp);
1252 /** Returns non-zero if the type is already visited */
1253 int type_visited(const ir_type *tp);
1254 /** Returns non-zero if the type is not yet visited */
1255 int type_not_visited(const ir_type *tp);
1256
1257 /** Returns the associated link field of a type. */
1258 void *get_type_link(const ir_type *tp);
1259 /** Sets the associated link field of a type. */
1260 void set_type_link(ir_type *tp, void *l);
1261
1262 /**
1263  * Visited flag to traverse the type information.
1264  *
1265  * Increase this flag by one before traversing the type information
1266  * using inc_master_type_visited().
1267  * Mark type nodes as visited by mark_type_visited(ir_type).
1268  * Check whether node was already visited by type_visited(ir_type)
1269  * and type_not_visited(ir_type).
1270  * Or use the function to walk all types.
1271  *
1272  * @see  typewalk
1273  */
1274 void         set_master_type_visited(ir_visited_t val);
1275 ir_visited_t get_master_type_visited(void);
1276 void         inc_master_type_visited(void);
1277
1278 /**
1279  * Sets the debug information of a type.
1280  *
1281  * @param tp  The type.
1282  * @param db  The debug info.
1283  */
1284 void set_type_dbg_info(ir_type *tp, type_dbg_info *db);
1285
1286 /**
1287  * Returns the debug information of a type.
1288  *
1289  * @param tp  The type.
1290  */
1291 type_dbg_info *get_type_dbg_info(const ir_type *tp);
1292
1293 /**
1294  * Checks whether a pointer points to a type.
1295  *
1296  * @param thing     an arbitrary pointer
1297  *
1298  * @return
1299  *     true if the thing is a type, else false
1300  */
1301 int is_type(const void *thing);
1302
1303 /**
1304  *   Checks whether two types are structurally equal.
1305  *
1306  *   @param typ1  the first type
1307  *   @param typ2  the second type
1308  *
1309  *   @return
1310  *    true if the types are equal, else false.
1311  *
1312  *   Types are equal if :
1313  *    - they are the same type kind
1314  *    - they have the same name
1315  *    - they have the same mode (if applicable)
1316  *    - they have the same type_state and, ev., the same size
1317  *    - they are class types and have:
1318  *      - the same members (see same_entity in entity.h)
1319  *      - the same supertypes -- the C-pointers are compared --> no recursive call.
1320  *      - the same number of subtypes.  Subtypes are not compared,
1321  *        as this could cause a cyclic test.
1322  *      - the same peculiarity
1323  *    - they are structure types and have the same members
1324  *    - they are method types and have
1325  *      - the same parameter types
1326  *      - the same result types
1327  *    - they are union types and have the same members
1328  *    - they are array types and have
1329  *      - the same number of dimensions
1330  *      - the same dimension bounds
1331  *      - the same dimension order
1332  *      - the same element type
1333  *    - they are enumeration types and have the same enumerator names
1334  *    - they are pointer types and have the identical points_to type
1335  *      (i.e., the same C-struct to represent the type.
1336  *       This is to avoid endless recursions; with pointer types cyclic
1337  *       type graphs are possible.)
1338  */
1339 int equal_type(ir_type *typ1, ir_type *typ2);
1340
1341 /**
1342  *   Checks whether two types are structural comparable.
1343  *
1344  *   @param st pointer type
1345  *   @param lt pointer type
1346  *
1347  *   @return
1348  *    true if type st is smaller than type lt, i.e. whenever
1349  *    lt is expected a st can be used.
1350  *    This is true if
1351  *    - they are the same type kind
1352  *    - mode(st) < mode (lt)  (if applicable)
1353  *    - they are class types and st is (transitive) subtype of lt,
1354  *    - they are structure types and
1355  *       - the members of st have exactly one counterpart in lt with the same name,
1356  *       - the counterpart has a bigger type.
1357  *    - they are method types and have
1358  *      - the same number of parameter and result types,
1359  *      - the parameter types of st are smaller than those of lt,
1360  *      - the result types of st are smaller than those of lt
1361  *    - they are union types and have the members of st have exactly one
1362  *      @return counterpart in lt and the type is smaller
1363  *    - they are array types and have
1364  *      - the same number of dimensions
1365  *      - all bounds of lt are bound of st
1366  *      - the same dimension order
1367  *      - the same element type
1368  *      @return or
1369  *      - the element type of st is smaller than that of lt
1370  *      - the element types have the same size and fixed layout.
1371  *    - they are enumeration types and have the same enumerator names
1372  *    - they are pointer types and have the points_to type of st is
1373  *      @return smaller than the points_to type of lt.
1374  *
1375  */
1376 int smaller_type(ir_type *st, ir_type *lt);
1377
1378 /**
1379  *  @page class_type    Representation of a class type
1380  *
1381  *  If the type opcode is set to type_class the type represents class
1382  *  types.  A list of fields and methods is associated with a class.
1383  *  Further a class can inherit from and bequest to other classes.
1384  *
1385  *  The following attributes are private to this type kind:
1386  *  - member:     All entities belonging to this class.  This are method entities
1387  *                which have type_method or fields that can have any of the
1388  *                following type kinds: type_class, type_struct, type_union,
1389  *                type_array, type_enumeration, type_pointer, type_primitive.
1390  *
1391  *  The following two are dynamic lists that can be grown with an "add_" function,
1392  *  but not shrinked:
1393  *
1394  *  - subtypes:    A list of direct subclasses.
1395  *
1396  *  - supertypes:  A list of direct superclasses.
1397  *
1398  *  - peculiarity: The peculiarity of this class.  If the class is of peculiarity
1399  *                 "description" it only is a description of requirements to a class,
1400  *                 as, e.g., a Java interface.  The class will never be allocated.
1401  *                 Peculiarity inherited is only possible for entities.  An entity
1402  *                 is of peculiarity inherited if the compiler generated the entity
1403  *                 to explicitly resolve inheritance.  An inherited method entity has
1404  *                 no value for irg.
1405  *                 Values: description, existent, inherited.  Default: existent.
1406  *
1407  *  - type_info:   An entity representing the type information of this class.
1408  *                 This entity can be of arbitrari type, Firm did not use it yet.
1409  *                 It allows to express the coupling of a type with an entity
1410  *                 representing this type.  This information is useful for lowering
1411  *                 of InstOf and TypeChk nodes.  Default: NULL
1412  *
1413  *  - vtable_size: The size of this class virtual function table.
1414  *                 Default:  0
1415  *
1416  *  - final:       A final class is always a leaf in the class hierarchy.  Final
1417  *                 classes cannot be super classes of other ones.  As this information
1418  *                 can only be computed in whole world compilations, we allow to
1419  *                 set this flag.  It is used in optimizations if get_opt_closed_world()
1420  *                 is false.  Default:  false
1421  *
1422  *  - interface:   The class represents an interface.  This flag can be set to distinguish
1423  *                 between interfaces, abstract classes and other classes that all may
1424  *                 have the peculiarity peculiarity_description.  Depending on this flag
1425  *                 the lowering might do different actions.  Default:  false
1426  *
1427  *  - abstract :   The class represents an abstract class.  This flag can be set to distinguish
1428  *                 between interfaces, abstract classes and other classes that all may
1429  *                 have the peculiarity peculiarity_description.  Depending on this flag
1430  *                 the lowering might do different actions.  Default:  false
1431  */
1432
1433 /** Creates a new class type. */
1434 ir_type *new_type_class(ident *name);
1435
1436 /** Creates a new class type with debug information. */
1437 ir_type *new_d_type_class(ident *name, type_dbg_info *db);
1438
1439 /* --- manipulate private fields of class type  --- */
1440
1441 /** return identifier of the class type */
1442 ident *get_class_ident(const ir_type *clss);
1443
1444 /** return identifier of the class type */
1445 const char *get_class_name(const ir_type *clss);
1446
1447 /** Adds the entity as member of the class.  */
1448 void add_class_member(ir_type *clss, ir_entity *member);
1449
1450 /** Returns the number of members of this class. */
1451 int get_class_n_members(const ir_type *clss);
1452
1453 /** Returns the member at position pos, 0 <= pos < n_member */
1454 ir_entity *get_class_member(const ir_type *clss, int pos);
1455
1456 /** Returns index of mem in clss, -1 if not contained. */
1457 int get_class_member_index(const ir_type *clss, ir_entity *mem);
1458
1459 /** Finds the member with name 'name'. If several members with the same
1460  *  name returns one of them.  Returns NULL if no member found. */
1461 ir_entity *get_class_member_by_name(ir_type *clss, ident *name);
1462
1463 /** Overwrites the member at position pos, 0 <= pos < n_member with
1464  *  the passed entity. */
1465 void set_class_member(ir_type *clss, ir_entity *member, int pos);
1466
1467 /** Replaces complete member list in class type by the list passed.
1468  *
1469  *  Copies the list passed. This function is necessary to reduce the number of members.
1470  *  members is an array of entities, num the size of this array.  Sets all
1471  *  owners of the members passed to clss. */
1472 void set_class_members(ir_type *clss, ir_entity *members[], int arity);
1473
1474 /** Finds member in the list of members and removes it.
1475  *
1476  *  Shrinks the member list, so iterate from the end!!!
1477  *  Does not deallocate the entity.  */
1478 void remove_class_member(ir_type *clss, ir_entity *member);
1479
1480
1481 /** Adds subtype as subtype to clss.
1482  *
1483  *  Checks whether clss is a supertype of subtype.  If not
1484  *  adds also clss as supertype to subtype.  */
1485 void add_class_subtype(ir_type *clss, ir_type *subtype);
1486
1487 /** Returns the number of subtypes */
1488 int get_class_n_subtypes(const ir_type *clss);
1489
1490 /** Gets the subtype at position pos, 0 <= pos < n_subtype. */
1491 ir_type *get_class_subtype(ir_type *clss, int pos);
1492
1493 /** Returns the index to access subclass as subtype of class.
1494  *
1495  *  If subclass is no direct subtype of class returns -1.
1496  */
1497 int get_class_subtype_index(ir_type *clss, const ir_type *subclass);
1498
1499 /** Sets the subtype at position pos, 0 <= pos < n_subtype.
1500  *
1501  *  Does not set the corresponding supertype relation for subtype: this might
1502  *  be a different position! */
1503 void set_class_subtype(ir_type *clss, ir_type *subtype, int pos);
1504
1505 /** Finds subtype in the list of subtypes and removes it  */
1506 void remove_class_subtype(ir_type *clss, ir_type *subtype);
1507
1508 /* Convenience macros */
1509 #define add_class_derived_type(clss, drvtype)       add_class_subtype(clss, drvtype)
1510 #define get_class_n_derived_types(clss)             get_class_n_subtypes(clss)
1511 #define get_class_derived_type(clss, pos)           get_class_subtype(clss, pos)
1512 #define get_class_derived_type_index(clss, drvtype) get_class_subtype_index(clss, drvtype)
1513 #define set_class_derived_type(clss, drvtype, pos)  set_class_subtype(clss, drvtype, pos)
1514 #define remove_class_derived_type(clss, drvtype)    remove_class_subtype(clss, drvtype)
1515
1516 /** Adds supertype as supertype to class.
1517  *
1518  *  Checks whether clss is a subtype of supertype.  If not
1519  *  adds also clss as subtype to supertype.  */
1520 void add_class_supertype(ir_type *clss, ir_type *supertype);
1521
1522 /** Returns the number of supertypes */
1523 int get_class_n_supertypes(const ir_type *clss);
1524
1525 /** Returns the index to access superclass as supertype of class.
1526  *
1527  *  If superclass is no direct supertype of class returns -1.
1528  */
1529 int get_class_supertype_index(ir_type *clss, ir_type *super_clss);
1530
1531 /** Gets the supertype at position pos,  0 <= pos < n_supertype. */
1532 ir_type *get_class_supertype(ir_type *clss, int pos);
1533
1534 /** Sets the supertype at position pos, 0 <= pos < n_supertype.
1535  *
1536  *  Does not set the corresponding subtype relation for supertype: this might
1537  *  be at a different position! */
1538 void set_class_supertype(ir_type *clss, ir_type *supertype, int pos);
1539
1540 /** Finds supertype in the list of supertypes and removes it */
1541 void remove_class_supertype(ir_type *clss, ir_type *supertype);
1542
1543 /** Convenience macro */
1544 #define add_class_base_type(clss, basetype)        add_class_supertype(clss, basetype)
1545 #define get_class_n_base_types(clss)               get_class_n_supertypes(clss)
1546 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
1547 #define get_class_base_type(clss, pos)             get_class_supertype(clss, pos)
1548 #define set_class_base_type(clss, basetype, pos)   set_class_supertype(clss, basetype, pos)
1549 #define remove_class_base_type(clss, basetype)     remove_class_supertype(clss, basetype)
1550
1551 /** Returns a human readable string for a peculiarity. */
1552 const char *get_peculiarity_name(ir_peculiarity p);
1553
1554 /** Returns the peculiarity of the class. */
1555 ir_peculiarity get_class_peculiarity(const ir_type *clss);
1556 /** Sets the peculiarity of the class. */
1557 void set_class_peculiarity(ir_type *clss, ir_peculiarity pec);
1558
1559 /** Returns the type info entity of a class. */
1560 ir_entity *get_class_type_info(const ir_type *clss);
1561
1562 /** Set a type info entity for the class. */
1563 void set_class_type_info(ir_type *clss, ir_entity *ent);
1564
1565 /** Returns the size of the virtual function table. */
1566 unsigned get_class_vtable_size(const ir_type *clss);
1567
1568 /** Sets a new size of the virtual function table. */
1569 void set_class_vtable_size(ir_type *clss, unsigned size);
1570
1571 /** Returns non-zero if a class is final. */
1572 int is_class_final(const ir_type *clss);
1573
1574 /** Sets the class final flag. */
1575 void set_class_final(ir_type *clss, int flag);
1576
1577 /** Return non-zero if a class is an interface */
1578 int is_class_interface(const ir_type *clss);
1579
1580 /** Sets the class interface flag. */
1581 void set_class_interface(ir_type *clss, int flag);
1582
1583 /** Return non-zero if a class is an abstract class. */
1584 int is_class_abstract(const ir_type *clss);
1585
1586 /** Sets the class abstract flag. */
1587 void set_class_abstract(ir_type *clss, int flag);
1588
1589 /** Set and get a class' dfn --
1590    @todo This is an undocumented field, subject to change! */
1591 void set_class_dfn(ir_type *clss, int dfn);
1592 int  get_class_dfn(const ir_type *clss);
1593
1594 /** Returns true if a type is a class type. */
1595 int is_Class_type(const ir_type *clss);
1596
1597 /**
1598  *  @page struct_type   Representation of a struct type
1599  *
1600  *  A struct type represents aggregate types that consist of a list
1601  *  of fields.
1602  *
1603  *  The following attributes are private to this type kind:
1604  *  - member:  All entities belonging to this class.  This are the fields
1605  *             that can have any of the following types:  type_class,
1606  *             type_struct, type_union, type_array, type_enumeration,
1607  *             type_pointer, type_primitive.
1608  *             This is a dynamic list that can be grown with an "add_" function,
1609  *             but not shrinked.
1610  *             This is a dynamic list that can be grown with an "add_" function,
1611  *             but not shrinked.
1612  */
1613 /** Creates a new type struct */
1614 ir_type *new_type_struct(ident *name);
1615 /** Creates a new type struct with debug information. */
1616 ir_type *new_d_type_struct(ident *name, type_dbg_info* db);
1617
1618 /* --- manipulate private fields of struct --- */
1619
1620 /** return struct identifier */
1621 ident *get_struct_ident(const ir_type *strct);
1622
1623 /** return struct identifier as c-string*/
1624 const char *get_struct_name(const ir_type *strct);
1625
1626 /** Adds the entity as member of the struct.  */
1627 void add_struct_member(ir_type *strct, ir_entity *member);
1628
1629 /** Returns the number of members of this struct. */
1630 int get_struct_n_members(const ir_type *strct);
1631
1632 /** Returns the member at position pos, 0 <= pos < n_member */
1633 ir_entity *get_struct_member(const ir_type *strct, int pos);
1634
1635 /** Returns index of member in strct, -1 if not contained. */
1636 int get_struct_member_index(const ir_type *strct, ir_entity *member);
1637
1638 /** Overwrites the member at position pos, 0 <= pos < n_member with
1639    the passed entity. */
1640 void set_struct_member(ir_type *strct, int pos, ir_entity *member);
1641
1642 /** Finds member in the list of members and removes it. */
1643 void remove_struct_member(ir_type *strct, ir_entity *member);
1644
1645 /** Returns true if a type is a struct type. */
1646 int is_Struct_type(const ir_type *strct);
1647
1648 /**
1649  * @page method_type    Representation of a method type
1650  *
1651  * A method type represents a method, function or procedure type.
1652  * It contains a list of the parameter and result types, as these
1653  * are part of the type description.  These lists should not
1654  * be changed by a optimization, as a change creates a new method
1655  * type.  Therefore optimizations should allocated new method types.
1656  * The set_ routines are only for construction by a frontend.
1657  *
1658  * - n_params:   Number of parameters to the procedure.
1659  *               A procedure in FIRM has only call by value parameters.
1660  *
1661  * - param_type: A list with the types of parameters.  This list is ordered.
1662  *               The nth type in this list corresponds to the nth element
1663  *               in the parameter tuple that is a result of the start node.
1664  *               (See ircons.h for more information.)
1665  *
1666  * - value_param_ents
1667  *               A list of entities (whose owner is a struct private to the
1668  *               method type) that represent parameters passed by value.
1669  *
1670  * - n_res:      The number of results of the method.  In general, procedures
1671  *               have zero results, functions one.
1672  *
1673  * - res_type:   A list with the types of parameters.  This list is ordered.
1674  *               The nth type in this list corresponds to the nth input to
1675  *               Return nodes.  (See ircons.h for more information.)
1676  *
1677  * - value_res_ents
1678  *               A list of entities (whose owner is a struct private to the
1679  *               method type) that represent results passed by value.
1680  */
1681
1682 /* These macros define the suffixes for the types and entities used
1683    to represent value parameters / results. */
1684 #define VALUE_PARAMS_SUFFIX  "val_param"
1685 #define VALUE_RESS_SUFFIX    "val_res"
1686
1687 /** Create a new method type.
1688  *
1689  * @param name      the name (ident) of this type
1690  * @param n_param   the number of parameters
1691  * @param n_res     the number of results
1692  *
1693  * The arrays for the parameter and result types are not initialized by
1694  * the constructor.
1695  */
1696 ir_type *new_type_method(int n_param, int n_res);
1697
1698 /** Create a new method type with debug information.
1699  *
1700  * @param name      the name (ident) of this type
1701  * @param n_param   the number of parameters
1702  * @param n_res     the number of results
1703  * @param db        user defined debug information
1704  *
1705  * The arrays for the parameter and result types are not initialized by
1706  * the constructor.
1707  */
1708 ir_type *new_d_type_method(int n_param, int n_res, type_dbg_info *db);
1709
1710 /* -- manipulate private fields of method. -- */
1711
1712 /** Returns the number of parameters of this method. */
1713 int get_method_n_params(const ir_type *method);
1714
1715 /** Returns the type of the parameter at position pos of a method. */
1716 ir_type *get_method_param_type(ir_type *method, int pos);
1717 /** Sets the type of the parameter at position pos of a method.
1718     Also changes the type in the pass-by-value representation by just
1719     changing the type of the corresponding entity if the representation is constructed. */
1720 void set_method_param_type(ir_type *method, int pos, ir_type *tp);
1721 /** Returns an entity that represents the copied value argument.  Only necessary
1722    for compounds passed by value. This information is constructed only on demand. */
1723 ir_entity *get_method_value_param_ent(ir_type *method, int pos);
1724 /**
1725  * Sets the type that represents the copied value arguments.
1726  */
1727 void set_method_value_param_type(ir_type *method, ir_type *tp);
1728 /**
1729  * Returns a type that represents the copied value arguments if one
1730  * was allocated, else NULL.
1731  */
1732 ir_type *get_method_value_param_type(const ir_type *method);
1733 /** Returns an ident representing the parameters name. Returns NULL if not set.
1734     For debug support only. */
1735 ident *get_method_param_ident(ir_type *method, int pos);
1736 /** Returns a string representing the parameters name. Returns NULL if not set.
1737     For debug support only. */
1738 const char *get_method_param_name(ir_type *method, int pos);
1739 /** Sets an ident representing the parameters name. For debug support only. */
1740 void set_method_param_ident(ir_type *method, int pos, ident *id);
1741
1742 /** Returns the number of results of a method type. */
1743 int get_method_n_ress(const ir_type *method);
1744 /** Returns the return type of a method type at position pos. */
1745 ir_type *get_method_res_type(ir_type *method, int pos);
1746 /** Sets the type of the result at position pos of a method.
1747     Also changes the type in the pass-by-value representation by just
1748     changing the type of the corresponding entity if the representation is constructed. */
1749 void set_method_res_type(ir_type *method, int pos, ir_type *tp);
1750 /** Returns an entity that represents the copied value result.  Only necessary
1751    for compounds passed by value. This information is constructed only on demand. */
1752 ir_entity *get_method_value_res_ent(ir_type *method, int pos);
1753
1754 /**
1755  * Returns a type that represents the copied value results.
1756  */
1757 ir_type *get_method_value_res_type(const ir_type *method);
1758
1759 /**
1760  * This enum flags the variadicity of methods (methods with a
1761  * variable amount of arguments (e.g. C's printf). Default is
1762  * non_variadic.
1763  */
1764 typedef enum ir_variadicity {
1765         variadicity_non_variadic, /**< non variadic */
1766         variadicity_variadic      /**< variadic */
1767 } ir_variadicity;
1768
1769 /** Returns the null-terminated name of this variadicity. */
1770 const char *get_variadicity_name(ir_variadicity vari);
1771
1772 /** Returns the variadicity of a method. */
1773 ir_variadicity get_method_variadicity(const ir_type *method);
1774
1775 /** Sets the variadicity of a method. */
1776 void set_method_variadicity(ir_type *method, ir_variadicity vari);
1777
1778 /**
1779  * Returns the first variadic parameter index of a type.
1780  * If this index was NOT set, the index of the last parameter
1781  * of the method type plus one is returned for variadic functions.
1782  * Non-variadic function types always return -1 here.
1783  */
1784 int get_method_first_variadic_param_index(const ir_type *method);
1785
1786 /**
1787  * Sets the first variadic parameter index. This allows to specify
1788  * a complete call type (containing the type of all parameters)
1789  * but still have the knowledge, which parameter must be passed as
1790  * variadic one.
1791  */
1792 void set_method_first_variadic_param_index(ir_type *method, int index);
1793
1794 /** Returns the mask of the additional graph properties. */
1795 unsigned get_method_additional_properties(const ir_type *method);
1796
1797 /** Sets the mask of the additional graph properties. */
1798 void set_method_additional_properties(ir_type *method, unsigned property_mask);
1799
1800 /** Sets one additional graph property. */
1801 void set_method_additional_property(ir_type *method, mtp_additional_property flag);
1802
1803 /**
1804  * Calling conventions: lower 24 bits are the number of register parameters,
1805  * upper 8 encode the calling conventions.
1806  */
1807 typedef enum {
1808         cc_reg_param           = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
1809                                                   This flag may be set as default on some architectures. */
1810         cc_last_on_top         = 0x02000000, /**< The last non-register parameter is transmitted on top of
1811                                                   the stack. This is equivalent to the pascal
1812                                                   calling convention. If this flag is not set, the first
1813                                                   non-register parameter is used (stdcall or cdecl
1814                                                   calling convention) */
1815         cc_callee_clear_stk    = 0x04000000, /**< The callee clears the stack. This forbids variadic
1816                                                   function calls (stdcall). */
1817         cc_this_call           = 0x08000000, /**< The first parameter is a this pointer and is transmitted
1818                                                   in a special way. */
1819         cc_compound_ret        = 0x10000000, /**< The method returns a compound type. */
1820         cc_frame_on_caller_stk = 0x20000000, /**< The method did not allocate an own stack frame, instead the
1821                                                   caller must reserve size on its own stack. */
1822         cc_fpreg_param         = 0x40000000, /**< Transmit floating point parameters in registers, else the stack is used. */
1823         cc_bits                = (0xFF << 24)/**< The calling convention bits. */
1824 } calling_convention;
1825
1826 /* some often used cases: made as defines because firmjni cannot handle two
1827    equal enum values. */
1828
1829 /** cdecl calling convention */
1830 #define cc_cdecl_set    (0)
1831 /** stdcall calling convention */
1832 #define cc_stdcall_set  cc_callee_clear_stk
1833 /** fastcall calling convention */
1834 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
1835
1836 /** Returns the default calling convention for method types. */
1837 unsigned get_default_cc_mask(void);
1838
1839 /**
1840  * check for the CDECL calling convention
1841  */
1842 #define IS_CDECL(cc_mask)     (((cc_mask) & cc_bits) == cc_cdecl_set)
1843
1844 /**
1845  * check for the STDCALL calling convention
1846  */
1847 #define IS_STDCALL(cc_mask)   (((cc_mask) & cc_bits) == cc_stdcall_set)
1848
1849 /**
1850  * check for the FASTCALL calling convention
1851  */
1852 #define IS_FASTCALL(cc_mask)  (((cc_mask) & cc_bits) == cc_fastcall_set)
1853
1854 /**
1855  * Sets the CDECL convention bits.
1856  */
1857 #define SET_CDECL(cc_mask)    (((cc_mask) & ~cc_bits) | cc_cdecl_set)
1858
1859 /**
1860  * Set. the STDCALL convention bits.
1861  */
1862 #define SET_STDCALL(cc_mask)  (((cc_mask) & ~cc_bits) | cc_stdcall_set)
1863
1864 /**
1865  * Sets the FASTCALL convention bits.
1866  */
1867 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
1868
1869 /** Returns the calling convention of an entities graph. */
1870 unsigned get_method_calling_convention(const ir_type *method);
1871
1872 /** Sets the calling convention of an entities graph. */
1873 void set_method_calling_convention(ir_type *method, unsigned cc_mask);
1874
1875 /** Returns the number of registers parameters, 0 means default. */
1876 unsigned get_method_n_regparams(ir_type *method);
1877
1878 /** Sets the number of registers parameters, 0 means default. */
1879 void set_method_n_regparams(ir_type *method, unsigned n_regs);
1880
1881 /** Returns true if a type is a method type. */
1882 int is_Method_type(const ir_type *method);
1883
1884 /**
1885  *   @page union_type   Representation of a union (variant) type.
1886  *
1887  *   The union type represents union types.  Note that this representation
1888  *   resembles the C union type.  For tagged variant types like in Pascal or Modula
1889  *   a combination of a struct and a union type must be used.
1890  *
1891  *   - n_types:     Number of unioned types.
1892  *   - members:     Entities for unioned types.  Fixed length array.
1893  *                  This is a dynamic list that can be grown with an "add_" function,
1894  *                  but not shrinked.
1895  */
1896 /** Creates a new type union. */
1897 ir_type *new_type_union(ident *name);
1898
1899 /** Creates a new type union with debug information. */
1900 ir_type *new_d_type_union(ident *name, type_dbg_info* db);
1901
1902 /* --- manipulate private fields of struct --- */
1903
1904 /** return union identifier */
1905 ident *get_union_ident(const ir_type *uni);
1906
1907 /** return union identifier as c-string */
1908 const char *get_union_name(const ir_type *uni);
1909
1910 /** Returns the number of unioned types of this union */
1911 int get_union_n_members(const ir_type *uni);
1912
1913 /** Adds a new entity to a union type */
1914 void add_union_member(ir_type *uni, ir_entity *member);
1915
1916 /** Returns the entity at position pos of a union */
1917 ir_entity *get_union_member(const ir_type *uni, int pos);
1918
1919 /** Returns index of member in uni, -1 if not contained. */
1920 int get_union_member_index(const ir_type *uni, ir_entity *member);
1921
1922 /** Overwrites a entity at position pos in a union type. */
1923 void set_union_member(ir_type *uni, int pos, ir_entity *member);
1924
1925 /** Finds member in the list of members and removes it. */
1926 void remove_union_member(ir_type *uni, ir_entity *member);
1927
1928 /** Returns true if a type is a union type. */
1929 int is_Union_type(const ir_type *uni);
1930
1931 /**
1932  * @page array_type Representation of an array type
1933  *
1934  * The array type represents rectangular multi dimensional arrays.
1935  * The constants representing the bounds must be allocated to
1936  * get_const_code_irg() by setting current_ir_graph accordingly.
1937  *
1938  * - n_dimensions:    Number of array dimensions.
1939  * - *lower_bound:    Lower bounds of dimensions.  Usually all 0.
1940  * - *upper_bound:    Upper bounds or dimensions.
1941  * - *element_type:   The type of the array elements.
1942  * - *element_ent:    An entity for the array elements to be used for
1943  *                      element selection with Sel.
1944  * @todo
1945  *   Do we need several entities?  One might want
1946  *   to select a dimension and not a single element in case of multi
1947  *   dimensional arrays.
1948  */
1949
1950 /** Create a new type array.
1951  *
1952  * Sets n_dimension to dimension and all dimension entries to NULL.
1953  * Initializes order to the order of the dimensions.
1954  * The entity for array elements is built automatically.
1955  * Set dimension sizes after call to constructor with set_* routines.
1956  */
1957 ir_type *new_type_array(int n_dims, ir_type *element_type);
1958
1959 /** Create a new type array with debug information.
1960  *
1961  * Sets n_dimension to dimension and all dimension entries to NULL.
1962  * Initializes order to the order of the dimensions.
1963  * The entity for array elements is built automatically.
1964  * Set dimension sizes after call to constructor with set_* routines.
1965  * A legal array type must have at least one dimension set.
1966  */
1967 ir_type *new_d_type_array(int n_dims, ir_type *element_type, type_dbg_info* db);
1968
1969 /* --- manipulate private fields of array type --- */
1970
1971 /** Returns the number of array dimensions of this type. */
1972 int get_array_n_dimensions(const ir_type *array);
1973
1974 /**
1975  * Allocates Const nodes of mode_Is for one array dimension.
1976  * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1977  */
1978 void set_array_bounds_int(ir_type *array, int dimension, int lower_bound,
1979                                                          int upper_bound);
1980 /**
1981  * Sets the bounds for one array dimension.
1982  * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1983  */
1984 void set_array_bounds(ir_type *array, int dimension, ir_node *lower_bound,
1985                                                      ir_node *upper_bound);
1986 /** Sets the lower bound for one array dimension, i.e. [lower,upper[ */
1987 void set_array_lower_bound(ir_type *array, int dimension, ir_node *lower_bound);
1988
1989 /** Allocates Const nodes of mode_Is for the lower bound of an array
1990     dimension, i.e. [lower,upper[ */
1991 void set_array_lower_bound_int(ir_type *array, int dimension, int lower_bound);
1992
1993 /** Sets the upper bound for one array dimension, i.e. [lower,upper[ */
1994 void set_array_upper_bound(ir_type *array, int dimension, ir_node *upper_bound);
1995
1996 /** Allocates Const nodes of mode_Is for the upper bound of an array
1997     dimension, i.e. [lower,upper[. */
1998 void set_array_upper_bound_int(ir_type *array, int dimension, int upper_bound);
1999
2000 /** Returns true if lower bound != Unknown. */
2001 int has_array_lower_bound(const ir_type *array, int dimension);
2002 /** Returns the lower bound of an array. */
2003 ir_node *get_array_lower_bound(const ir_type *array, int dimension);
2004 /** Works only if bound is Const node with tarval that can be converted to long. */
2005 long get_array_lower_bound_int(const ir_type *array, int dimension);
2006 /** returns true if lower bound != Unknown */
2007 int has_array_upper_bound(const ir_type *array, int dimension);
2008 /** Returns the upper bound of an array. */
2009 ir_node *get_array_upper_bound(const ir_type *array, int dimension);
2010 /** Works only if bound is Const node with tarval that can be converted to long. */
2011 long get_array_upper_bound_int(const ir_type *array, int dimension);
2012
2013 /** Sets an array dimension to a specific order. */
2014 void set_array_order(ir_type *array, int dimension, int order);
2015
2016 /** Returns the order of an array dimension. */
2017 int get_array_order(const ir_type *array, int dimension);
2018
2019 /** Find the array dimension that is placed at order order. */
2020 int find_array_dimension(const ir_type *array, int order);
2021
2022 /** Sets the array element type. */
2023 void set_array_element_type(ir_type *array, ir_type* tp);
2024
2025 /** Gets the array element type. */
2026 ir_type *get_array_element_type(const ir_type *array);
2027
2028 /** Sets the array element entity. */
2029 void set_array_element_entity(ir_type *array, ir_entity *ent);
2030
2031 /** Get the array element entity. */
2032 ir_entity *get_array_element_entity(const ir_type *array);
2033
2034 /** Returns true if a type is an array type. */
2035 int is_Array_type(const ir_type *array);
2036
2037 /**
2038  * @page enumeration_type   Representation of an enumeration type
2039  *
2040  * Enumeration types need not necessarily be represented explicitly
2041  * by Firm types, as the frontend can lower them to integer constants as
2042  * well.  For debugging purposes or similar tasks this information is useful.
2043  * The type state layout_fixed is set, if all enumeration constant have
2044  * there tarvals assigned.  Until then
2045  *
2046  * - *const:        The target values representing the constants used to
2047  *                  represent individual enumerations.
2048  */
2049
2050 /** Create a new type enumeration -- set the enumerators independently. */
2051 ir_type *new_type_enumeration(ident *name, int n_enums);
2052
2053 /** Create a new type enumeration with debug information -- set the enumerators independently. */
2054 ir_type *new_d_type_enumeration(ident *name, int n_enums, type_dbg_info *db);
2055
2056 /* --- manipulate fields of enumeration type. --- */
2057
2058 /** return enumeration identifier */
2059 ident *get_enumeration_ident(const ir_type *enumeration);
2060
2061 /** return enumeration identifier as c-string */
2062 const char *get_enumeration_name(const ir_type *enumeration);
2063
2064 /** Set an enumeration constant to a enumeration type at a given position. */
2065 void set_enumeration_const(ir_type *enumeration, int pos, ident *nameid, tarval *con);
2066
2067 /** Returns the number of enumeration values of this enumeration */
2068 int get_enumeration_n_enums(const ir_type *enumeration);
2069
2070 /** Returns the enumeration constant at a given position. */
2071 ir_enum_const *get_enumeration_const(const ir_type *enumeration, int pos);
2072
2073 /** Returns the enumeration type owner of an enumeration constant. */
2074 ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst);
2075
2076 /** Sets the enumeration constant value. */
2077 void set_enumeration_value(ir_enum_const *enum_cnst, tarval *con);
2078
2079 /** Returns the enumeration constant value. */
2080 tarval *get_enumeration_value(const ir_enum_const *enum_cnst);
2081
2082 /** Assign an ident to an enumeration constant. */
2083 void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
2084
2085 /** Returns the assigned ident of an enumeration constant. */
2086 ident *get_enumeration_const_nameid(const ir_enum_const *enum_cnst);
2087
2088 /** Returns the assigned name of an enumeration constant. */
2089 const char *get_enumeration_const_name(const ir_enum_const *enum_cnst);
2090
2091 /** Returns true if a type is a enumeration type. */
2092 int is_Enumeration_type(const ir_type *enumeration);
2093
2094 /**
2095  * @page pointer_type   Representation of a pointer type
2096  *
2097  * Pointer types:
2098  * - points_to:      The type of the entity this pointer points to.
2099  */
2100
2101 /** Creates a new type pointer. */
2102 ir_type *new_type_pointer(ir_type *points_to);
2103
2104 /** Creates a new type pointer with debug information. */
2105 ir_type *new_d_type_pointer(ir_type *points_to, type_dbg_info* db);
2106
2107 /* --- manipulate fields of type_pointer --- */
2108
2109 /** Sets the type to which a pointer points to. */
2110 void set_pointer_points_to_type(ir_type *pointer, ir_type *tp);
2111
2112 /** Returns the type to which a pointer points to. */
2113 ir_type *get_pointer_points_to_type(const ir_type *pointer);
2114
2115 /** Returns true if a type is a pointer type. */
2116 int is_Pointer_type(const ir_type *pointer);
2117
2118 /** Returns the first pointer type that has as points_to tp.
2119  *  Not efficient: O(\#types).
2120  *  If not found returns firm_unknown_type. */
2121 ir_type *find_pointer_type_to_type(ir_type *tp);
2122
2123 /**
2124  * @page primitive_type Representation of a primitive type
2125  *
2126  * Primitive types are types that represent atomic data values that
2127  * map directly to modes.  They don't have private attributes.  The
2128  * important information they carry is held in the common mode field.
2129  */
2130 /** Creates a new primitive type. */
2131 ir_type *new_type_primitive(ir_mode *mode);
2132
2133 /** Creates a new primitive type with debug information. */
2134 ir_type *new_d_type_primitive(ir_mode *mode, type_dbg_info* db);
2135
2136 /** Returns true if a type is a primitive type. */
2137 int is_Primitive_type(const ir_type *primitive);
2138
2139 /** Return the base type of a primitive (bitfield) type or NULL if none. */
2140 ir_type *get_primitive_base_type(const ir_type *tp);
2141
2142 /** Sets the base type of a primitive (bitfield) type. */
2143 void set_primitive_base_type(ir_type *tp, ir_type *base_tp);
2144
2145 /**
2146  * @page none_type The None type
2147  *
2148  *  This type is an auxiliary type dedicated to support type analyses.
2149  *
2150  *  The none type represents that there is no type.  The type can be used to
2151  *  initialize fields of type* that actually can not contain a type or that
2152  *  are initialized for an analysis. There exists exactly one type none.
2153  *  This type is not on the type list in ir_prog. It is
2154  *  allocated when initializing the type module.
2155  *
2156  *  The following values are set:
2157  *    - mode:  mode_BAD
2158  *    - name:  "type_none"
2159  *    - state: layout_fixed
2160  *    - size:  0
2161  */
2162 /** A variable that contains the only none type. */
2163 extern ir_type *firm_none_type;
2164
2165 /** A variable that contains the only code type. */
2166 extern ir_type *firm_code_type;
2167
2168 /** Returns the none type. */
2169 ir_type *get_none_type(void);
2170 /** Returns the code type. */
2171 ir_type *get_code_type(void);
2172
2173 /**
2174  * @page unknown_type  The Unknown type
2175  *
2176  *  This type is an auxiliary type dedicated to support type analyses.
2177  *
2178  *  The unknown type represents that there could be a type, but it is not
2179  *  known.  This type can be used to initialize fields before an analysis (not known
2180  *  yet) or to represent the top of a lattice (could not be determined).  There exists
2181  *  exactly one type unknown. This type is not on the type list in ir_prog.  It is
2182  *  allocated when initializing the type module.
2183  *
2184  *  The following values are set:
2185  *    - mode:  mode_ANY
2186  *    - name:  "type_unknown"
2187  *    - state: layout_fixed
2188  *    - size:  0
2189  */
2190 /** A variable that contains the only unknown type. */
2191 extern ir_type *firm_unknown_type;
2192
2193 /** Returns the unknown type. */
2194 ir_type *get_unknown_type(void);
2195
2196
2197 /**
2198  *  Checks whether a type is atomic.
2199  *  @param tp   any type
2200  *  @return true if type is primitive, pointer or enumeration
2201  */
2202 int is_atomic_type(const ir_type *tp);
2203
2204 /* --- Support for compound types --- */
2205
2206 /**
2207  * Gets the identifier of a compound type
2208  */
2209 ident *get_compound_ident(const ir_type *tp);
2210
2211 /** return compound identifier as c-string */
2212 const char *get_compound_name(const ir_type *tp);
2213
2214 /**
2215  * Gets the number of elements in a Firm compound type.
2216  *
2217  * This is just a comfortability function, because structs and
2218  * classes can often be treated be the same code, but they have
2219  * different access functions to their members.
2220  *
2221  * @param tp  The type (must be struct, union or class).
2222  *
2223  * @return Number of members in the compound type.
2224  */
2225 int get_compound_n_members(const ir_type *tp);
2226
2227 /**
2228  * Gets the member of a Firm compound type at position pos.
2229  *
2230  * @param tp  The type (must be struct, union or class).
2231  * @param pos The number of the member.
2232  *
2233  * @return The member entity at position pos.
2234  *
2235  * @see get_compound_n_members() for justification of existence.
2236  */
2237 ir_entity *get_compound_member(const ir_type *tp, int pos);
2238
2239 /** Returns index of member in tp, -1 if not contained. */
2240 int get_compound_member_index(const ir_type *tp, ir_entity *member);
2241
2242 /**
2243  * Checks whether a type is a compound type.
2244  *
2245  * @param tp - any type
2246  *
2247  * @return true if the type is class, structure, union or array type.
2248  */
2249 int is_compound_type(const ir_type *tp);
2250
2251 /**
2252  * Checks wether a type is a code type.
2253  */
2254 int is_code_type(const ir_type *tp);
2255
2256 /**
2257  * Checks, whether a type is a frame type.
2258  */
2259 int is_frame_type(const ir_type *tp);
2260
2261 /**
2262  * Checks, whether a type is a value parameter type.
2263  */
2264 int is_value_param_type(const ir_type *tp);
2265
2266 /**
2267  * Checks, whether a type is a lowered type.
2268  */
2269 int is_lowered_type(const ir_type *tp);
2270
2271 /**
2272  * Makes a new value type. Value types are struct types,
2273  * so all struct access functions work.
2274  * Value types are not in the global list of types.
2275  */
2276 ir_type *new_type_value(void);
2277
2278 /**
2279  * Makes a new frame type. Frame types are class types,
2280  * so all class access functions work.
2281  * Frame types are not in the global list of types.
2282  */
2283 ir_type *new_type_frame(void);
2284
2285 /**
2286  * Makes a clone of a frame type.
2287  * Sets entity links from old frame entities to new onces and
2288  * vice versa.
2289  */
2290 ir_type *clone_frame_type(ir_type *type);
2291
2292 /**
2293  * Sets a lowered type for a type. This sets both associations
2294  * and marks lowered_type as a "lowered" one.
2295  */
2296 void set_lowered_type(ir_type *tp, ir_type *lowered_type);
2297
2298 /**
2299  * Gets the lowered/unlowered type of a type or NULL if this type
2300  * has no lowered/unlowered one.
2301  */
2302 ir_type *get_associated_type(const ir_type *tp);
2303
2304 /**
2305  * Allocate an area of size bytes aligned at alignment
2306  * at the start or the end of a frame type.
2307  * The frame type must already have a fixed layout.
2308  *
2309  * @param frame_type a frame type
2310  * @param size       the size of the entity
2311  * @param alignment  the alignment of the entity
2312  * @param at_start   if true, put the area at the frame type's start, else at end
2313  *
2314  * @return the entity representing the area
2315  */
2316 ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, int at_start);
2317
2318 /*-----------------------------------------------------------------*/
2319 /** Debug aides                                                   **/
2320 /*-----------------------------------------------------------------*/
2321
2322 /**
2323  *  Outputs a unique number for this type if libfirm is compiled for
2324  *  debugging, (configure with --enable-debug) else returns the address
2325  *  of the type cast to long.
2326  */
2327 long get_type_nr(const ir_type *tp);
2328
2329 /* ------------------------------------------------------------------------ */
2330
2331 /**  Type for a function that compares two types.
2332  *
2333  *   @param tp1  The first type to compare.
2334  *   @param tp2  The second type to compare.
2335  */
2336 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
2337
2338 /** Compares two types by their name.
2339  *
2340  * Compares the opcode and the name of the types. If these are
2341  * equal returns 0, else non-zero.
2342  */
2343 int compare_names(const void *tp1, const void *tp2);
2344
2345 /** Compares two types strict.
2346  *
2347  * returns 0 if tp1 == tp2, else non-zero
2348  */
2349 int compare_strict(const void *tp1, const void *tp2);
2350
2351 /* ------------------------------------------------------------------------ */
2352
2353 /** Computes a hash value by the type name.
2354  *
2355  * Uses the name of the type and the type opcode to compute the hash.
2356  */
2357 int firm_hash_name(ir_type *tp);
2358
2359 /* ------------------------------------------------------------------------ */
2360
2361 /** Finalize type construction.
2362  *
2363  * Indicate that a type is so far completed that it can be
2364  * distinguished from other types.  Mature_type hashes the type into a
2365  * table.  It uses the function in compare_types_func to compare the
2366  * types.
2367  *
2368  * If it finds a type identical to tp it returns this type.  It turns
2369  * tp into the Id type.  All places formerly pointing to tp will now
2370  * point to the found type.  All entities of tp now refer to the found
2371  * type as their owner, but they are not a member of this type.  This
2372  * is invalid firm -- the entities must be replaced by entities of the
2373  * found type.  The Id type will be removed from the representation
2374  * automatically, but within an unknown time span.  It occupies memory
2375  * for this time.
2376  *
2377  * @param tp     The type to mature.
2378  */
2379 ir_type *mature_type(ir_type *tp);
2380
2381 /** Finalize type construction.
2382  *
2383  * Indicate that a type is so far completed that it can be
2384  * distinguished from other types.  mature_type() hashes the type into a
2385  * table.  It uses the function in compare_types_func to compare the
2386  * types.
2387  *
2388  * If it finds a type identical to tp it returns this type.  It frees
2389  * type tp and all its entities.
2390  *
2391  * @param tp     The type to mature.
2392  */
2393 ir_type *mature_type_free(ir_type *tp);
2394
2395 /** Finalize type construction.
2396  *
2397  * Indicate that a type is so far completed that it can be
2398  * distinguished from other types.  Mature_type hashes the type into a
2399  * table.  It uses the function in compare_types_func to compare the
2400  * types.
2401  *
2402  * If it find a type identical to tp it returns this type.  It frees
2403  * the entities and turns the type into an Id type.  All places
2404  * formerly pointing to tp will now point to the found type.  The Id
2405  * type will be removed from the representation automatically, but
2406  * within an unknown time span.  It occupies memory for this time.
2407  *
2408  * @param tp     The type to mature.
2409  */
2410 ir_type *mature_type_free_entities(ir_type *tp);
2411
2412 /** A data type to treat types and entities as the same. */
2413 typedef union {
2414         ir_type   *typ;   /**< points to a type */
2415         ir_entity *ent;   /**< points to an entity */
2416 } type_or_ent;
2417
2418 /** Type of argument functions for type walkers.
2419  *
2420  * @param tore    points to the visited type or entity
2421  * @param env     free environment pointer
2422  */
2423 typedef void type_walk_func(type_or_ent tore, void *env);
2424
2425 /**  The class walk function
2426  *
2427  * @param clss    points to the visited class
2428  * @param env     free environment pointer
2429  */
2430 typedef void class_walk_func(ir_type *clss, void *env);
2431
2432 /** Touches every type and entity in unspecified order.  If new
2433  *  types/entities are created during the traversal these will
2434  *  be visited, too.
2435  *  Does not touch frame types or types for value params ... */
2436 void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
2437
2438 /** Touches every type, entity, frame type, and value param type in
2439  *  unspecified order (also all segment types). */
2440 void type_walk_prog(type_walk_func *pre, type_walk_func *post, void *env);
2441
2442 /** Walks over all type information reachable from an ir graph.
2443  *
2444  *  Walks over all type information reachable from irg, i.e., starts a
2445  *  type walk at the irgs entity, the irgs frame type and all types and
2446  *  entities that are attributes to firm nodes. */
2447 void type_walk_irg(ir_graph *irg, type_walk_func *pre, type_walk_func *post,
2448                    void *env);
2449
2450 /**
2451     Touches every class in specified order:
2452     - first the super class
2453     - second the class itself
2454     - third the sub classes.  If new classes are created
2455     during the traversal these will be visited, too.
2456
2457     @todo should be named class-walk
2458
2459     @deprecated will be removed?
2460 */
2461 void type_walk_super2sub(type_walk_func *pre, type_walk_func *post, void *env);
2462
2463 /** Walker for class types in inheritance order.
2464  *
2465  *  Touches every class in specified order:
2466  *   - first the super class
2467  *   - second the class itself
2468  *   If new classes are created during the traversal these
2469  *   will be visited, too.
2470  * Starts the walk at arbitrary classes.
2471  * Executes pre when first visiting a class.  Executes post after
2472  * visiting all superclasses.
2473  *
2474  * The arguments pre, post, env may be NULL. */
2475 void type_walk_super(type_walk_func *pre, type_walk_func *post, void *env);
2476
2477 /** Same as type_walk_super2sub, but visits only class types.
2478    Executes pre for a class if all superclasses have been visited.
2479    Then iterates to subclasses.  Executes post after return from
2480    subclass.
2481    Does not visit global type, frame types.
2482 */
2483 void class_walk_super2sub(class_walk_func *pre, class_walk_func *post,
2484                           void *env);
2485
2486 /**
2487  * the entity walk function.  A function type for entity walkers.
2488  *
2489  * @param ent     points to the visited entity
2490  * @param env     free environment pointer
2491  */
2492 typedef void entity_walk_func(ir_entity *ent, void *env);
2493
2494 /**
2495  * Walks over all entities in the type.
2496  *
2497  * @param tp    the type
2498  * @param doit  the entity walker function
2499  * @param env   environment, will be passed to the walker function
2500  */
2501 void walk_types_entities(ir_type *tp, entity_walk_func *doit, void *env);
2502
2503 /**
2504  * layout members of a struct/union or class type in a default way.
2505  */
2506 void default_layout_compound_type(ir_type *tp);
2507
2508 /**
2509  * If we have the closed world assumption, we can calculate the
2510  * finalization of classes and entities by inspecting the class hierarchy.
2511  * After this is done, all classes and entities that are not overridden
2512  * anymore have the final property set.
2513  */
2514 void types_calc_finalization(void);
2515
2516 #endif