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