2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Declarations for functions and datastructures to represent types
24 #ifndef FIRM_TYPEREP_H
25 #define FIRM_TYPEREP_H
28 #include "firm_types.h"
33 * @page entity Entity representation
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.
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
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.
52 * The type ir_entity is an abstract data type to represent program entities.
53 * If contains the following attributes:
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
72 * - visited: visited flag. Master flag is type_visited.
74 * These fields can only be accessed via access functions.
76 * @see ir_type, ir_entity
80 * Visibility classed for entities.
84 * The entity is visible outside the compilation unit, but it is defined
87 ir_visibility_default,
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
96 * The entity is defined outside the compilation unit but potentially used
99 ir_visibility_external,
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
107 ir_visibility_private
111 * linkage specifies how the linker treats symbols
113 typedef enum ir_linkage {
114 IR_LINKAGE_DEFAULT = 0,
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.
121 IR_LINKAGE_CONSTANT = 1 << 0,
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
128 IR_LINKAGE_WEAK = 1 << 1,
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).
134 IR_LINKAGE_GARBAGE_COLLECT = 1 << 2,
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)
141 IR_LINKAGE_MERGE = 1 << 3,
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.
150 IR_LINKAGE_HIDDEN_USER = 1 << 4
152 ENUM_BITSET(ir_linkage)
155 * Return the visibility class of an entity
157 FIRM_API ir_visibility get_entity_visibility(const ir_entity *entity);
160 * Set visibility class of an entity
162 FIRM_API void set_entity_visibility(ir_entity *entity, ir_visibility visibility);
165 * Return 1 if the entity is visible outside the current compilation unit
166 * or to unknown callers (like asm statements).
167 * (The entity might still be accessible indirectly through pointers)
168 * This is a convenience function and does the same as
169 * get_entity_visibility(entity) != ir_visibility_local ||
170 * (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER)
172 FIRM_API int entity_is_externally_visible(const ir_entity *entity);
175 * Return 1 if the entity has a definition (initializer) in the current
178 FIRM_API int entity_has_definition(const ir_entity *entity);
181 * Creates a new entity.
183 * Automatically inserts the entity as a member of owner.
184 * Entity is automatic_allocated and uninitialized except if the type
185 * is type_method, then it is static_allocated and constant. The constant
186 * value is a pointer to the method.
187 * Visibility is local, offset -1, and it is not volatile.
189 FIRM_API ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp);
192 * Creates a new entity.
194 * Automatically inserts the entity as a member of owner.
195 * The entity is automatic allocated and uninitialized except if the type
196 * is type_method, then it is static allocated and constant. The constant
197 * value is a pointer to the method.
198 * Visibility is local, offset -1, and it is not volatile.
200 FIRM_API ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp,
204 * Copies the entity if the new_owner is different from the
205 * owner of the old entity, else returns the old entity.
207 * Automatically inserts the new entity as a member of owner.
208 * Resets the overwrites/overwritten_by fields.
209 * Keeps the old atomic value.
211 FIRM_API ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner);
214 * Copies the entity if the new_name is different from the
215 * name of the old entity, else returns the old entity.
217 * Automatically inserts the new entity as a member of owner.
218 * The mangled name ld_name is set to NULL.
219 * Overwrites relation is copied from old.
221 FIRM_API ir_entity *copy_entity_name(ir_entity *old, ident *new_name);
226 * The owner will still contain the pointer to this
227 * entity, as well as all other references!
229 FIRM_API void free_entity(ir_entity *ent);
231 /** Returns the name of an entity. */
232 FIRM_API const char *get_entity_name(const ir_entity *ent);
234 /** Returns the ident of an entity. */
235 FIRM_API ident *get_entity_ident(const ir_entity *ent);
237 /** Sets the ident of the entity. */
238 FIRM_API void set_entity_ident(ir_entity *ent, ident *id);
240 /** Returns the mangled name of the entity.
242 * If the mangled name is set it returns the existing name.
243 * Else it generates a name with mangle_entity()
244 * and remembers this new name internally.
246 FIRM_API ident *get_entity_ld_ident(const ir_entity *ent);
248 /** Sets the mangled name of the entity. */
249 FIRM_API void set_entity_ld_ident(ir_entity *ent, ident *ld_ident);
251 /** Returns the mangled name of the entity as a string. */
252 FIRM_API const char *get_entity_ld_name(const ir_entity *ent);
254 /** returns 1 if the entity has an ld_ident set explicitely */
255 FIRM_API int entity_has_ld_ident(const ir_entity *entity);
257 /** Returns the owner of the entity. */
258 FIRM_API ir_type *get_entity_owner(const ir_entity *ent);
261 * Sets the owner field in entity to owner.
262 * Automatically removes entity from old owner type and adds it to the new
265 FIRM_API void set_entity_owner(ir_entity *ent, ir_type *owner);
267 /** Returns the type of an entity. */
268 FIRM_API ir_type *get_entity_type(const ir_entity *ent);
270 /** Sets the type of an entity. */
271 FIRM_API void set_entity_type(ir_entity *ent, ir_type *tp);
273 /** Returns the linkage of an entity. */
274 FIRM_API ir_linkage get_entity_linkage(const ir_entity *entity);
276 /** Sets the linkage of an entity. */
277 FIRM_API void set_entity_linkage(ir_entity *entity, ir_linkage linkage);
278 FIRM_API void add_entity_linkage(ir_entity *entity, ir_linkage linkage);
279 FIRM_API void remove_entity_linkage(ir_entity *entity, ir_linkage linkage);
282 * This enumeration flags the volatility of entities and Loads/Stores.
286 volatility_non_volatile, /**< The entity is not volatile. Default. */
287 volatility_is_volatile /**< The entity is volatile. */
291 * Returns the volatility of an entity.
294 FIRM_API ir_volatility get_entity_volatility(const ir_entity *ent);
297 * Sets the volatility of an entity.
300 FIRM_API void set_entity_volatility(ir_entity *ent, ir_volatility vol);
302 /** Return the name of the volatility. */
303 FIRM_API const char *get_volatility_name(ir_volatility var);
305 /** Returns alignment of entity in bytes */
306 FIRM_API unsigned get_entity_alignment(const ir_entity *entity);
308 /** Allows you to override the type alignment for an entity.
309 * @param entity the entity
310 * @param alignment alignment in bytes
312 FIRM_API void set_entity_alignment(ir_entity *entity, unsigned alignment);
316 * This enumeration flags the align of Loads/Stores.
320 align_non_aligned, /**< The entity is not aligned. */
321 align_is_aligned /**< The entity is aligned. Default */
325 * Returns indication wether entity is aligned in memory.
328 FIRM_API ir_align get_entity_aligned(const ir_entity *ent);
331 * Sets indication wether entity is aligned in memory
334 FIRM_API void set_entity_aligned(ir_entity *ent, ir_align a);
336 /** Return the name of the alignment. */
337 FIRM_API const char *get_align_name(ir_align a);
339 /** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */
340 FIRM_API int get_entity_offset(const ir_entity *ent);
342 /** Sets the offset of an entity (in a compound) in bytes. */
343 FIRM_API void set_entity_offset(ir_entity *ent, int offset);
345 /** Returns the offset bit remainder of a bitfield entity (in a compound) in bits. Only set if layout = fixed. */
346 FIRM_API unsigned char get_entity_offset_bits_remainder(const ir_entity *ent);
348 /** Sets the offset bit remainder of a bitfield entity (in a compound) in bits. */
349 FIRM_API void set_entity_offset_bits_remainder(ir_entity *ent,
350 unsigned char offset);
352 /** Returns the stored intermediate information. */
353 FIRM_API void *get_entity_link(const ir_entity *ent);
355 /** Stores new intermediate information. */
356 FIRM_API void set_entity_link(ir_entity *ent, void *l);
358 /* -- Fields of method entities -- */
359 /** The entity knows the corresponding irg if the entity is a method.
360 This allows to get from a Call to the called irg. */
361 FIRM_API ir_graph *get_entity_irg(const ir_entity *ent);
362 FIRM_API void set_entity_irg(ir_entity *ent, ir_graph *irg);
364 /** A reserved value for "not yet set". */
365 #define IR_VTABLE_NUM_NOT_SET ((unsigned)(-1))
367 /** Gets the entity vtable number. */
368 FIRM_API unsigned get_entity_vtable_number(const ir_entity *ent);
370 /** Sets the entity vtable number. */
371 FIRM_API void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number);
373 /** Set label number of an entity with code type */
374 FIRM_API void set_entity_label(ir_entity *ent, ir_label_t label);
375 /** Return label number of an entity with code type */
376 FIRM_API ir_label_t get_entity_label(const ir_entity *ent);
378 /** Checks if an entity is compiler generated. */
379 FIRM_API int is_entity_compiler_generated(const ir_entity *ent);
381 /** Sets/resets the compiler generated flag. */
382 FIRM_API void set_entity_compiler_generated(ir_entity *ent, int flag);
385 * Bitfield type indicating the way an entity is used.
388 ir_usage_none = 0, /**< This entity is unused. */
389 ir_usage_address_taken = 1 << 0, /**< The address of this entity was taken. */
390 ir_usage_write = 1 << 1, /**< The entity was written to. */
391 ir_usage_read = 1 << 2, /**< The entity was read. */
392 ir_usage_reinterpret_cast = 1 << 3, /**< The entity was read but with a wrong mode
393 (an implicit reinterpret cast) */
394 /** Unknown access */
396 = ir_usage_address_taken | ir_usage_write | ir_usage_read
397 | ir_usage_reinterpret_cast
400 /** Return the entity usage */
401 FIRM_API ir_entity_usage get_entity_usage(const ir_entity *ent);
403 /** Sets/resets the state of the address taken flag of an entity. */
404 FIRM_API void set_entity_usage(ir_entity *ent, ir_entity_usage flag);
407 * Returns the debug information of an entity.
409 * @param ent The entity.
411 FIRM_API dbg_info *get_entity_dbg_info(const ir_entity *ent);
414 * Sets the debug information of an entity.
416 * @param ent The entity.
417 * @param db The debug info.
419 FIRM_API void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
421 /* -- Representation of constant values of entities -- */
423 * Returns true if the the node is representable as code on
426 * @deprecated This function is not used by libFirm and stays here
427 * only as a helper for the old Jack frontend.
429 FIRM_API int is_irn_const_expression(ir_node *n);
432 * Copies a Firm subgraph that complies to the restrictions for
433 * constant expressions to block.
435 * @param dbg debug info for all newly created nodes
438 * Set current_ir_graph to get_const_code_irg() to generate a constant
441 FIRM_API ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *to_block);
443 /* Set has no effect for existent entities of type method. */
444 FIRM_API ir_node *get_atomic_ent_value(ir_entity *ent);
445 FIRM_API void set_atomic_ent_value(ir_entity *ent, ir_node *val);
447 /** the kind (type) of an initializer */
448 typedef enum ir_initializer_kind_t {
449 /** initializer containing an ir_node from the const-code irg */
450 IR_INITIALIZER_CONST,
451 /** initializer containing a tarval */
452 IR_INITIALIZER_TARVAL,
453 /** initializes type with default values (usually 0) */
455 /** list of initializers used to initializer a compound or array type */
456 IR_INITIALIZER_COMPOUND
457 } ir_initializer_kind_t;
459 /** returns kind of an initializer */
460 FIRM_API ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer);
462 /** Return the name of the initializer kind. */
463 FIRM_API const char *get_initializer_kind_name(ir_initializer_kind_t ini);
466 * returns the null initializer (there's only one instance of it in a program )
468 FIRM_API ir_initializer_t *get_initializer_null(void);
471 * creates an initializer containing a reference to a node on the const-code
474 FIRM_API ir_initializer_t *create_initializer_const(ir_node *value);
476 /** creates an initializer containing a single tarval value */
477 FIRM_API ir_initializer_t *create_initializer_tarval(ir_tarval *tv);
479 /** return value contained in a const initializer */
480 FIRM_API ir_node *get_initializer_const_value(const ir_initializer_t *initializer);
482 /** return value contained in a tarval initializer */
483 FIRM_API ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initialzier);
485 /** creates a compound initializer which holds @p n_entries entries */
486 FIRM_API ir_initializer_t *create_initializer_compound(unsigned n_entries);
488 /** returns the number of entries in a compound initializer */
489 FIRM_API unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer);
491 /** sets entry with index @p index to the initializer @p value */
492 FIRM_API void set_initializer_compound_value(ir_initializer_t *initializer,
494 ir_initializer_t *value);
496 /** returns the value with index @p index of a compound initializer */
497 FIRM_API ir_initializer_t *get_initializer_compound_value(
498 const ir_initializer_t *initializer, unsigned index);
500 /** Sets the new style initializers of an entity. */
501 FIRM_API void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer);
503 /** Returns true, if an entity has new style initializers. */
504 FIRM_API int has_entity_initializer(const ir_entity *entity);
506 /** Return the new style initializers of an entity. */
507 FIRM_API ir_initializer_t *get_entity_initializer(const ir_entity *entity);
509 /* --- Fields of entities with a class type as owner --- */
510 /* Overwrites is a field that specifies that an access to the overwritten
511 entity in the supertype must use this entity. It's a list as with
512 multiple inheritance several entities can be overwritten. This field
513 is mostly useful for method entities.
514 If a Sel node selects an entity that is overwritten by other entities it
515 must return a pointer to the entity of the dynamic type of the pointer
516 that is passed to it. Lowering of the Sel node must assure this.
517 Overwrittenby is the inverse of overwrites. Both add routines add
518 both relations, they only differ in the order of arguments. */
519 FIRM_API void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
520 FIRM_API int get_entity_n_overwrites(const ir_entity *ent);
521 FIRM_API int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten);
522 FIRM_API ir_entity *get_entity_overwrites(const ir_entity *ent, int pos);
523 FIRM_API void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten);
524 FIRM_API void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
526 FIRM_API int get_entity_n_overwrittenby(const ir_entity *ent);
527 FIRM_API int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites);
528 FIRM_API ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos);
529 FIRM_API void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites);
530 FIRM_API void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
533 * Checks whether a pointer points to an entity.
535 * @param thing an arbitrary pointer
538 * true if the thing is an entity, else false
540 FIRM_API int is_entity(const void *thing);
542 /** Returns true if the type of the entity is a primitive, pointer
543 * enumeration or method type.
545 * @note This is a different classification than from is_primitive_type().
547 FIRM_API int is_atomic_entity(const ir_entity *ent);
548 /** Returns true if the type of the entity is a class, structure,
549 array or union type. */
550 FIRM_API int is_compound_entity(const ir_entity *ent);
551 /** Returns true if the type of the entity is a Method type. */
552 FIRM_API int is_method_entity(const ir_entity *ent);
554 /** Outputs a unique number for this entity if libfirm is compiled for
555 * debugging, (configure with --enable-debug) else returns the address
556 * of the type cast to long.
558 FIRM_API long get_entity_nr(const ir_entity *ent);
560 /** Returns the entities visited count. */
561 FIRM_API ir_visited_t get_entity_visited(const ir_entity *ent);
563 /** Sets the entities visited count. */
564 FIRM_API void set_entity_visited(ir_entity *ent, ir_visited_t num);
566 /** Sets visited field in entity to entity_visited. */
567 FIRM_API void mark_entity_visited(ir_entity *ent);
569 /** Returns true if this entity was visited. */
570 FIRM_API int entity_visited(const ir_entity *ent);
572 /** Returns true if this entity was not visited. */
573 FIRM_API int entity_not_visited(const ir_entity *ent);
576 * Returns the mask of the additional entity properties.
577 * The properties are automatically inherited from the irg if available
578 * or from the method type if they were not set using
579 * set_entity_additional_properties() or
580 * set_entity_additional_property().
582 FIRM_API mtp_additional_properties get_entity_additional_properties(const ir_entity *ent);
584 /** Sets the mask of the additional graph properties. */
585 FIRM_API void set_entity_additional_properties(ir_entity *ent,
586 mtp_additional_properties prop);
588 /** Sets additional graph properties. */
589 FIRM_API void add_entity_additional_properties(ir_entity *ent,
590 mtp_additional_properties flag);
592 /** Returns the class type that this type info entity represents or NULL
593 if ent is no type info entity. */
594 FIRM_API ir_type *get_entity_repr_class(const ir_entity *ent);
597 * @page unknown_entity The Unknown entity
599 * This entity is an auxiliary entity dedicated to support analyses.
601 * The unknown entity represents that there could be an entity, but it is not
602 * known. This entity can be used to initialize fields before an analysis (not known
603 * yet) or to represent the top of a lattice (could not be determined). There exists
604 * exactly one entity unknown. This entity has as owner and as type the unknown type. It is
605 * allocated when initializing the entity module.
607 * The entity can take the role of any entity, also methods. It returns default
608 * values in these cases.
610 * The following values are set:
612 * - name = "unknown_entity"
613 * - ld_name = "unknown_entity"
614 * - owner = unknown_type
615 * - type = unknown_type
617 * - value = SymConst(unknown_entity)
620 * - volatility = volatility_non_volatile
621 * - stickyness = stickyness_unsticky
623 * - overwrites = NULL
624 * - overwrittenby = NULL
629 /** A variable that contains the only unknown entity. */
630 FIRM_API ir_entity *unknown_entity;
632 /** Returns the @link unknown_entity unknown entity @endlink. */
633 FIRM_API ir_entity *get_unknown_entity(void);
635 /** Encodes how a pointer parameter is accessed. */
636 typedef enum ptr_access_kind {
637 ptr_access_none = 0, /**< no access */
638 ptr_access_read = 1, /**< read access */
639 ptr_access_write = 2, /**< write access */
640 ptr_access_rw = ptr_access_read|ptr_access_write, /**< read AND write access */
641 ptr_access_store = 4, /**< the pointer is stored */
642 ptr_access_all = ptr_access_rw|ptr_access_store /**< all possible access */
644 ENUM_BITSET(ptr_access_kind)
646 #define IS_READ(a) ((a) & ptr_access_read)
647 #define IS_WRITTEN(a) ((a) & ptr_access_write)
648 #define IS_STORED(a) ((a) & ptr_access_store)
651 * @page tyop type operations
652 * This module specifies the kinds of types available in firm.
654 * They are called type opcodes. These include classes, structs, methods, unions,
655 * arrays, enumerations, pointers and primitive types.
656 * Special types with own opcodes are the id type, a type representing an unknown
657 * type and a type used to specify that something has no type.
661 * An enum for the type kinds.
662 * For each type kind exists a typecode to identify it.
665 tpo_uninitialized = 0, /* not a type opcode */
666 tpo_class, /**< A class type. */
667 tpo_struct, /**< A struct type. */
668 tpo_method, /**< A method type. */
669 tpo_union, /**< An union type. */
670 tpo_array, /**< An array type. */
671 tpo_enumeration, /**< An enumeration type. */
672 tpo_pointer, /**< A pointer type. */
673 tpo_primitive, /**< A primitive type. */
674 tpo_code, /**< a piece of code (a basic block) */
675 tpo_none, /**< Special type for the None type. */
676 tpo_unknown, /**< Special code for the Unknown type. */
677 tpo_last = tpo_unknown /* not a type opcode */
681 * A structure containing information about a kind of type.
682 * A structure containing information about a kind of type. So far
683 * this is only the kind name, an enum for case-switching and some
686 * @see get_tpop_name(), get_tpop_code()
688 typedef struct tp_op tp_op;
692 * Returns the string for the type opcode.
694 * @param op The type opcode to get the string from.
697 FIRM_API const char *get_tpop_name(const tp_op *op);
700 * Returns an enum for the type opcode.
702 * @param op The type opcode to get the enum from.
705 FIRM_API tp_opcode get_tpop_code(const tp_op *op);
708 * This type opcode marks that the corresponding type is a class type.
710 * Consequently the type refers to supertypes, subtypes and entities.
711 * Entities can be any fields, but also methods.
712 * @@@ value class or not???
713 * This struct is dynamically allocated but constant for the lifetime
716 FIRM_API const tp_op *type_class;
717 FIRM_API const tp_op *get_tpop_class(void);
720 * This type opcode marks that the corresponding type is a compound type
723 * Consequently the type refers to a list of entities
724 * which may not be methods (but pointers to methods).
725 * This struct is dynamically allocated but constant for the lifetime
728 FIRM_API const tp_op *type_struct;
729 FIRM_API const tp_op *get_tpop_struct(void);
732 * This type opcode marks that the corresponding type is a method type.
734 * Consequently it refers to a list of arguments and results.
735 * This struct is dynamically allocated but constant for the lifetime
738 FIRM_API const tp_op *type_method;
739 FIRM_API const tp_op *get_tpop_method(void);
742 * This type opcode marks that the corresponding type is a union type.
744 * Consequently it refers to a list of unioned types.
745 * This struct is dynamically allocated but constant for the lifetime
748 FIRM_API const tp_op *type_union;
749 FIRM_API const tp_op *get_tpop_union(void);
752 * This type opcode marks that the corresponding type is an array type.
754 * Consequently it contains a list of dimensions (lower and upper bounds)
755 * and an element type.
756 * This struct is dynamically allocated but constant for the lifetime
759 FIRM_API const tp_op *type_array;
760 FIRM_API const tp_op *get_tpop_array(void);
763 * This type opcode marks that the corresponding type is an enumeration type.
765 * Consequently it contains a list of idents for the enumeration identifiers
766 * and a list of target values that are the constants used to implement
768 * This struct is dynamically allocated but constant for the lifetime
771 FIRM_API const tp_op *type_enumeration;
772 FIRM_API const tp_op *get_tpop_enumeration(void);
775 * This type opcode marks that the corresponding type is a pointer type.
777 * It contains a reference to the type the pointer points to.
778 * This struct is dynamically allocated but constant for the lifetime
781 FIRM_API const tp_op *type_pointer;
782 FIRM_API const tp_op *get_tpop_pointer(void);
785 * This type opcode marks that the corresponding type is a primitive type.
787 * Primitive types are types that are directly mapped to target machine
789 * This struct is dynamically allocated but constant for the lifetime
792 FIRM_API const tp_op *type_primitive;
793 FIRM_API const tp_op *get_tpop_primitive(void);
796 * The code type is used to mark pieces of code (basic blocks)
798 FIRM_API const tp_op *tpop_code;
799 FIRM_API const tp_op *get_tpop_code_type(void);
802 * This type opcode is an auxiliary opcode dedicated to support type analyses.
804 * Types with this opcode represents that there is no type.
805 * The type can be used to initialize fields of the type* that actually can not
806 * contain a type or that are initialized for an analysis. There exists exactly
807 * one type with this opcode.
809 FIRM_API const tp_op *tpop_none;
810 FIRM_API const tp_op *get_tpop_none(void);
813 * This type opcode is an auxiliary opcode dedicated to support type analyses.
815 * Types with this opcode represents that there could be a type, but it is not
816 * known. This type can be used to initialize fields before an analysis (not known
817 * yet) or to represent the top of a lattice (could not be determined). There exists
818 * exactly one type with this opcode.
820 FIRM_API const tp_op *tpop_unknown;
821 FIRM_API const tp_op *get_tpop_unknown(void);
823 /* ----------------------------------------------------------------------- */
824 /* Classify pairs of types/entities in the inheritance relations. */
825 /* ----------------------------------------------------------------------- */
827 /** Returns true if low is subclass of high.
829 * Low is a subclass of high if low == high or if low is a subclass of
830 * a subclass of high. I.e, we search in all subtypes of high for low.
831 * @@@ this can be implemented more efficient if we know the set of all
832 * subclasses of high. */
833 FIRM_API int is_SubClass_of(ir_type *low, ir_type *high);
835 /** Subclass check for pointers to classes.
837 * Dereferences at both types the same amount of pointer types (as
838 * many as possible). If the remaining types are both class types
839 * and subclasses, returns true, else false. Can also be called with
840 * two class types. */
841 FIRM_API int is_SubClass_ptr_of(ir_type *low, ir_type *high);
843 /** Returns true if high is superclass of low.
845 * Low is a subclass of high if low == high or if low is a subclass of
846 * a subclass of high. I.e, we search in all subtypes of high for low.
847 * @@@ this can be implemented more efficient if we know the set of all
848 * subclasses of high. */
849 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
851 /** Superclass check for pointers to classes.
853 * Dereferences at both types the same amount of pointer types (as
854 * many as possible). If the remaining types are both class types
855 * and superclasses, returns true, else false. Can also be called with
856 * two class types. */
857 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
859 /** Returns true if high is (transitive) overwritten by low.
861 * Returns false if high == low. */
862 FIRM_API int is_overwritten_by(ir_entity *high, ir_entity *low);
864 /** Resolve polymorphism in the inheritance relation.
866 * Returns the dynamically referenced entity if the static entity and the
867 * dynamic type are given.
868 * Searches downwards in overwritten tree. */
869 FIRM_API ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class,
870 ir_entity* static_ent);
872 /* ----------------------------------------------------------------------- */
873 /* Resolve implicit inheritance. */
874 /* ----------------------------------------------------------------------- */
876 /** Default name mangling for inherited entities.
878 * Returns an ident that consists of the name of type followed by an
879 * underscore and the name (not ld_name) of the entity. */
880 FIRM_API ident *default_mangle_inherited_name(const ir_entity *ent,
881 const ir_type *clss);
883 /** Type of argument functions for inheritance resolver.
885 * @param ent The entity in the super type that will be overwritten
886 * by the newly generated entity, for which this name is
888 * @param clss The class type in which the new entity will be placed.
890 typedef ident *mangle_inherited_name_func(const ir_entity *ent,
891 const ir_type *clss);
893 /** Resolve implicit inheritance.
895 * Resolves the implicit inheritance supplied by firm. Firm defines,
896 * that each entity that is not overwritten in a subclass is
897 * inherited to this subclass without change implicitly. This
898 * function generates entities that explicitly represent this
899 * inheritance. It generates for each entity overwriting entities in
900 * all subclasses of the owner of the entity, if the entity is not
901 * overwritten in that subclass.
903 * The name of the new entity is generated with the function passed.
904 * If the function is NULL, the default_mangle_inherited_name() is
907 FIRM_API void resolve_inheritance(mangle_inherited_name_func *mfunc);
910 /* ----------------------------------------------------------------------- */
911 /* The transitive closure of the subclass/superclass and */
912 /* overwrites/overwrittenby relation. */
914 /* A walk over the ir (O(#types+#entities)) computes the transitive */
915 /* closure. Adding a new type/entity or changing the basic relations in */
916 /* some other way invalidates the transitive closure, i.e., it is not */
917 /* updated by the basic functions. */
919 /* The transitive edges are held in a set, not in an array as the */
920 /* underlying relation. */
922 /* Do the sets contain the node itself? I assume NOT! */
923 /* ----------------------------------------------------------------------- */
926 * The state of the transitive closure.
929 inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */
930 inh_transitive_closure_valid, /**< Closure computed and valid. */
931 inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */
932 inh_transitive_closure_max /**< Invalid value. */
933 } inh_transitive_closure_state;
935 FIRM_API void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
936 FIRM_API void invalidate_irp_inh_transitive_closure_state(void);
937 FIRM_API inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
940 /** Compute transitive closure of the subclass/superclass and
941 * overwrites/overwrittenby relation.
943 * This function walks over the ir (O(\#types+\#entities)) to compute the
944 * transitive closure. */
945 FIRM_API void compute_inh_transitive_closure(void);
947 /** Free memory occupied by the transitive closure information. */
948 FIRM_API void free_inh_transitive_closure(void);
951 /* - subtype ------------------------------------------------------------- */
953 /** Iterate over all transitive subtypes. */
954 FIRM_API ir_type *get_class_trans_subtype_first(const ir_type *tp);
955 FIRM_API ir_type *get_class_trans_subtype_next(const ir_type *tp);
956 FIRM_API int is_class_trans_subtype(const ir_type *tp, const ir_type *subtp);
958 /* - supertype ----------------------------------------------------------- */
960 /** Iterate over all transitive supertypes. */
961 FIRM_API ir_type *get_class_trans_supertype_first(const ir_type *tp);
962 FIRM_API ir_type *get_class_trans_supertype_next(const ir_type *tp);
964 /* - overwrittenby ------------------------------------------------------- */
966 /** Iterate over all entities that transitive overwrite this entities. */
967 FIRM_API ir_entity *get_entity_trans_overwrittenby_first(const ir_entity *ent);
968 FIRM_API ir_entity *get_entity_trans_overwrittenby_next(const ir_entity *ent);
970 /* - overwrites ---------------------------------------------------------- */
972 /** Iterate over all transitive overwritten entities. */
973 FIRM_API ir_entity *get_entity_trans_overwrites_first(const ir_entity *ent);
974 FIRM_API ir_entity *get_entity_trans_overwrites_next(const ir_entity *ent);
977 /* ----------------------------------------------------------------------- */
978 /** The state of Cast operations that cast class types or pointers to class
981 * The state expresses, how far Cast operations conform with the class
985 * class B1 extends A {}
986 * class B2 extends A {}
987 * class C extends B1 {}
988 * normalized: Cast operations conform with the inheritance relation.
989 * I.e., the type of the operand of a Cast is either a super= or a sub-
990 * type of the type casted to. Example: (A)((B2) (new C())).
991 * transitive: Cast operations conform with the transitive inheritance
992 * relation. Example: (A)(new C()).
993 * any: Cast operations do not conform with the transitive inheritance
994 * relation. Example: (B2)(new B1())
996 /* ----------------------------------------------------------------------- */
998 /** Flags for class cast state.
1000 * The state in irp is always smaller or equal to the state of any
1003 * We rely on the ordering of the enum. */
1005 ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with
1006 the class hierarchy. @@@ So far this does not happen in Firm. */
1007 ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */
1008 ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */
1009 ir_class_casts_state_max
1010 } ir_class_cast_state;
1011 FIRM_API const char *get_class_cast_state_string(ir_class_cast_state s);
1013 FIRM_API void set_irg_class_cast_state(ir_graph *irg,
1014 ir_class_cast_state s);
1015 FIRM_API ir_class_cast_state get_irg_class_cast_state(const ir_graph *irg);
1016 FIRM_API void set_irp_class_cast_state(ir_class_cast_state s);
1017 FIRM_API ir_class_cast_state get_irp_class_cast_state(void);
1019 /** Verify the class cast state of an irg.
1021 * Asserts if state is to high, outputs debug warning if state is to low
1022 * and firm verbosity is set.
1024 FIRM_API void verify_irg_class_cast_state(ir_graph *irg);
1027 * possible trverify() error codes
1029 enum trverify_error_codes {
1030 no_error = 0, /**< no error */
1031 error_ent_not_cont, /**< overwritten entity not in superclass */
1032 error_null_mem, /**< compound contains NULL member */
1033 error_const_on_wrong_irg, /**< constant placed on wrong IRG */
1034 error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */
1035 error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */
1036 error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */
1037 error_glob_ent_allocation, /**< wrong allocation of a global entity */
1038 error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */
1039 error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */
1046 * 0 if no error encountered
1048 FIRM_API int check_type(ir_type *tp);
1051 * Check an entity. Currently, we check only if initialized constants
1052 * are build on the const irg graph.
1055 * 0 if no error encountered
1056 * != 0 a trverify_error_codes code
1058 FIRM_API int check_entity(ir_entity *ent);
1061 * Walks the type information and performs a set of sanity checks.
1063 * Currently, the following checks are executed:
1064 * - values of initialized entities must be allocated on the constant IRG
1065 * - class types: doesn't have NULL members
1066 * - class types: all overwrites are existent in the super type
1069 * 0 if graph is correct
1072 FIRM_API int tr_verify(void);
1075 * @page type representation of types
1077 * Datastructure to hold type information.
1079 * This module supplies a datastructure to represent all types
1080 * known in the compiled program. This includes types specified
1081 * in the program as well as types defined by the language. In the
1082 * view of the intermediate representation there is no difference
1083 * between these types. Finally it specifies some auxiliary types.
1085 * There exist several kinds of types, arranged by the structure of
1086 * the type. A type is described by a set of attributes. Some of
1087 * these attributes are common to all types, others depend on the
1090 * Types are different from the modes defined in irmode: Types are
1091 * on the level of the programming language, modes at the level of
1092 * the target processor.
1095 /** Frees all entities associated with a type.
1096 * Does not free the array entity.
1097 * Warning: ensure these entities are not referenced anywhere else.
1099 FIRM_API void free_type_entities(ir_type *tp);
1101 /** Frees the memory used by the type.
1103 * Removes the type from the type list. Does not free the entities
1104 * belonging to the type, except for the array element entity. Does
1105 * not free if tp is "none" or "unknown". Frees entities in value
1106 * param subtypes of method types!!! Make sure these are not
1107 * referenced any more. Further make sure there is no pointer type
1108 * that refers to this type. */
1109 FIRM_API void free_type(ir_type *tp);
1111 FIRM_API const tp_op *get_type_tpop(const ir_type *tp);
1112 FIRM_API ident *get_type_tpop_nameid(const ir_type *tp);
1113 FIRM_API const char *get_type_tpop_name(const ir_type *tp);
1114 FIRM_API tp_opcode get_type_tpop_code(const ir_type *tp);
1117 * construct a string representing the type.
1118 * This uses the info retrieved by the type_dbg_info if available.
1119 * Otherwise it tries to create an approximate textual representation of the
1121 * Keep in mind that this representation is not unique for each type,
1122 * might abstract away some details. The main intention of this is creating
1123 * human redable strings giving an idea of the type.
1125 FIRM_API void ir_print_type(char *buffer, size_t buffer_size,
1128 /** The state of the type layout. */
1130 layout_undefined, /**< The layout of this type is not defined.
1131 Address computation to access fields is not
1132 possible, fields must be accessed by Sel
1133 nodes. Enumeration constants might be undefined.
1134 This is the default value except for
1135 pointer, primitive and method types. */
1136 layout_fixed /**< The layout is fixed, all component/member entities
1137 have an offset assigned. Size of the type is known.
1138 Arrays can be accessed by explicit address
1139 computation. Enumeration constants must be defined.
1140 Default for pointer, primitive and method types. */
1143 /** Returns a human readable string for the enum entry. */
1144 FIRM_API const char *get_type_state_name(ir_type_state s);
1146 /** Returns the type layout state of a type. */
1147 FIRM_API ir_type_state get_type_state(const ir_type *tp);
1149 /** Sets the type layout state of a type.
1151 * For primitives, pointer and method types the layout is always fixed.
1152 * This call is legal but has no effect.
1154 FIRM_API void set_type_state(ir_type *tp, ir_type_state state);
1156 /** Returns the mode of a type.
1158 * Returns NULL for all non atomic types.
1160 FIRM_API ir_mode *get_type_mode(const ir_type *tp);
1162 /** Sets the mode of a type.
1164 * Only has an effect on primitive, enumeration and pointer types.
1166 FIRM_API void set_type_mode(ir_type *tp, ir_mode* m);
1168 /** Returns the size of a type in bytes. */
1169 FIRM_API unsigned get_type_size_bytes(const ir_type *tp);
1171 /** Sets the size of a type in bytes.
1173 * For primitive, enumeration, pointer and method types the size
1174 * is always fixed. This call is legal but has no effect.
1176 FIRM_API void set_type_size_bytes(ir_type *tp, unsigned size);
1178 /** Returns the alignment of a type in bytes. */
1179 FIRM_API unsigned get_type_alignment_bytes(ir_type *tp);
1181 /** Returns the alignment of a type in bits.
1183 * If the alignment of a type is
1184 * not set, it is calculated here according to the following rules:
1185 * -#.) if a type has a mode, the alignment is the mode size.
1186 * -#.) compound types have the alignment of there biggest member.
1187 * -#.) array types have the alignment of there element type.
1188 * -#.) method types return 0 here.
1189 * -#.) all other types return 1 here (i.e. aligned at byte).
1191 FIRM_API void set_type_alignment_bytes(ir_type *tp, unsigned align);
1193 /** Returns the visited count of a type. */
1194 FIRM_API ir_visited_t get_type_visited(const ir_type *tp);
1195 /** Sets the visited count of a type to num. */
1196 FIRM_API void set_type_visited(ir_type *tp, ir_visited_t num);
1197 /** Sets visited field in type to type_visited. */
1198 FIRM_API void mark_type_visited(ir_type *tp);
1199 /** Returns non-zero if the type is already visited */
1200 FIRM_API int type_visited(const ir_type *tp);
1201 /** Returns non-zero if the type is not yet visited */
1202 FIRM_API int type_not_visited(const ir_type *tp);
1204 /** Returns the associated link field of a type. */
1205 FIRM_API void *get_type_link(const ir_type *tp);
1206 /** Sets the associated link field of a type. */
1207 FIRM_API void set_type_link(ir_type *tp, void *l);
1210 * Visited flag to traverse the type information.
1212 * Increase this flag by one before traversing the type information
1213 * using inc_master_type_visited().
1214 * Mark type nodes as visited by mark_type_visited(ir_type).
1215 * Check whether node was already visited by type_visited(ir_type)
1216 * and type_not_visited(ir_type).
1217 * Or use the function to walk all types.
1221 FIRM_API void set_master_type_visited(ir_visited_t val);
1222 FIRM_API ir_visited_t get_master_type_visited(void);
1223 FIRM_API void inc_master_type_visited(void);
1226 * Sets the debug information of a type.
1228 * @param tp The type.
1229 * @param db The debug info.
1231 FIRM_API void set_type_dbg_info(ir_type *tp, type_dbg_info *db);
1234 * Returns the debug information of a type.
1236 * @param tp The type.
1238 FIRM_API type_dbg_info *get_type_dbg_info(const ir_type *tp);
1241 * Checks whether a pointer points to a type.
1243 * @param thing an arbitrary pointer
1246 * true if the thing is a type, else false
1248 FIRM_API int is_type(const void *thing);
1251 * Checks whether two types are structurally equal.
1253 * @param typ1 the first type
1254 * @param typ2 the second type
1257 * true if the types are equal, else false.
1259 * Types are equal if :
1260 * - they are the same type kind
1261 * - they have the same name
1262 * - they have the same mode (if applicable)
1263 * - they have the same type_state and, ev., the same size
1264 * - they are class types and have:
1265 * - the same members (see same_entity in entity.h)
1266 * - the same supertypes -- the C-pointers are compared --> no recursive call.
1267 * - the same number of subtypes. Subtypes are not compared,
1268 * as this could cause a cyclic test.
1269 * - they are structure types and have the same members
1270 * - they are method types and have
1271 * - the same parameter types
1272 * - the same result types
1273 * - they are union types and have the same members
1274 * - they are array types and have
1275 * - the same number of dimensions
1276 * - the same dimension bounds
1277 * - the same dimension order
1278 * - the same element type
1279 * - they are enumeration types and have the same enumerator names
1280 * - they are pointer types and have the identical points_to type
1281 * (i.e., the same C-struct to represent the type.
1282 * This is to avoid endless recursions; with pointer types cyclic
1283 * type graphs are possible.)
1285 FIRM_API int equal_type(ir_type *typ1, ir_type *typ2);
1288 * Checks whether two types are structural comparable.
1290 * @param st pointer type
1291 * @param lt pointer type
1294 * true if type st is smaller than type lt, i.e. whenever
1295 * lt is expected a st can be used.
1297 * - they are the same type kind
1298 * - mode(st) < mode (lt) (if applicable)
1299 * - they are class types and st is (transitive) subtype of lt,
1300 * - they are structure types and
1301 * - the members of st have exactly one counterpart in lt with the same name,
1302 * - the counterpart has a bigger type.
1303 * - they are method types and have
1304 * - the same number of parameter and result types,
1305 * - the parameter types of st are smaller than those of lt,
1306 * - the result types of st are smaller than those of lt
1307 * - they are union types and have the members of st have exactly one
1308 * @return counterpart in lt and the type is smaller
1309 * - they are array types and have
1310 * - the same number of dimensions
1311 * - all bounds of lt are bound of st
1312 * - the same dimension order
1313 * - the same element type
1315 * - the element type of st is smaller than that of lt
1316 * - the element types have the same size and fixed layout.
1317 * - they are enumeration types and have the same enumerator names
1318 * - they are pointer types and have the points_to type of st is
1319 * @return smaller than the points_to type of lt.
1322 FIRM_API int smaller_type(ir_type *st, ir_type *lt);
1325 * @page class_type Representation of a class type
1327 * If the type opcode is set to type_class the type represents class
1328 * types. A list of fields and methods is associated with a class.
1329 * Further a class can inherit from and bequest to other classes.
1331 * The following attributes are private to this type kind:
1332 * - member: All entities belonging to this class. This are method entities
1333 * which have type_method or fields that can have any of the
1334 * following type kinds: type_class, type_struct, type_union,
1335 * type_array, type_enumeration, type_pointer, type_primitive.
1337 * The following two are dynamic lists that can be grown with an "add_" function,
1340 * - subtypes: A list of direct subclasses.
1342 * - supertypes: A list of direct superclasses.
1344 * - type_info: An entity representing the type information of this class.
1345 * This entity can be of arbitrari type, Firm did not use it yet.
1346 * It allows to express the coupling of a type with an entity
1347 * representing this type. This information is useful for lowering
1348 * of InstOf and TypeChk nodes. Default: NULL
1350 * - vtable_size: The size of this class virtual function table.
1353 * - final: A final class is always a leaf in the class hierarchy. Final
1354 * classes cannot be super classes of other ones. As this information
1355 * can only be computed in whole world compilations, we allow to
1356 * set this flag. It is used in optimizations if get_opt_closed_world()
1357 * is false. Default: false
1359 * - interface: The class represents an interface. This flag can be set to distinguish
1360 * between interfaces, abstract classes and other classes that all may
1361 * have the peculiarity peculiarity_description. Depending on this flag
1362 * the lowering might do different actions. Default: false
1364 * - abstract : The class represents an abstract class. This flag can be set to distinguish
1365 * between interfaces, abstract classes and other classes that all may
1366 * have the peculiarity peculiarity_description. Depending on this flag
1367 * the lowering might do different actions. Default: false
1370 /** Creates a new class type. */
1371 FIRM_API ir_type *new_type_class(ident *name);
1373 /** Creates a new class type with debug information. */
1374 FIRM_API ir_type *new_d_type_class(ident *name, type_dbg_info *db);
1376 /* --- manipulate private fields of class type --- */
1378 /** return identifier of the class type */
1379 FIRM_API ident *get_class_ident(const ir_type *clss);
1381 /** return identifier of the class type */
1382 FIRM_API const char *get_class_name(const ir_type *clss);
1384 /** Returns the number of members of this class. */
1385 FIRM_API int get_class_n_members(const ir_type *clss);
1387 /** Returns the member at position pos, 0 <= pos < n_member */
1388 FIRM_API ir_entity *get_class_member(const ir_type *clss, int pos);
1390 /** Returns index of mem in clss, -1 if not contained. */
1391 FIRM_API int get_class_member_index(const ir_type *clss, ir_entity *mem);
1393 /** Finds the member with name 'name'. If several members with the same
1394 * name returns one of them. Returns NULL if no member found. */
1395 FIRM_API ir_entity *get_class_member_by_name(ir_type *clss, ident *name);
1397 /** Adds subtype as subtype to clss.
1399 * Checks whether clss is a supertype of subtype. If not
1400 * adds also clss as supertype to subtype. */
1401 FIRM_API void add_class_subtype(ir_type *clss, ir_type *subtype);
1403 /** Returns the number of subtypes */
1404 FIRM_API int get_class_n_subtypes(const ir_type *clss);
1406 /** Gets the subtype at position pos, 0 <= pos < n_subtype. */
1407 FIRM_API ir_type *get_class_subtype(ir_type *clss, int pos);
1409 /** Returns the index to access subclass as subtype of class.
1411 * If subclass is no direct subtype of class returns -1.
1413 FIRM_API int get_class_subtype_index(ir_type *clss, const ir_type *subclass);
1415 /** Sets the subtype at position pos, 0 <= pos < n_subtype.
1417 * Does not set the corresponding supertype relation for subtype: this might
1418 * be a different position! */
1419 FIRM_API void set_class_subtype(ir_type *clss, ir_type *subtype, int pos);
1421 /** Finds subtype in the list of subtypes and removes it */
1422 FIRM_API void remove_class_subtype(ir_type *clss, ir_type *subtype);
1424 /* Convenience macros */
1425 #define add_class_derived_type(clss, drvtype) add_class_subtype(clss, drvtype)
1426 #define get_class_n_derived_types(clss) get_class_n_subtypes(clss)
1427 #define get_class_derived_type(clss, pos) get_class_subtype(clss, pos)
1428 #define get_class_derived_type_index(clss, drvtype) get_class_subtype_index(clss, drvtype)
1429 #define set_class_derived_type(clss, drvtype, pos) set_class_subtype(clss, drvtype, pos)
1430 #define remove_class_derived_type(clss, drvtype) remove_class_subtype(clss, drvtype)
1432 /** Adds supertype as supertype to class.
1434 * Checks whether clss is a subtype of supertype. If not
1435 * adds also clss as subtype to supertype. */
1436 FIRM_API void add_class_supertype(ir_type *clss, ir_type *supertype);
1438 /** Returns the number of supertypes */
1439 FIRM_API int get_class_n_supertypes(const ir_type *clss);
1441 /** Returns the index to access superclass as supertype of class.
1443 * If superclass is no direct supertype of class returns -1.
1445 FIRM_API int get_class_supertype_index(ir_type *clss, ir_type *super_clss);
1447 /** Gets the supertype at position pos, 0 <= pos < n_supertype. */
1448 FIRM_API ir_type *get_class_supertype(ir_type *clss, int pos);
1450 /** Sets the supertype at position pos, 0 <= pos < n_supertype.
1452 * Does not set the corresponding subtype relation for supertype: this might
1453 * be at a different position! */
1454 FIRM_API void set_class_supertype(ir_type *clss, ir_type *supertype, int pos);
1456 /** Finds supertype in the list of supertypes and removes it */
1457 FIRM_API void remove_class_supertype(ir_type *clss, ir_type *supertype);
1459 /** Convenience macro */
1460 #define add_class_base_type(clss, basetype) add_class_supertype(clss, basetype)
1461 #define get_class_n_base_types(clss) get_class_n_supertypes(clss)
1462 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
1463 #define get_class_base_type(clss, pos) get_class_supertype(clss, pos)
1464 #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos)
1465 #define remove_class_base_type(clss, basetype) remove_class_supertype(clss, basetype)
1467 /** Returns the type info entity of a class. */
1468 FIRM_API ir_entity *get_class_type_info(const ir_type *clss);
1470 /** Set a type info entity for the class. */
1471 FIRM_API void set_class_type_info(ir_type *clss, ir_entity *ent);
1473 /** Returns the size of the virtual function table. */
1474 FIRM_API unsigned get_class_vtable_size(const ir_type *clss);
1476 /** Sets a new size of the virtual function table. */
1477 FIRM_API void set_class_vtable_size(ir_type *clss, unsigned size);
1479 /** Returns non-zero if a class is final. */
1480 FIRM_API int is_class_final(const ir_type *clss);
1482 /** Sets the class final flag. */
1483 FIRM_API void set_class_final(ir_type *clss, int flag);
1485 /** Return non-zero if a class is an interface */
1486 FIRM_API int is_class_interface(const ir_type *clss);
1488 /** Sets the class interface flag. */
1489 FIRM_API void set_class_interface(ir_type *clss, int flag);
1491 /** Return non-zero if a class is an abstract class. */
1492 FIRM_API int is_class_abstract(const ir_type *clss);
1494 /** Sets the class abstract flag. */
1495 FIRM_API void set_class_abstract(ir_type *clss, int flag);
1497 /** Returns true if a type is a class type. */
1498 FIRM_API int is_Class_type(const ir_type *clss);
1501 * @page struct_type Representation of a struct type
1503 * A struct type represents aggregate types that consist of a list
1506 * The following attributes are private to this type kind:
1507 * - member: All entities belonging to this class. This are the fields
1508 * that can have any of the following types: type_class,
1509 * type_struct, type_union, type_array, type_enumeration,
1510 * type_pointer, type_primitive.
1511 * This is a dynamic list that can be grown with an "add_" function,
1513 * This is a dynamic list that can be grown with an "add_" function,
1516 /** Creates a new type struct */
1517 FIRM_API ir_type *new_type_struct(ident *name);
1518 /** Creates a new type struct with debug information. */
1519 FIRM_API ir_type *new_d_type_struct(ident *name, type_dbg_info* db);
1521 /* --- manipulate private fields of struct --- */
1523 /** return struct identifier */
1524 FIRM_API ident *get_struct_ident(const ir_type *strct);
1526 /** return struct identifier as c-string*/
1527 FIRM_API const char *get_struct_name(const ir_type *strct);
1529 /** Returns the number of members of this struct. */
1530 FIRM_API int get_struct_n_members(const ir_type *strct);
1532 /** Returns the member at position pos, 0 <= pos < n_member */
1533 FIRM_API ir_entity *get_struct_member(const ir_type *strct, int pos);
1535 /** Returns index of member in strct, -1 if not contained. */
1536 FIRM_API int get_struct_member_index(const ir_type *strct, ir_entity *member);
1538 /** Returns true if a type is a struct type. */
1539 FIRM_API int is_Struct_type(const ir_type *strct);
1542 * @page method_type Representation of a method type
1544 * A method type represents a method, function or procedure type.
1545 * It contains a list of the parameter and result types, as these
1546 * are part of the type description. These lists should not
1547 * be changed by a optimization, as a change creates a new method
1548 * type. Therefore optimizations should allocated new method types.
1549 * The set_ routines are only for construction by a frontend.
1551 * - n_params: Number of parameters to the procedure.
1552 * A procedure in FIRM has only call by value parameters.
1554 * - param_type: A list with the types of parameters. This list is ordered.
1555 * The nth type in this list corresponds to the nth element
1556 * in the parameter tuple that is a result of the start node.
1557 * (See ircons.h for more information.)
1559 * - value_param_ents
1560 * A list of entities (whose owner is a struct private to the
1561 * method type) that represent parameters passed by value.
1563 * - n_res: The number of results of the method. In general, procedures
1564 * have zero results, functions one.
1566 * - res_type: A list with the types of parameters. This list is ordered.
1567 * The nth type in this list corresponds to the nth input to
1568 * Return nodes. (See ircons.h for more information.)
1571 * A list of entities (whose owner is a struct private to the
1572 * method type) that represent results passed by value.
1575 /* These macros define the suffixes for the types and entities used
1576 to represent value parameters / results. */
1577 #define VALUE_PARAMS_SUFFIX "val_param"
1578 #define VALUE_RESS_SUFFIX "val_res"
1580 /** Create a new method type.
1582 * @param n_param the number of parameters
1583 * @param n_res the number of results
1585 * The arrays for the parameter and result types are not initialized by
1588 FIRM_API ir_type *new_type_method(int n_param, int n_res);
1590 /** Create a new method type with debug information.
1592 * @param n_param the number of parameters
1593 * @param n_res the number of results
1594 * @param db user defined debug information
1596 * The arrays for the parameter and result types are not initialized by
1599 FIRM_API ir_type *new_d_type_method(int n_param, int n_res, type_dbg_info *db);
1601 /* -- manipulate private fields of method. -- */
1603 /** Returns the number of parameters of this method. */
1604 FIRM_API int get_method_n_params(const ir_type *method);
1606 /** Returns the type of the parameter at position pos of a method. */
1607 FIRM_API ir_type *get_method_param_type(ir_type *method, int pos);
1608 /** Sets the type of the parameter at position pos of a method.
1609 Also changes the type in the pass-by-value representation by just
1610 changing the type of the corresponding entity if the representation is constructed. */
1611 FIRM_API void set_method_param_type(ir_type *method, int pos, ir_type *tp);
1612 /** Returns an entity that represents the copied value argument. Only necessary
1613 for compounds passed by value. This information is constructed only on demand. */
1614 FIRM_API ir_entity *get_method_value_param_ent(ir_type *method, int pos);
1616 * Sets the type that represents the copied value arguments.
1618 FIRM_API void set_method_value_param_type(ir_type *method, ir_type *tp);
1620 * Returns a type that represents the copied value arguments if one
1621 * was allocated, else NULL.
1623 FIRM_API ir_type *get_method_value_param_type(const ir_type *method);
1624 /** Returns an ident representing the parameters name. Returns NULL if not set.
1625 For debug support only. */
1626 FIRM_API ident *get_method_param_ident(ir_type *method, int pos);
1627 /** Returns a string representing the parameters name. Returns NULL if not set.
1628 For debug support only. */
1629 FIRM_API const char *get_method_param_name(ir_type *method, int pos);
1630 /** Sets an ident representing the parameters name. For debug support only. */
1631 FIRM_API void set_method_param_ident(ir_type *method, int pos, ident *id);
1633 /** Returns the number of results of a method type. */
1634 FIRM_API int get_method_n_ress(const ir_type *method);
1635 /** Returns the return type of a method type at position pos. */
1636 FIRM_API ir_type *get_method_res_type(ir_type *method, int pos);
1637 /** Sets the type of the result at position pos of a method.
1638 Also changes the type in the pass-by-value representation by just
1639 changing the type of the corresponding entity if the representation is constructed. */
1640 FIRM_API void set_method_res_type(ir_type *method, int pos, ir_type *tp);
1641 /** Returns an entity that represents the copied value result. Only necessary
1642 for compounds passed by value. This information is constructed only on demand. */
1643 FIRM_API ir_entity *get_method_value_res_ent(ir_type *method, int pos);
1646 * Returns a type that represents the copied value results.
1648 FIRM_API ir_type *get_method_value_res_type(const ir_type *method);
1651 * This enum flags the variadicity of methods (methods with a
1652 * variable amount of arguments (e.g. C's printf). Default is
1655 typedef enum ir_variadicity {
1656 variadicity_non_variadic, /**< non variadic */
1657 variadicity_variadic /**< variadic */
1660 /** Returns the null-terminated name of this variadicity. */
1661 FIRM_API const char *get_variadicity_name(ir_variadicity vari);
1663 /** Returns the variadicity of a method. */
1664 FIRM_API ir_variadicity get_method_variadicity(const ir_type *method);
1666 /** Sets the variadicity of a method. */
1667 FIRM_API void set_method_variadicity(ir_type *method, ir_variadicity vari);
1670 * Returns the first variadic parameter index of a type.
1671 * If this index was NOT set, the index of the last parameter
1672 * of the method type plus one is returned for variadic functions.
1673 * Non-variadic function types always return -1 here.
1675 FIRM_API int get_method_first_variadic_param_index(const ir_type *method);
1678 * Sets the first variadic parameter index. This allows to specify
1679 * a complete call type (containing the type of all parameters)
1680 * but still have the knowledge, which parameter must be passed as
1683 FIRM_API void set_method_first_variadic_param_index(ir_type *method, int index);
1685 /** Returns the mask of the additional graph properties. */
1686 FIRM_API mtp_additional_properties get_method_additional_properties(const ir_type *method);
1688 /** Sets the mask of the additional graph properties. */
1689 FIRM_API void set_method_additional_properties(ir_type *method,
1690 mtp_additional_properties property_mask);
1692 /** Sets one additional graph property. */
1693 FIRM_API void add_method_additional_properties(ir_type *method,
1694 mtp_additional_properties flag);
1697 * Calling conventions: lower 24 bits are the number of register parameters,
1698 * upper 8 encode the calling conventions.
1701 cc_reg_param = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
1702 This flag may be set as default on some architectures. */
1703 cc_last_on_top = 0x02000000, /**< The last non-register parameter is transmitted on top of
1704 the stack. This is equivalent to the pascal
1705 calling convention. If this flag is not set, the first
1706 non-register parameter is used (stdcall or cdecl
1707 calling convention) */
1708 cc_callee_clear_stk = 0x04000000, /**< The callee clears the stack. This forbids variadic
1709 function calls (stdcall). */
1710 cc_this_call = 0x08000000, /**< The first parameter is a this pointer and is transmitted
1711 in a special way. */
1712 cc_compound_ret = 0x10000000, /**< The method returns a compound type. */
1713 cc_frame_on_caller_stk = 0x20000000, /**< The method did not allocate an own stack frame, instead the
1714 caller must reserve size on its own stack. */
1715 cc_fpreg_param = 0x40000000, /**< Transmit floating point parameters in registers, else the stack is used. */
1716 cc_bits = (0xFF << 24)/**< The calling convention bits. */
1717 } calling_convention;
1719 /* some often used cases: made as defines because firmjni cannot handle two
1720 equal enum values. */
1722 /** cdecl calling convention */
1723 #define cc_cdecl_set (0)
1724 /** stdcall calling convention */
1725 #define cc_stdcall_set cc_callee_clear_stk
1726 /** fastcall calling convention */
1727 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
1730 * check for the CDECL calling convention
1732 #define IS_CDECL(cc_mask) (((cc_mask) & cc_bits) == cc_cdecl_set)
1735 * check for the STDCALL calling convention
1737 #define IS_STDCALL(cc_mask) (((cc_mask) & cc_bits) == cc_stdcall_set)
1740 * check for the FASTCALL calling convention
1742 #define IS_FASTCALL(cc_mask) (((cc_mask) & cc_bits) == cc_fastcall_set)
1745 * Sets the CDECL convention bits.
1747 #define SET_CDECL(cc_mask) (((cc_mask) & ~cc_bits) | cc_cdecl_set)
1750 * Set. the STDCALL convention bits.
1752 #define SET_STDCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_stdcall_set)
1755 * Sets the FASTCALL convention bits.
1757 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
1759 /** Returns the calling convention of an entities graph. */
1760 FIRM_API unsigned get_method_calling_convention(const ir_type *method);
1762 /** Sets the calling convention of an entities graph. */
1763 FIRM_API void set_method_calling_convention(ir_type *method, unsigned cc_mask);
1765 /** Returns the number of registers parameters, 0 means default. */
1766 FIRM_API unsigned get_method_n_regparams(ir_type *method);
1768 /** Sets the number of registers parameters, 0 means default. */
1769 FIRM_API void set_method_n_regparams(ir_type *method, unsigned n_regs);
1771 /** Returns true if a type is a method type. */
1772 FIRM_API int is_Method_type(const ir_type *method);
1775 * @page union_type Representation of a union (variant) type.
1777 * The union type represents union types. Note that this representation
1778 * resembles the C union type. For tagged variant types like in Pascal or Modula
1779 * a combination of a struct and a union type must be used.
1781 * - n_types: Number of unioned types.
1782 * - members: Entities for unioned types. Fixed length array.
1783 * This is a dynamic list that can be grown with an "add_" function,
1786 /** Creates a new type union. */
1787 FIRM_API ir_type *new_type_union(ident *name);
1789 /** Creates a new type union with debug information. */
1790 FIRM_API ir_type *new_d_type_union(ident *name, type_dbg_info* db);
1792 /* --- manipulate private fields of struct --- */
1794 /** return union identifier */
1795 FIRM_API ident *get_union_ident(const ir_type *uni);
1797 /** return union identifier as c-string */
1798 FIRM_API const char *get_union_name(const ir_type *uni);
1800 /** Returns the number of unioned types of this union */
1801 FIRM_API int get_union_n_members(const ir_type *uni);
1803 /** Returns the entity at position pos of a union */
1804 FIRM_API ir_entity *get_union_member(const ir_type *uni, int pos);
1806 /** Returns index of member in uni, -1 if not contained. */
1807 FIRM_API int get_union_member_index(const ir_type *uni, ir_entity *member);
1809 /** Returns true if a type is a union type. */
1810 FIRM_API int is_Union_type(const ir_type *uni);
1813 * @page array_type Representation of an array type
1815 * The array type represents rectangular multi dimensional arrays.
1816 * The constants representing the bounds must be allocated to
1817 * get_const_code_irg() by setting current_ir_graph accordingly.
1819 * - n_dimensions: Number of array dimensions.
1820 * - *lower_bound: Lower bounds of dimensions. Usually all 0.
1821 * - *upper_bound: Upper bounds or dimensions.
1822 * - *element_type: The type of the array elements.
1823 * - *element_ent: An entity for the array elements to be used for
1824 * element selection with Sel.
1827 /** Create a new type array.
1829 * Sets n_dimension to dimension and all dimension entries to NULL.
1830 * Initializes order to the order of the dimensions.
1831 * The entity for array elements is built automatically.
1832 * Set dimension sizes after call to constructor with set_* routines.
1834 FIRM_API ir_type *new_type_array(int n_dims, ir_type *element_type);
1836 /** Create a new type array with debug information.
1838 * Sets n_dimension to dimension and all dimension entries to NULL.
1839 * Initializes order to the order of the dimensions.
1840 * The entity for array elements is built automatically.
1841 * Set dimension sizes after call to constructor with set_* routines.
1842 * A legal array type must have at least one dimension set.
1844 FIRM_API ir_type *new_d_type_array(int n_dims, ir_type *element_type,
1847 /* --- manipulate private fields of array type --- */
1849 /** Returns the number of array dimensions of this type. */
1850 FIRM_API int get_array_n_dimensions(const ir_type *array);
1853 * Allocates Const nodes of mode_Is for one array dimension.
1854 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1856 FIRM_API void set_array_bounds_int(ir_type *array, int dimension,
1857 int lower_bound, int upper_bound);
1859 * Sets the bounds for one array dimension.
1860 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1862 FIRM_API void set_array_bounds(ir_type *array, int dimension,
1863 ir_node *lower_bound, ir_node *upper_bound);
1864 /** Sets the lower bound for one array dimension, i.e. [lower,upper[ */
1865 FIRM_API void set_array_lower_bound(ir_type *array, int dimension,
1866 ir_node *lower_bound);
1868 /** Allocates Const nodes of mode_Is for the lower bound of an array
1869 dimension, i.e. [lower,upper[ */
1870 FIRM_API void set_array_lower_bound_int(ir_type *array, int dimension,
1873 /** Sets the upper bound for one array dimension, i.e. [lower,upper[ */
1874 FIRM_API void set_array_upper_bound(ir_type *array, int dimension,
1875 ir_node *upper_bound);
1877 /** Allocates Const nodes of mode_Is for the upper bound of an array
1878 dimension, i.e. [lower,upper[. */
1879 FIRM_API void set_array_upper_bound_int(ir_type *array, int dimension,
1882 /** Returns true if lower bound != Unknown. */
1883 FIRM_API int has_array_lower_bound(const ir_type *array, int dimension);
1884 /** Returns the lower bound of an array. */
1885 FIRM_API ir_node *get_array_lower_bound(const ir_type *array, int dimension);
1886 /** Works only if bound is Const node with tarval that can be converted to long. */
1887 FIRM_API long get_array_lower_bound_int(const ir_type *array, int dimension);
1888 /** returns true if lower bound != Unknown */
1889 FIRM_API int has_array_upper_bound(const ir_type *array, int dimension);
1890 /** Returns the upper bound of an array. */
1891 FIRM_API ir_node *get_array_upper_bound(const ir_type *array, int dimension);
1892 /** Works only if bound is Const node with tarval that can be converted to long. */
1893 FIRM_API long get_array_upper_bound_int(const ir_type *array, int dimension);
1895 /** Sets an array dimension to a specific order. */
1896 FIRM_API void set_array_order(ir_type *array, int dimension, int order);
1898 /** Returns the order of an array dimension. */
1899 FIRM_API int get_array_order(const ir_type *array, int dimension);
1901 /** Find the array dimension that is placed at order order. */
1902 FIRM_API int find_array_dimension(const ir_type *array, int order);
1904 /** Sets the array element type. */
1905 FIRM_API void set_array_element_type(ir_type *array, ir_type* tp);
1907 /** Gets the array element type. */
1908 FIRM_API ir_type *get_array_element_type(const ir_type *array);
1910 /** Sets the array element entity. */
1911 FIRM_API void set_array_element_entity(ir_type *array, ir_entity *ent);
1913 /** Get the array element entity. */
1914 FIRM_API ir_entity *get_array_element_entity(const ir_type *array);
1916 /** Returns true if a type is an array type. */
1917 FIRM_API int is_Array_type(const ir_type *array);
1920 * @page enumeration_type Representation of an enumeration type
1922 * Enumeration types need not necessarily be represented explicitly
1923 * by Firm types, as the frontend can lower them to integer constants as
1924 * well. For debugging purposes or similar tasks this information is useful.
1925 * The type state layout_fixed is set, if all enumeration constant have
1926 * there tarvals assigned. Until then
1928 * - *const: The target values representing the constants used to
1929 * represent individual enumerations.
1932 /** Create a new type enumeration -- set the enumerators independently. */
1933 FIRM_API ir_type *new_type_enumeration(ident *name, int n_enums);
1935 /** Create a new type enumeration with debug information -- set the enumerators independently. */
1936 FIRM_API ir_type *new_d_type_enumeration(ident *name, int n_enums,
1939 /* --- manipulate fields of enumeration type. --- */
1941 /** return enumeration identifier */
1942 FIRM_API ident *get_enumeration_ident(const ir_type *enumeration);
1944 /** return enumeration identifier as c-string */
1945 FIRM_API const char *get_enumeration_name(const ir_type *enumeration);
1947 /** Set an enumeration constant to a enumeration type at a given position. */
1948 FIRM_API void set_enumeration_const(ir_type *enumeration, int pos,
1949 ident *nameid, ir_tarval *con);
1951 /** Returns the number of enumeration values of this enumeration */
1952 FIRM_API int get_enumeration_n_enums(const ir_type *enumeration);
1954 /** Returns the enumeration constant at a given position. */
1955 FIRM_API ir_enum_const *get_enumeration_const(const ir_type *enumeration,
1958 /** Returns the enumeration type owner of an enumeration constant. */
1959 FIRM_API ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst);
1961 /** Sets the enumeration constant value. */
1962 FIRM_API void set_enumeration_value(ir_enum_const *enum_cnst, ir_tarval *con);
1964 /** Returns the enumeration constant value. */
1965 FIRM_API ir_tarval *get_enumeration_value(const ir_enum_const *enum_cnst);
1967 /** Assign an ident to an enumeration constant. */
1968 FIRM_API void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
1970 /** Returns the assigned ident of an enumeration constant. */
1971 FIRM_API ident *get_enumeration_const_nameid(const ir_enum_const *enum_cnst);
1973 /** Returns the assigned name of an enumeration constant. */
1974 FIRM_API const char *get_enumeration_const_name(const ir_enum_const *enum_cnst);
1976 /** Returns true if a type is a enumeration type. */
1977 FIRM_API int is_Enumeration_type(const ir_type *enumeration);
1980 * @page pointer_type Representation of a pointer type
1983 * - points_to: The type of the entity this pointer points to.
1986 /** Creates a new type pointer. */
1987 FIRM_API ir_type *new_type_pointer(ir_type *points_to);
1989 /** Creates a new type pointer with debug information. */
1990 FIRM_API ir_type *new_d_type_pointer(ir_type *points_to, type_dbg_info* db);
1992 /* --- manipulate fields of type_pointer --- */
1994 /** Sets the type to which a pointer points to. */
1995 FIRM_API void set_pointer_points_to_type(ir_type *pointer, ir_type *tp);
1997 /** Returns the type to which a pointer points to. */
1998 FIRM_API ir_type *get_pointer_points_to_type(const ir_type *pointer);
2000 /** Returns true if a type is a pointer type. */
2001 FIRM_API int is_Pointer_type(const ir_type *pointer);
2003 /** Returns the first pointer type that has as points_to tp.
2004 * Not efficient: O(\#types).
2005 * If not found returns firm_unknown_type. */
2006 FIRM_API ir_type *find_pointer_type_to_type(ir_type *tp);
2009 * @page primitive_type Representation of a primitive type
2011 * Primitive types are types that represent atomic data values that
2012 * map directly to modes. They don't have private attributes. The
2013 * important information they carry is held in the common mode field.
2015 /** Creates a new primitive type. */
2016 FIRM_API ir_type *new_type_primitive(ir_mode *mode);
2018 /** Creates a new primitive type with debug information. */
2019 FIRM_API ir_type *new_d_type_primitive(ir_mode *mode, type_dbg_info* db);
2021 /** Returns true if a type is a primitive type. */
2022 FIRM_API int is_Primitive_type(const ir_type *primitive);
2024 /** Return the base type of a primitive (bitfield) type or NULL if none. */
2025 FIRM_API ir_type *get_primitive_base_type(const ir_type *tp);
2027 /** Sets the base type of a primitive (bitfield) type. */
2028 FIRM_API void set_primitive_base_type(ir_type *tp, ir_type *base_tp);
2031 * @page none_type The None type
2033 * This type is an auxiliary type dedicated to support type analyses.
2035 * The none type represents that there is no type. The type can be used to
2036 * initialize fields of type* that actually can not contain a type or that
2037 * are initialized for an analysis. There exists exactly one type none.
2038 * This type is not on the type list in ir_prog. It is
2039 * allocated when initializing the type module.
2041 * The following values are set:
2043 * - name: "type_none"
2044 * - state: layout_fixed
2047 /** A variable that contains the only none type. */
2048 FIRM_API ir_type *firm_none_type;
2050 /** A variable that contains the only code type. */
2051 FIRM_API ir_type *firm_code_type;
2053 /** Returns the none type. */
2054 FIRM_API ir_type *get_none_type(void);
2055 /** Returns the code type. */
2056 FIRM_API ir_type *get_code_type(void);
2059 * @page unknown_type The Unknown type
2061 * This type is an auxiliary type dedicated to support type analyses.
2063 * The unknown type represents that there could be a type, but it is not
2064 * known. This type can be used to initialize fields before an analysis (not known
2065 * yet) or to represent the top of a lattice (could not be determined). There exists
2066 * exactly one type unknown. This type is not on the type list in ir_prog. It is
2067 * allocated when initializing the type module.
2069 * The following values are set:
2071 * - name: "type_unknown"
2072 * - state: layout_fixed
2075 /** A variable that contains the only unknown type. */
2076 FIRM_API ir_type *firm_unknown_type;
2078 /** Returns the unknown type. */
2079 FIRM_API ir_type *get_unknown_type(void);
2083 * Checks whether a type is atomic.
2084 * @param tp any type
2085 * @return true if type is primitive, pointer or enumeration
2087 FIRM_API int is_atomic_type(const ir_type *tp);
2089 /* --- Support for compound types --- */
2092 * Gets the identifier of a compound type
2094 FIRM_API ident *get_compound_ident(const ir_type *tp);
2096 /** return compound identifier as c-string */
2097 FIRM_API const char *get_compound_name(const ir_type *tp);
2100 * Gets the number of elements in a Firm compound type.
2102 * This is just a comfortability function, because structs and
2103 * classes can often be treated be the same code, but they have
2104 * different access functions to their members.
2106 * @param tp The type (must be struct, union or class).
2108 * @return Number of members in the compound type.
2110 FIRM_API int get_compound_n_members(const ir_type *tp);
2113 * Gets the member of a Firm compound type at position pos.
2115 * @param tp The type (must be struct, union or class).
2116 * @param pos The number of the member.
2118 * @return The member entity at position pos.
2120 FIRM_API ir_entity *get_compound_member(const ir_type *tp, int pos);
2122 /** Returns index of member in tp, -1 if not contained. */
2123 FIRM_API int get_compound_member_index(const ir_type *tp, ir_entity *member);
2126 * layout members of a struct/union or class type in a default way.
2128 FIRM_API void default_layout_compound_type(ir_type *tp);
2131 * Checks whether a type is a compound type.
2133 * @param tp - any type
2135 * @return true if the type is class, structure, union or array type.
2137 FIRM_API int is_compound_type(const ir_type *tp);
2140 * Checks wether a type is a code type.
2142 FIRM_API int is_code_type(const ir_type *tp);
2145 * Checks, whether a type is a frame type.
2147 FIRM_API int is_frame_type(const ir_type *tp);
2150 * Checks, whether a type is a value parameter type.
2152 FIRM_API int is_value_param_type(const ir_type *tp);
2155 * Checks, whether a type is a lowered type.
2157 FIRM_API int is_lowered_type(const ir_type *tp);
2160 * Makes a new value type. Value types are struct types,
2161 * so all struct access functions work.
2162 * Value types are not in the global list of types.
2164 FIRM_API ir_type *new_type_value(void);
2167 * Makes a new frame type. Frame types are class types,
2168 * so all class access functions work.
2169 * Frame types are not in the global list of types.
2171 FIRM_API ir_type *new_type_frame(void);
2174 * Makes a clone of a frame type.
2175 * Sets entity links from old frame entities to new onces and
2178 FIRM_API ir_type *clone_frame_type(ir_type *type);
2181 * Sets a lowered type for a type. This sets both associations
2182 * and marks lowered_type as a "lowered" one.
2184 FIRM_API void set_lowered_type(ir_type *tp, ir_type *lowered_type);
2187 * Gets the lowered/unlowered type of a type or NULL if this type
2188 * has no lowered/unlowered one.
2190 FIRM_API ir_type *get_associated_type(const ir_type *tp);
2193 * Allocate an area of size bytes aligned at alignment
2194 * at the start or the end of a frame type.
2195 * The frame type must already have a fixed layout.
2197 * @param frame_type a frame type
2198 * @param size the size of the entity
2199 * @param alignment the alignment of the entity
2200 * @param at_start if true, put the area at the frame type's start, else at end
2202 * @return the entity representing the area
2204 FIRM_API ir_entity *frame_alloc_area(ir_type *frame_type, int size,
2205 unsigned alignment, int at_start);
2207 /*-----------------------------------------------------------------*/
2209 /*-----------------------------------------------------------------*/
2212 * Outputs a unique number for this type if libfirm is compiled for
2213 * debugging, (configure with --enable-debug) else returns the address
2214 * of the type cast to long.
2216 FIRM_API long get_type_nr(const ir_type *tp);
2218 /* ------------------------------------------------------------------------ */
2220 /** Type for a function that compares two types.
2222 * @param tp1 The first type to compare.
2223 * @param tp2 The second type to compare.
2225 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
2227 /* ------------------------------------------------------------------------ */
2229 /** A data type to treat types and entities as the same. */
2231 ir_type *typ; /**< points to a type */
2232 ir_entity *ent; /**< points to an entity */
2235 /** Type of argument functions for type walkers.
2237 * @param tore points to the visited type or entity
2238 * @param env free environment pointer
2240 typedef void type_walk_func(type_or_ent tore, void *env);
2242 /** The class walk function
2244 * @param clss points to the visited class
2245 * @param env free environment pointer
2247 typedef void class_walk_func(ir_type *clss, void *env);
2249 /** Touches every type and entity in unspecified order. If new
2250 * types/entities are created during the traversal these will
2252 * Does not touch frame types or types for value params ... */
2253 FIRM_API void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
2255 /** Touches every type, entity, frame type, and value param type in
2256 * unspecified order (also all segment types). */
2257 FIRM_API void type_walk_prog(type_walk_func *pre, type_walk_func *post,
2260 /** Walks over all type information reachable from an ir graph.
2262 * Walks over all type information reachable from irg, i.e., starts a
2263 * type walk at the irgs entity, the irgs frame type and all types and
2264 * entities that are attributes to firm nodes. */
2265 FIRM_API void type_walk_irg(ir_graph *irg, type_walk_func *pre,
2266 type_walk_func *post, void *env);
2269 * Touches every class in specified order:
2270 * - first the super class
2271 * - second the class itself
2272 * - third the sub classes. If new classes are created
2273 * during the traversal these will be visited, too.
2275 * @deprecated will be removed?
2277 FIRM_API void type_walk_super2sub(type_walk_func *pre, type_walk_func *post,
2280 /** Walker for class types in inheritance order.
2282 * Touches every class in specified order:
2283 * - first the super class
2284 * - second the class itself
2285 * If new classes are created during the traversal these
2286 * will be visited, too.
2287 * Starts the walk at arbitrary classes.
2288 * Executes pre when first visiting a class. Executes post after
2289 * visiting all superclasses.
2291 * The arguments pre, post, env may be NULL. */
2292 FIRM_API void type_walk_super(type_walk_func *pre, type_walk_func *post,
2295 /** Same as type_walk_super2sub, but visits only class types.
2296 Executes pre for a class if all superclasses have been visited.
2297 Then iterates to subclasses. Executes post after return from
2299 Does not visit global type, frame types.
2301 FIRM_API void class_walk_super2sub(class_walk_func *pre, class_walk_func *post,
2305 * the entity walk function. A function type for entity walkers.
2307 * @param ent points to the visited entity
2308 * @param env free environment pointer
2310 typedef void entity_walk_func(ir_entity *ent, void *env);
2313 * Walks over all entities in the type.
2315 * @param tp the type
2316 * @param doit the entity walker function
2317 * @param env environment, will be passed to the walker function
2319 FIRM_API void walk_types_entities(ir_type *tp, entity_walk_func *doit,
2323 * If we have the closed world assumption, we can calculate the
2324 * finalization of classes and entities by inspecting the class hierarchy.
2325 * After this is done, all classes and entities that are not overridden
2326 * anymore have the final property set.
2328 FIRM_API void types_calc_finalization(void);
2331 FIRM_API ir_visibility get_type_visibility(const ir_type *tp);
2333 FIRM_API void set_type_visibility(ir_type *tp, ir_visibility v);
2337 allocation_automatic,
2338 allocation_parameter,
2343 FIRM_API ir_allocation get_entity_allocation(const ir_entity *ent);
2345 FIRM_API void set_entity_allocation(ir_entity *ent, ir_allocation al);
2349 peculiarity_existent,
2350 peculiarity_description,
2351 peculiarity_inherited
2354 FIRM_API ir_peculiarity get_entity_peculiarity(const ir_entity *ent);
2356 FIRM_API void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec);
2359 FIRM_API int is_entity_final(const ir_entity *ent);
2361 FIRM_API void set_entity_final(ir_entity *ent, int final);
2364 FIRM_API ir_peculiarity get_class_peculiarity(const ir_type *clss);
2366 FIRM_API void set_class_peculiarity(ir_type *clss, ir_peculiarity pec);