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