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
437 * @param to_block block to copy to
439 FIRM_API ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *to_block);
441 /* Set has no effect for existent entities of type method. */
442 FIRM_API ir_node *get_atomic_ent_value(ir_entity *ent);
443 FIRM_API void set_atomic_ent_value(ir_entity *ent, ir_node *val);
445 /** the kind (type) of an initializer */
446 typedef enum ir_initializer_kind_t {
447 /** initializer containing an ir_node from the const-code irg */
448 IR_INITIALIZER_CONST,
449 /** initializer containing a tarval */
450 IR_INITIALIZER_TARVAL,
451 /** initializes type with default values (usually 0) */
453 /** list of initializers used to initializer a compound or array type */
454 IR_INITIALIZER_COMPOUND
455 } ir_initializer_kind_t;
457 /** returns kind of an initializer */
458 FIRM_API ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer);
460 /** Return the name of the initializer kind. */
461 FIRM_API const char *get_initializer_kind_name(ir_initializer_kind_t ini);
464 * returns the null initializer (there's only one instance of it in a program )
466 FIRM_API ir_initializer_t *get_initializer_null(void);
469 * creates an initializer containing a reference to a node on the const-code
472 FIRM_API ir_initializer_t *create_initializer_const(ir_node *value);
474 /** creates an initializer containing a single tarval value */
475 FIRM_API ir_initializer_t *create_initializer_tarval(ir_tarval *tv);
477 /** return value contained in a const initializer */
478 FIRM_API ir_node *get_initializer_const_value(const ir_initializer_t *initializer);
480 /** return value contained in a tarval initializer */
481 FIRM_API ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initialzier);
483 /** creates a compound initializer which holds @p n_entries entries */
484 FIRM_API ir_initializer_t *create_initializer_compound(unsigned n_entries);
486 /** returns the number of entries in a compound initializer */
487 FIRM_API unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer);
489 /** sets entry with index @p index to the initializer @p value */
490 FIRM_API void set_initializer_compound_value(ir_initializer_t *initializer,
492 ir_initializer_t *value);
494 /** returns the value with index @p index of a compound initializer */
495 FIRM_API ir_initializer_t *get_initializer_compound_value(
496 const ir_initializer_t *initializer, unsigned index);
498 /** Sets the new style initializers of an entity. */
499 FIRM_API void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer);
501 /** Returns true, if an entity has new style initializers. */
502 FIRM_API int has_entity_initializer(const ir_entity *entity);
504 /** Return the new style initializers of an entity. */
505 FIRM_API ir_initializer_t *get_entity_initializer(const ir_entity *entity);
507 /* --- Fields of entities with a class type as owner --- */
508 /* Overwrites is a field that specifies that an access to the overwritten
509 entity in the supertype must use this entity. It's a list as with
510 multiple inheritance several entities can be overwritten. This field
511 is mostly useful for method entities.
512 If a Sel node selects an entity that is overwritten by other entities it
513 must return a pointer to the entity of the dynamic type of the pointer
514 that is passed to it. Lowering of the Sel node must assure this.
515 Overwrittenby is the inverse of overwrites. Both add routines add
516 both relations, they only differ in the order of arguments. */
517 FIRM_API void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
518 FIRM_API int get_entity_n_overwrites(const ir_entity *ent);
519 FIRM_API int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten);
520 FIRM_API ir_entity *get_entity_overwrites(const ir_entity *ent, int pos);
521 FIRM_API void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten);
522 FIRM_API void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
524 FIRM_API int get_entity_n_overwrittenby(const ir_entity *ent);
525 FIRM_API int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites);
526 FIRM_API ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos);
527 FIRM_API void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites);
528 FIRM_API void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
531 * Checks whether a pointer points to an entity.
533 * @param thing an arbitrary pointer
536 * true if the thing is an entity, else false
538 FIRM_API int is_entity(const void *thing);
540 /** Returns true if the type of the entity is a primitive, pointer
541 * enumeration or method type.
543 * @note This is a different classification than from is_primitive_type().
545 FIRM_API int is_atomic_entity(const ir_entity *ent);
546 /** Returns true if the type of the entity is a class, structure,
547 array or union type. */
548 FIRM_API int is_compound_entity(const ir_entity *ent);
549 /** Returns true if the type of the entity is a Method type. */
550 FIRM_API int is_method_entity(const ir_entity *ent);
552 /** Outputs a unique number for this entity if libfirm is compiled for
553 * debugging, (configure with --enable-debug) else returns the address
554 * of the type cast to long.
556 FIRM_API long get_entity_nr(const ir_entity *ent);
558 /** Returns the entities visited count. */
559 FIRM_API ir_visited_t get_entity_visited(const ir_entity *ent);
561 /** Sets the entities visited count. */
562 FIRM_API void set_entity_visited(ir_entity *ent, ir_visited_t num);
564 /** Sets visited field in entity to entity_visited. */
565 FIRM_API void mark_entity_visited(ir_entity *ent);
567 /** Returns true if this entity was visited. */
568 FIRM_API int entity_visited(const ir_entity *ent);
570 /** Returns true if this entity was not visited. */
571 FIRM_API int entity_not_visited(const ir_entity *ent);
574 * Returns the mask of the additional entity properties.
575 * The properties are automatically inherited from the irg if available
576 * or from the method type if they were not set using
577 * set_entity_additional_properties() or
578 * set_entity_additional_property().
580 FIRM_API mtp_additional_properties get_entity_additional_properties(const ir_entity *ent);
582 /** Sets the mask of the additional graph properties. */
583 FIRM_API void set_entity_additional_properties(ir_entity *ent,
584 mtp_additional_properties prop);
586 /** Sets additional graph properties. */
587 FIRM_API void add_entity_additional_properties(ir_entity *ent,
588 mtp_additional_properties flag);
590 /** Returns the class type that this type info entity represents or NULL
591 if ent is no type info entity. */
592 FIRM_API ir_type *get_entity_repr_class(const ir_entity *ent);
595 * @page unknown_entity The Unknown entity
597 * This entity is an auxiliary entity dedicated to support analyses.
599 * The unknown entity represents that there could be an entity, but it is not
600 * known. This entity can be used to initialize fields before an analysis (not known
601 * yet) or to represent the top of a lattice (could not be determined). There exists
602 * exactly one entity unknown. This entity has as owner and as type the unknown type. It is
603 * allocated when initializing the entity module.
605 * The entity can take the role of any entity, also methods. It returns default
606 * values in these cases.
608 * The following values are set:
610 * - name = "unknown_entity"
611 * - ld_name = "unknown_entity"
612 * - owner = unknown_type
613 * - type = unknown_type
615 * - value = SymConst(unknown_entity)
618 * - volatility = volatility_non_volatile
619 * - stickyness = stickyness_unsticky
621 * - overwrites = NULL
622 * - overwrittenby = NULL
627 /** A variable that contains the only unknown entity. */
628 FIRM_API ir_entity *unknown_entity;
630 /** Returns the @link unknown_entity unknown entity @endlink. */
631 FIRM_API ir_entity *get_unknown_entity(void);
633 /** Encodes how a pointer parameter is accessed. */
634 typedef enum ptr_access_kind {
635 ptr_access_none = 0, /**< no access */
636 ptr_access_read = 1, /**< read access */
637 ptr_access_write = 2, /**< write access */
638 ptr_access_rw = ptr_access_read|ptr_access_write, /**< read AND write access */
639 ptr_access_store = 4, /**< the pointer is stored */
640 ptr_access_all = ptr_access_rw|ptr_access_store /**< all possible access */
642 ENUM_BITSET(ptr_access_kind)
644 #define IS_READ(a) ((a) & ptr_access_read)
645 #define IS_WRITTEN(a) ((a) & ptr_access_write)
646 #define IS_STORED(a) ((a) & ptr_access_store)
649 * @page tyop type operations
650 * This module specifies the kinds of types available in firm.
652 * They are called type opcodes. These include classes, structs, methods, unions,
653 * arrays, enumerations, pointers and primitive types.
654 * Special types with own opcodes are the id type, a type representing an unknown
655 * type and a type used to specify that something has no type.
659 * An enum for the type kinds.
660 * For each type kind exists a typecode to identify it.
663 tpo_uninitialized = 0, /* not a type opcode */
664 tpo_class, /**< A class type. */
665 tpo_struct, /**< A struct type. */
666 tpo_method, /**< A method type. */
667 tpo_union, /**< An union type. */
668 tpo_array, /**< An array type. */
669 tpo_enumeration, /**< An enumeration type. */
670 tpo_pointer, /**< A pointer type. */
671 tpo_primitive, /**< A primitive type. */
672 tpo_code, /**< a piece of code (a basic block) */
673 tpo_none, /**< Special type for the None type. */
674 tpo_unknown, /**< Special code for the Unknown type. */
675 tpo_last = tpo_unknown /* not a type opcode */
679 * A structure containing information about a kind of type.
680 * A structure containing information about a kind of type. So far
681 * this is only the kind name, an enum for case-switching and some
684 * @see get_tpop_name(), get_tpop_code()
686 typedef struct tp_op tp_op;
690 * Returns the string for the type opcode.
692 * @param op The type opcode to get the string from.
695 FIRM_API const char *get_tpop_name(const tp_op *op);
698 * Returns an enum for the type opcode.
700 * @param op The type opcode to get the enum from.
703 FIRM_API tp_opcode get_tpop_code(const tp_op *op);
706 * This type opcode marks that the corresponding type is a class type.
708 * Consequently the type refers to supertypes, subtypes and entities.
709 * Entities can be any fields, but also methods.
710 * @@@ value class or not???
711 * This struct is dynamically allocated but constant for the lifetime
714 FIRM_API const tp_op *type_class;
715 FIRM_API const tp_op *get_tpop_class(void);
718 * This type opcode marks that the corresponding type is a compound type
721 * Consequently the type refers to a list of entities
722 * which may not be methods (but pointers to methods).
723 * This struct is dynamically allocated but constant for the lifetime
726 FIRM_API const tp_op *type_struct;
727 FIRM_API const tp_op *get_tpop_struct(void);
730 * This type opcode marks that the corresponding type is a method type.
732 * Consequently it refers to a list of arguments and results.
733 * This struct is dynamically allocated but constant for the lifetime
736 FIRM_API const tp_op *type_method;
737 FIRM_API const tp_op *get_tpop_method(void);
740 * This type opcode marks that the corresponding type is a union type.
742 * Consequently it refers to a list of unioned types.
743 * This struct is dynamically allocated but constant for the lifetime
746 FIRM_API const tp_op *type_union;
747 FIRM_API const tp_op *get_tpop_union(void);
750 * This type opcode marks that the corresponding type is an array type.
752 * Consequently it contains a list of dimensions (lower and upper bounds)
753 * and an element type.
754 * This struct is dynamically allocated but constant for the lifetime
757 FIRM_API const tp_op *type_array;
758 FIRM_API const tp_op *get_tpop_array(void);
761 * This type opcode marks that the corresponding type is an enumeration type.
763 * Consequently it contains a list of idents for the enumeration identifiers
764 * and a list of target values that are the constants used to implement
766 * This struct is dynamically allocated but constant for the lifetime
769 FIRM_API const tp_op *type_enumeration;
770 FIRM_API const tp_op *get_tpop_enumeration(void);
773 * This type opcode marks that the corresponding type is a pointer type.
775 * It contains a reference to the type the pointer points to.
776 * This struct is dynamically allocated but constant for the lifetime
779 FIRM_API const tp_op *type_pointer;
780 FIRM_API const tp_op *get_tpop_pointer(void);
783 * This type opcode marks that the corresponding type is a primitive type.
785 * Primitive types are types that are directly mapped to target machine
787 * This struct is dynamically allocated but constant for the lifetime
790 FIRM_API const tp_op *type_primitive;
791 FIRM_API const tp_op *get_tpop_primitive(void);
794 * The code type is used to mark pieces of code (basic blocks)
796 FIRM_API const tp_op *tpop_code;
797 FIRM_API const tp_op *get_tpop_code_type(void);
800 * This type opcode is an auxiliary opcode dedicated to support type analyses.
802 * Types with this opcode represents that there is no type.
803 * The type can be used to initialize fields of the type* that actually can not
804 * contain a type or that are initialized for an analysis. There exists exactly
805 * one type with this opcode.
807 FIRM_API const tp_op *tpop_none;
808 FIRM_API const tp_op *get_tpop_none(void);
811 * This type opcode is an auxiliary opcode dedicated to support type analyses.
813 * Types with this opcode represents that there could be a type, but it is not
814 * known. This type can be used to initialize fields before an analysis (not known
815 * yet) or to represent the top of a lattice (could not be determined). There exists
816 * exactly one type with this opcode.
818 FIRM_API const tp_op *tpop_unknown;
819 FIRM_API const tp_op *get_tpop_unknown(void);
821 /* ----------------------------------------------------------------------- */
822 /* Classify pairs of types/entities in the inheritance relations. */
823 /* ----------------------------------------------------------------------- */
825 /** Returns true if low is subclass of high.
827 * Low is a subclass of high if low == high or if low is a subclass of
828 * a subclass of high. I.e, we search in all subtypes of high for low.
829 * @@@ this can be implemented more efficient if we know the set of all
830 * subclasses of high. */
831 FIRM_API int is_SubClass_of(ir_type *low, ir_type *high);
833 /** Subclass check for pointers to classes.
835 * Dereferences at both types the same amount of pointer types (as
836 * many as possible). If the remaining types are both class types
837 * and subclasses, returns true, else false. Can also be called with
838 * two class types. */
839 FIRM_API int is_SubClass_ptr_of(ir_type *low, ir_type *high);
841 /** Returns true if high is superclass of low.
843 * Low is a subclass of high if low == high or if low is a subclass of
844 * a subclass of high. I.e, we search in all subtypes of high for low.
845 * @@@ this can be implemented more efficient if we know the set of all
846 * subclasses of high. */
847 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
849 /** Superclass check for pointers to classes.
851 * Dereferences at both types the same amount of pointer types (as
852 * many as possible). If the remaining types are both class types
853 * and superclasses, returns true, else false. Can also be called with
854 * two class types. */
855 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
857 /** Returns true if high is (transitive) overwritten by low.
859 * Returns false if high == low. */
860 FIRM_API int is_overwritten_by(ir_entity *high, ir_entity *low);
862 /** Resolve polymorphism in the inheritance relation.
864 * Returns the dynamically referenced entity if the static entity and the
865 * dynamic type are given.
866 * Searches downwards in overwritten tree. */
867 FIRM_API ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class,
868 ir_entity* static_ent);
870 /* ----------------------------------------------------------------------- */
871 /* Resolve implicit inheritance. */
872 /* ----------------------------------------------------------------------- */
874 /** Default name mangling for inherited entities.
876 * Returns an ident that consists of the name of type followed by an
877 * underscore and the name (not ld_name) of the entity. */
878 FIRM_API ident *default_mangle_inherited_name(const ir_entity *ent,
879 const ir_type *clss);
881 /** Type of argument functions for inheritance resolver.
883 * @param ent The entity in the super type that will be overwritten
884 * by the newly generated entity, for which this name is
886 * @param clss The class type in which the new entity will be placed.
888 typedef ident *mangle_inherited_name_func(const ir_entity *ent,
889 const ir_type *clss);
891 /** Resolve implicit inheritance.
893 * Resolves the implicit inheritance supplied by firm. Firm defines,
894 * that each entity that is not overwritten in a subclass is
895 * inherited to this subclass without change implicitly. This
896 * function generates entities that explicitly represent this
897 * inheritance. It generates for each entity overwriting entities in
898 * all subclasses of the owner of the entity, if the entity is not
899 * overwritten in that subclass.
901 * The name of the new entity is generated with the function passed.
902 * If the function is NULL, the default_mangle_inherited_name() is
905 FIRM_API void resolve_inheritance(mangle_inherited_name_func *mfunc);
908 /* ----------------------------------------------------------------------- */
909 /* The transitive closure of the subclass/superclass and */
910 /* overwrites/overwrittenby relation. */
912 /* A walk over the ir (O(#types+#entities)) computes the transitive */
913 /* closure. Adding a new type/entity or changing the basic relations in */
914 /* some other way invalidates the transitive closure, i.e., it is not */
915 /* updated by the basic functions. */
917 /* The transitive edges are held in a set, not in an array as the */
918 /* underlying relation. */
920 /* Do the sets contain the node itself? I assume NOT! */
921 /* ----------------------------------------------------------------------- */
924 * The state of the transitive closure.
927 inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */
928 inh_transitive_closure_valid, /**< Closure computed and valid. */
929 inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */
930 inh_transitive_closure_max /**< Invalid value. */
931 } inh_transitive_closure_state;
933 FIRM_API void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
934 FIRM_API void invalidate_irp_inh_transitive_closure_state(void);
935 FIRM_API inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
938 /** Compute transitive closure of the subclass/superclass and
939 * overwrites/overwrittenby relation.
941 * This function walks over the ir (O(\#types+\#entities)) to compute the
942 * transitive closure. */
943 FIRM_API void compute_inh_transitive_closure(void);
945 /** Free memory occupied by the transitive closure information. */
946 FIRM_API void free_inh_transitive_closure(void);
949 /* - subtype ------------------------------------------------------------- */
951 /** Iterate over all transitive subtypes. */
952 FIRM_API ir_type *get_class_trans_subtype_first(const ir_type *tp);
953 FIRM_API ir_type *get_class_trans_subtype_next(const ir_type *tp);
954 FIRM_API int is_class_trans_subtype(const ir_type *tp, const ir_type *subtp);
956 /* - supertype ----------------------------------------------------------- */
958 /** Iterate over all transitive supertypes. */
959 FIRM_API ir_type *get_class_trans_supertype_first(const ir_type *tp);
960 FIRM_API ir_type *get_class_trans_supertype_next(const ir_type *tp);
962 /* - overwrittenby ------------------------------------------------------- */
964 /** Iterate over all entities that transitive overwrite this entities. */
965 FIRM_API ir_entity *get_entity_trans_overwrittenby_first(const ir_entity *ent);
966 FIRM_API ir_entity *get_entity_trans_overwrittenby_next(const ir_entity *ent);
968 /* - overwrites ---------------------------------------------------------- */
970 /** Iterate over all transitive overwritten entities. */
971 FIRM_API ir_entity *get_entity_trans_overwrites_first(const ir_entity *ent);
972 FIRM_API ir_entity *get_entity_trans_overwrites_next(const ir_entity *ent);
975 /* ----------------------------------------------------------------------- */
976 /** The state of Cast operations that cast class types or pointers to class
979 * The state expresses, how far Cast operations conform with the class
983 * class B1 extends A {}
984 * class B2 extends A {}
985 * class C extends B1 {}
986 * normalized: Cast operations conform with the inheritance relation.
987 * I.e., the type of the operand of a Cast is either a super= or a sub-
988 * type of the type casted to. Example: (A)((B2) (new C())).
989 * transitive: Cast operations conform with the transitive inheritance
990 * relation. Example: (A)(new C()).
991 * any: Cast operations do not conform with the transitive inheritance
992 * relation. Example: (B2)(new B1())
994 /* ----------------------------------------------------------------------- */
996 /** Flags for class cast state.
998 * The state in irp is always smaller or equal to the state of any
1001 * We rely on the ordering of the enum. */
1003 ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with
1004 the class hierarchy. @@@ So far this does not happen in Firm. */
1005 ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */
1006 ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */
1007 ir_class_casts_state_max
1008 } ir_class_cast_state;
1009 FIRM_API const char *get_class_cast_state_string(ir_class_cast_state s);
1011 FIRM_API void set_irg_class_cast_state(ir_graph *irg,
1012 ir_class_cast_state s);
1013 FIRM_API ir_class_cast_state get_irg_class_cast_state(const ir_graph *irg);
1014 FIRM_API void set_irp_class_cast_state(ir_class_cast_state s);
1015 FIRM_API ir_class_cast_state get_irp_class_cast_state(void);
1017 /** Verify the class cast state of an irg.
1019 * Asserts if state is to high, outputs debug warning if state is to low
1020 * and firm verbosity is set.
1022 FIRM_API void verify_irg_class_cast_state(ir_graph *irg);
1025 * possible trverify() error codes
1027 enum trverify_error_codes {
1028 no_error = 0, /**< no error */
1029 error_ent_not_cont, /**< overwritten entity not in superclass */
1030 error_null_mem, /**< compound contains NULL member */
1031 error_const_on_wrong_irg, /**< constant placed on wrong IRG */
1032 error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */
1033 error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */
1034 error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */
1035 error_glob_ent_allocation, /**< wrong allocation of a global entity */
1036 error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */
1037 error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */
1044 * 0 if no error encountered
1046 FIRM_API int check_type(ir_type *tp);
1049 * Check an entity. Currently, we check only if initialized constants
1050 * are build on the const irg graph.
1053 * 0 if no error encountered
1054 * != 0 a trverify_error_codes code
1056 FIRM_API int check_entity(ir_entity *ent);
1059 * Walks the type information and performs a set of sanity checks.
1061 * Currently, the following checks are executed:
1062 * - values of initialized entities must be allocated on the constant IRG
1063 * - class types: doesn't have NULL members
1064 * - class types: all overwrites are existent in the super type
1067 * 0 if graph is correct
1070 FIRM_API int tr_verify(void);
1073 * @page type representation of types
1075 * Datastructure to hold type information.
1077 * This module supplies a datastructure to represent all types
1078 * known in the compiled program. This includes types specified
1079 * in the program as well as types defined by the language. In the
1080 * view of the intermediate representation there is no difference
1081 * between these types. Finally it specifies some auxiliary types.
1083 * There exist several kinds of types, arranged by the structure of
1084 * the type. A type is described by a set of attributes. Some of
1085 * these attributes are common to all types, others depend on the
1088 * Types are different from the modes defined in irmode: Types are
1089 * on the level of the programming language, modes at the level of
1090 * the target processor.
1093 /** Frees all entities associated with a type.
1094 * Does not free the array entity.
1095 * Warning: ensure these entities are not referenced anywhere else.
1097 FIRM_API void free_type_entities(ir_type *tp);
1099 /** Frees the memory used by the type.
1101 * Removes the type from the type list. Does not free the entities
1102 * belonging to the type, except for the array element entity. Does
1103 * not free if tp is "none" or "unknown". Frees entities in value
1104 * param subtypes of method types!!! Make sure these are not
1105 * referenced any more. Further make sure there is no pointer type
1106 * that refers to this type. */
1107 FIRM_API void free_type(ir_type *tp);
1109 FIRM_API const tp_op *get_type_tpop(const ir_type *tp);
1110 FIRM_API ident *get_type_tpop_nameid(const ir_type *tp);
1111 FIRM_API const char *get_type_tpop_name(const ir_type *tp);
1112 FIRM_API tp_opcode get_type_tpop_code(const ir_type *tp);
1115 * construct a string representing the type.
1116 * This uses the info retrieved by the type_dbg_info if available.
1117 * Otherwise it tries to create an approximate textual representation of the
1119 * Keep in mind that this representation is not unique for each type,
1120 * might abstract away some details. The main intention of this is creating
1121 * human redable strings giving an idea of the type.
1123 FIRM_API void ir_print_type(char *buffer, size_t buffer_size,
1126 /** The state of the type layout. */
1128 layout_undefined, /**< The layout of this type is not defined.
1129 Address computation to access fields is not
1130 possible, fields must be accessed by Sel
1131 nodes. Enumeration constants might be undefined.
1132 This is the default value except for
1133 pointer, primitive and method types. */
1134 layout_fixed /**< The layout is fixed, all component/member entities
1135 have an offset assigned. Size of the type is known.
1136 Arrays can be accessed by explicit address
1137 computation. Enumeration constants must be defined.
1138 Default for pointer, primitive and method types. */
1141 /** Returns a human readable string for the enum entry. */
1142 FIRM_API const char *get_type_state_name(ir_type_state s);
1144 /** Returns the type layout state of a type. */
1145 FIRM_API ir_type_state get_type_state(const ir_type *tp);
1147 /** Sets the type layout state of a type.
1149 * For primitives, pointer and method types the layout is always fixed.
1150 * This call is legal but has no effect.
1152 FIRM_API void set_type_state(ir_type *tp, ir_type_state state);
1154 /** Returns the mode of a type.
1156 * Returns NULL for all non atomic types.
1158 FIRM_API ir_mode *get_type_mode(const ir_type *tp);
1160 /** Sets the mode of a type.
1162 * Only has an effect on primitive, enumeration and pointer types.
1164 FIRM_API void set_type_mode(ir_type *tp, ir_mode* m);
1166 /** Returns the size of a type in bytes. */
1167 FIRM_API unsigned get_type_size_bytes(const ir_type *tp);
1169 /** Sets the size of a type in bytes.
1171 * For primitive, enumeration, pointer and method types the size
1172 * is always fixed. This call is legal but has no effect.
1174 FIRM_API void set_type_size_bytes(ir_type *tp, unsigned size);
1176 /** Returns the alignment of a type in bytes. */
1177 FIRM_API unsigned get_type_alignment_bytes(ir_type *tp);
1179 /** Returns the alignment of a type in bits.
1181 * If the alignment of a type is
1182 * not set, it is calculated here according to the following rules:
1183 * -#.) if a type has a mode, the alignment is the mode size.
1184 * -#.) compound types have the alignment of there biggest member.
1185 * -#.) array types have the alignment of there element type.
1186 * -#.) method types return 0 here.
1187 * -#.) all other types return 1 here (i.e. aligned at byte).
1189 FIRM_API void set_type_alignment_bytes(ir_type *tp, unsigned align);
1191 /** Returns the visited count of a type. */
1192 FIRM_API ir_visited_t get_type_visited(const ir_type *tp);
1193 /** Sets the visited count of a type to num. */
1194 FIRM_API void set_type_visited(ir_type *tp, ir_visited_t num);
1195 /** Sets visited field in type to type_visited. */
1196 FIRM_API void mark_type_visited(ir_type *tp);
1197 /** Returns non-zero if the type is already visited */
1198 FIRM_API int type_visited(const ir_type *tp);
1199 /** Returns non-zero if the type is not yet visited */
1200 FIRM_API int type_not_visited(const ir_type *tp);
1202 /** Returns the associated link field of a type. */
1203 FIRM_API void *get_type_link(const ir_type *tp);
1204 /** Sets the associated link field of a type. */
1205 FIRM_API void set_type_link(ir_type *tp, void *l);
1208 * Visited flag to traverse the type information.
1210 * Increase this flag by one before traversing the type information
1211 * using inc_master_type_visited().
1212 * Mark type nodes as visited by mark_type_visited(ir_type).
1213 * Check whether node was already visited by type_visited(ir_type)
1214 * and type_not_visited(ir_type).
1215 * Or use the function to walk all types.
1219 FIRM_API void set_master_type_visited(ir_visited_t val);
1220 FIRM_API ir_visited_t get_master_type_visited(void);
1221 FIRM_API void inc_master_type_visited(void);
1224 * Sets the debug information of a type.
1226 * @param tp The type.
1227 * @param db The debug info.
1229 FIRM_API void set_type_dbg_info(ir_type *tp, type_dbg_info *db);
1232 * Returns the debug information of a type.
1234 * @param tp The type.
1236 FIRM_API type_dbg_info *get_type_dbg_info(const ir_type *tp);
1239 * Checks whether a pointer points to a type.
1241 * @param thing an arbitrary pointer
1244 * true if the thing is a type, else false
1246 FIRM_API int is_type(const void *thing);
1249 * Checks whether two types are structurally equal.
1251 * @param typ1 the first type
1252 * @param typ2 the second type
1255 * true if the types are equal, else false.
1257 * Types are equal if :
1258 * - they are the same type kind
1259 * - they have the same name
1260 * - they have the same mode (if applicable)
1261 * - they have the same type_state and, ev., the same size
1262 * - they are class types and have:
1263 * - the same members (see same_entity in entity.h)
1264 * - the same supertypes -- the C-pointers are compared --> no recursive call.
1265 * - the same number of subtypes. Subtypes are not compared,
1266 * as this could cause a cyclic test.
1267 * - they are structure types and have the same members
1268 * - they are method types and have
1269 * - the same parameter types
1270 * - the same result types
1271 * - they are union types and have the same members
1272 * - they are array types and have
1273 * - the same number of dimensions
1274 * - the same dimension bounds
1275 * - the same dimension order
1276 * - the same element type
1277 * - they are enumeration types and have the same enumerator names
1278 * - they are pointer types and have the identical points_to type
1279 * (i.e., the same C-struct to represent the type.
1280 * This is to avoid endless recursions; with pointer types cyclic
1281 * type graphs are possible.)
1283 FIRM_API int equal_type(ir_type *typ1, ir_type *typ2);
1286 * Checks whether two types are structural comparable.
1288 * @param st pointer type
1289 * @param lt pointer type
1292 * true if type st is smaller than type lt, i.e. whenever
1293 * lt is expected a st can be used.
1295 * - they are the same type kind
1296 * - mode(st) < mode (lt) (if applicable)
1297 * - they are class types and st is (transitive) subtype of lt,
1298 * - they are structure types and
1299 * - the members of st have exactly one counterpart in lt with the same name,
1300 * - the counterpart has a bigger type.
1301 * - they are method types and have
1302 * - the same number of parameter and result types,
1303 * - the parameter types of st are smaller than those of lt,
1304 * - the result types of st are smaller than those of lt
1305 * - they are union types and have the members of st have exactly one
1306 * @return counterpart in lt and the type is smaller
1307 * - they are array types and have
1308 * - the same number of dimensions
1309 * - all bounds of lt are bound of st
1310 * - the same dimension order
1311 * - the same element type
1313 * - the element type of st is smaller than that of lt
1314 * - the element types have the same size and fixed layout.
1315 * - they are enumeration types and have the same enumerator names
1316 * - they are pointer types and have the points_to type of st is
1317 * @return smaller than the points_to type of lt.
1320 FIRM_API int smaller_type(ir_type *st, ir_type *lt);
1323 * @page class_type Representation of a class type
1325 * If the type opcode is set to type_class the type represents class
1326 * types. A list of fields and methods is associated with a class.
1327 * Further a class can inherit from and bequest to other classes.
1329 * The following attributes are private to this type kind:
1330 * - member: All entities belonging to this class. This are method entities
1331 * which have type_method or fields that can have any of the
1332 * following type kinds: type_class, type_struct, type_union,
1333 * type_array, type_enumeration, type_pointer, type_primitive.
1335 * The following two are dynamic lists that can be grown with an "add_" function,
1338 * - subtypes: A list of direct subclasses.
1340 * - supertypes: A list of direct superclasses.
1342 * - type_info: An entity representing the type information of this class.
1343 * This entity can be of arbitrari type, Firm did not use it yet.
1344 * It allows to express the coupling of a type with an entity
1345 * representing this type. This information is useful for lowering
1346 * of InstOf and TypeChk nodes. Default: NULL
1348 * - vtable_size: The size of this class virtual function table.
1351 * - final: A final class is always a leaf in the class hierarchy. Final
1352 * classes cannot be super classes of other ones. As this information
1353 * can only be computed in whole world compilations, we allow to
1354 * set this flag. It is used in optimizations if get_opt_closed_world()
1355 * is false. Default: false
1357 * - interface: The class represents an interface. This flag can be set to distinguish
1358 * between interfaces, abstract classes and other classes that all may
1359 * have the peculiarity peculiarity_description. Depending on this flag
1360 * the lowering might do different actions. Default: false
1362 * - abstract : The class represents an abstract class. This flag can be set to distinguish
1363 * between interfaces, abstract classes and other classes that all may
1364 * have the peculiarity peculiarity_description. Depending on this flag
1365 * the lowering might do different actions. Default: false
1368 /** Creates a new class type. */
1369 FIRM_API ir_type *new_type_class(ident *name);
1371 /** Creates a new class type with debug information. */
1372 FIRM_API ir_type *new_d_type_class(ident *name, type_dbg_info *db);
1374 /* --- manipulate private fields of class type --- */
1376 /** return identifier of the class type */
1377 FIRM_API ident *get_class_ident(const ir_type *clss);
1379 /** return identifier of the class type */
1380 FIRM_API const char *get_class_name(const ir_type *clss);
1382 /** Returns the number of members of this class. */
1383 FIRM_API int get_class_n_members(const ir_type *clss);
1385 /** Returns the member at position pos, 0 <= pos < n_member */
1386 FIRM_API ir_entity *get_class_member(const ir_type *clss, int pos);
1388 /** Returns index of mem in clss, -1 if not contained. */
1389 FIRM_API int get_class_member_index(const ir_type *clss, ir_entity *mem);
1391 /** Finds the member with name 'name'. If several members with the same
1392 * name returns one of them. Returns NULL if no member found. */
1393 FIRM_API ir_entity *get_class_member_by_name(ir_type *clss, ident *name);
1395 /** Adds subtype as subtype to clss.
1397 * Checks whether clss is a supertype of subtype. If not
1398 * adds also clss as supertype to subtype. */
1399 FIRM_API void add_class_subtype(ir_type *clss, ir_type *subtype);
1401 /** Returns the number of subtypes */
1402 FIRM_API int get_class_n_subtypes(const ir_type *clss);
1404 /** Gets the subtype at position pos, 0 <= pos < n_subtype. */
1405 FIRM_API ir_type *get_class_subtype(ir_type *clss, int pos);
1407 /** Returns the index to access subclass as subtype of class.
1409 * If subclass is no direct subtype of class returns -1.
1411 FIRM_API int get_class_subtype_index(ir_type *clss, const ir_type *subclass);
1413 /** Sets the subtype at position pos, 0 <= pos < n_subtype.
1415 * Does not set the corresponding supertype relation for subtype: this might
1416 * be a different position! */
1417 FIRM_API void set_class_subtype(ir_type *clss, ir_type *subtype, int pos);
1419 /** Finds subtype in the list of subtypes and removes it */
1420 FIRM_API void remove_class_subtype(ir_type *clss, ir_type *subtype);
1422 /* Convenience macros */
1423 #define add_class_derived_type(clss, drvtype) add_class_subtype(clss, drvtype)
1424 #define get_class_n_derived_types(clss) get_class_n_subtypes(clss)
1425 #define get_class_derived_type(clss, pos) get_class_subtype(clss, pos)
1426 #define get_class_derived_type_index(clss, drvtype) get_class_subtype_index(clss, drvtype)
1427 #define set_class_derived_type(clss, drvtype, pos) set_class_subtype(clss, drvtype, pos)
1428 #define remove_class_derived_type(clss, drvtype) remove_class_subtype(clss, drvtype)
1430 /** Adds supertype as supertype to class.
1432 * Checks whether clss is a subtype of supertype. If not
1433 * adds also clss as subtype to supertype. */
1434 FIRM_API void add_class_supertype(ir_type *clss, ir_type *supertype);
1436 /** Returns the number of supertypes */
1437 FIRM_API int get_class_n_supertypes(const ir_type *clss);
1439 /** Returns the index to access superclass as supertype of class.
1441 * If superclass is no direct supertype of class returns -1.
1443 FIRM_API int get_class_supertype_index(ir_type *clss, ir_type *super_clss);
1445 /** Gets the supertype at position pos, 0 <= pos < n_supertype. */
1446 FIRM_API ir_type *get_class_supertype(ir_type *clss, int pos);
1448 /** Sets the supertype at position pos, 0 <= pos < n_supertype.
1450 * Does not set the corresponding subtype relation for supertype: this might
1451 * be at a different position! */
1452 FIRM_API void set_class_supertype(ir_type *clss, ir_type *supertype, int pos);
1454 /** Finds supertype in the list of supertypes and removes it */
1455 FIRM_API void remove_class_supertype(ir_type *clss, ir_type *supertype);
1457 /** Convenience macro */
1458 #define add_class_base_type(clss, basetype) add_class_supertype(clss, basetype)
1459 #define get_class_n_base_types(clss) get_class_n_supertypes(clss)
1460 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
1461 #define get_class_base_type(clss, pos) get_class_supertype(clss, pos)
1462 #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos)
1463 #define remove_class_base_type(clss, basetype) remove_class_supertype(clss, basetype)
1465 /** Returns the type info entity of a class. */
1466 FIRM_API ir_entity *get_class_type_info(const ir_type *clss);
1468 /** Set a type info entity for the class. */
1469 FIRM_API void set_class_type_info(ir_type *clss, ir_entity *ent);
1471 /** Returns the size of the virtual function table. */
1472 FIRM_API unsigned get_class_vtable_size(const ir_type *clss);
1474 /** Sets a new size of the virtual function table. */
1475 FIRM_API void set_class_vtable_size(ir_type *clss, unsigned size);
1477 /** Returns non-zero if a class is final. */
1478 FIRM_API int is_class_final(const ir_type *clss);
1480 /** Sets the class final flag. */
1481 FIRM_API void set_class_final(ir_type *clss, int flag);
1483 /** Return non-zero if a class is an interface */
1484 FIRM_API int is_class_interface(const ir_type *clss);
1486 /** Sets the class interface flag. */
1487 FIRM_API void set_class_interface(ir_type *clss, int flag);
1489 /** Return non-zero if a class is an abstract class. */
1490 FIRM_API int is_class_abstract(const ir_type *clss);
1492 /** Sets the class abstract flag. */
1493 FIRM_API void set_class_abstract(ir_type *clss, int flag);
1495 /** Returns true if a type is a class type. */
1496 FIRM_API int is_Class_type(const ir_type *clss);
1499 * @page struct_type Representation of a struct type
1501 * A struct type represents aggregate types that consist of a list
1504 * The following attributes are private to this type kind:
1505 * - member: All entities belonging to this class. This are the fields
1506 * that can have any of the following types: type_class,
1507 * type_struct, type_union, type_array, type_enumeration,
1508 * type_pointer, type_primitive.
1509 * This is a dynamic list that can be grown with an "add_" function,
1511 * This is a dynamic list that can be grown with an "add_" function,
1514 /** Creates a new type struct */
1515 FIRM_API ir_type *new_type_struct(ident *name);
1516 /** Creates a new type struct with debug information. */
1517 FIRM_API ir_type *new_d_type_struct(ident *name, type_dbg_info* db);
1519 /* --- manipulate private fields of struct --- */
1521 /** return struct identifier */
1522 FIRM_API ident *get_struct_ident(const ir_type *strct);
1524 /** return struct identifier as c-string*/
1525 FIRM_API const char *get_struct_name(const ir_type *strct);
1527 /** Returns the number of members of this struct. */
1528 FIRM_API int get_struct_n_members(const ir_type *strct);
1530 /** Returns the member at position pos, 0 <= pos < n_member */
1531 FIRM_API ir_entity *get_struct_member(const ir_type *strct, int pos);
1533 /** Returns index of member in strct, -1 if not contained. */
1534 FIRM_API int get_struct_member_index(const ir_type *strct, ir_entity *member);
1536 /** Returns true if a type is a struct type. */
1537 FIRM_API int is_Struct_type(const ir_type *strct);
1540 * @page method_type Representation of a method type
1542 * A method type represents a method, function or procedure type.
1543 * It contains a list of the parameter and result types, as these
1544 * are part of the type description. These lists should not
1545 * be changed by a optimization, as a change creates a new method
1546 * type. Therefore optimizations should allocated new method types.
1547 * The set_ routines are only for construction by a frontend.
1549 * - n_params: Number of parameters to the procedure.
1550 * A procedure in FIRM has only call by value parameters.
1552 * - param_type: A list with the types of parameters. This list is ordered.
1553 * The nth type in this list corresponds to the nth element
1554 * in the parameter tuple that is a result of the start node.
1555 * (See ircons.h for more information.)
1557 * - value_param_ents
1558 * A list of entities (whose owner is a struct private to the
1559 * method type) that represent parameters passed by value.
1561 * - n_res: The number of results of the method. In general, procedures
1562 * have zero results, functions one.
1564 * - res_type: A list with the types of parameters. This list is ordered.
1565 * The nth type in this list corresponds to the nth input to
1566 * Return nodes. (See ircons.h for more information.)
1569 * A list of entities (whose owner is a struct private to the
1570 * method type) that represent results passed by value.
1573 /* These macros define the suffixes for the types and entities used
1574 to represent value parameters / results. */
1575 #define VALUE_PARAMS_SUFFIX "val_param"
1576 #define VALUE_RESS_SUFFIX "val_res"
1578 /** Create a new method type.
1580 * @param n_param the number of parameters
1581 * @param n_res the number of results
1583 * The arrays for the parameter and result types are not initialized by
1586 FIRM_API ir_type *new_type_method(int n_param, int n_res);
1588 /** Create a new method type with debug information.
1590 * @param n_param the number of parameters
1591 * @param n_res the number of results
1592 * @param db user defined debug information
1594 * The arrays for the parameter and result types are not initialized by
1597 FIRM_API ir_type *new_d_type_method(int n_param, int n_res, type_dbg_info *db);
1599 /* -- manipulate private fields of method. -- */
1601 /** Returns the number of parameters of this method. */
1602 FIRM_API int get_method_n_params(const ir_type *method);
1604 /** Returns the type of the parameter at position pos of a method. */
1605 FIRM_API ir_type *get_method_param_type(ir_type *method, int pos);
1606 /** Sets the type of the parameter at position pos of a method.
1607 Also changes the type in the pass-by-value representation by just
1608 changing the type of the corresponding entity if the representation is constructed. */
1609 FIRM_API void set_method_param_type(ir_type *method, int pos, ir_type *tp);
1610 /** Returns an entity that represents the copied value argument. Only necessary
1611 for compounds passed by value. This information is constructed only on demand. */
1612 FIRM_API ir_entity *get_method_value_param_ent(ir_type *method, int pos);
1614 * Sets the type that represents the copied value arguments.
1616 FIRM_API void set_method_value_param_type(ir_type *method, ir_type *tp);
1618 * Returns a type that represents the copied value arguments if one
1619 * was allocated, else NULL.
1621 FIRM_API ir_type *get_method_value_param_type(const ir_type *method);
1622 /** Returns an ident representing the parameters name. Returns NULL if not set.
1623 For debug support only. */
1624 FIRM_API ident *get_method_param_ident(ir_type *method, int pos);
1625 /** Returns a string representing the parameters name. Returns NULL if not set.
1626 For debug support only. */
1627 FIRM_API const char *get_method_param_name(ir_type *method, int pos);
1628 /** Sets an ident representing the parameters name. For debug support only. */
1629 FIRM_API void set_method_param_ident(ir_type *method, int pos, ident *id);
1631 /** Returns the number of results of a method type. */
1632 FIRM_API int get_method_n_ress(const ir_type *method);
1633 /** Returns the return type of a method type at position pos. */
1634 FIRM_API ir_type *get_method_res_type(ir_type *method, int pos);
1635 /** Sets the type of the result at position pos of a method.
1636 Also changes the type in the pass-by-value representation by just
1637 changing the type of the corresponding entity if the representation is constructed. */
1638 FIRM_API void set_method_res_type(ir_type *method, int pos, ir_type *tp);
1639 /** Returns an entity that represents the copied value result. Only necessary
1640 for compounds passed by value. This information is constructed only on demand. */
1641 FIRM_API ir_entity *get_method_value_res_ent(ir_type *method, int pos);
1644 * Returns a type that represents the copied value results.
1646 FIRM_API ir_type *get_method_value_res_type(const ir_type *method);
1649 * This enum flags the variadicity of methods (methods with a
1650 * variable amount of arguments (e.g. C's printf). Default is
1653 typedef enum ir_variadicity {
1654 variadicity_non_variadic, /**< non variadic */
1655 variadicity_variadic /**< variadic */
1658 /** Returns the null-terminated name of this variadicity. */
1659 FIRM_API const char *get_variadicity_name(ir_variadicity vari);
1661 /** Returns the variadicity of a method. */
1662 FIRM_API ir_variadicity get_method_variadicity(const ir_type *method);
1664 /** Sets the variadicity of a method. */
1665 FIRM_API void set_method_variadicity(ir_type *method, ir_variadicity vari);
1668 * Returns the first variadic parameter index of a type.
1669 * If this index was NOT set, the index of the last parameter
1670 * of the method type plus one is returned for variadic functions.
1671 * Non-variadic function types always return -1 here.
1673 FIRM_API int get_method_first_variadic_param_index(const ir_type *method);
1676 * Sets the first variadic parameter index. This allows to specify
1677 * a complete call type (containing the type of all parameters)
1678 * but still have the knowledge, which parameter must be passed as
1681 FIRM_API void set_method_first_variadic_param_index(ir_type *method, int index);
1683 /** Returns the mask of the additional graph properties. */
1684 FIRM_API mtp_additional_properties get_method_additional_properties(const ir_type *method);
1686 /** Sets the mask of the additional graph properties. */
1687 FIRM_API void set_method_additional_properties(ir_type *method,
1688 mtp_additional_properties property_mask);
1690 /** Sets one additional graph property. */
1691 FIRM_API void add_method_additional_properties(ir_type *method,
1692 mtp_additional_properties flag);
1695 * Calling conventions: lower 24 bits are the number of register parameters,
1696 * upper 8 encode the calling conventions.
1699 cc_reg_param = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
1700 This flag may be set as default on some architectures. */
1701 cc_last_on_top = 0x02000000, /**< The last non-register parameter is transmitted on top of
1702 the stack. This is equivalent to the pascal
1703 calling convention. If this flag is not set, the first
1704 non-register parameter is used (stdcall or cdecl
1705 calling convention) */
1706 cc_callee_clear_stk = 0x04000000, /**< The callee clears the stack. This forbids variadic
1707 function calls (stdcall). */
1708 cc_this_call = 0x08000000, /**< The first parameter is a this pointer and is transmitted
1709 in a special way. */
1710 cc_compound_ret = 0x10000000, /**< The method returns a compound type. */
1711 cc_frame_on_caller_stk = 0x20000000, /**< The method did not allocate an own stack frame, instead the
1712 caller must reserve size on its own stack. */
1713 cc_fpreg_param = 0x40000000, /**< Transmit floating point parameters in registers, else the stack is used. */
1714 cc_bits = (0xFF << 24)/**< The calling convention bits. */
1715 } calling_convention;
1717 /* some often used cases: made as defines because firmjni cannot handle two
1718 equal enum values. */
1720 /** cdecl calling convention */
1721 #define cc_cdecl_set (0)
1722 /** stdcall calling convention */
1723 #define cc_stdcall_set cc_callee_clear_stk
1724 /** fastcall calling convention */
1725 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
1728 * check for the CDECL calling convention
1730 #define IS_CDECL(cc_mask) (((cc_mask) & cc_bits) == cc_cdecl_set)
1733 * check for the STDCALL calling convention
1735 #define IS_STDCALL(cc_mask) (((cc_mask) & cc_bits) == cc_stdcall_set)
1738 * check for the FASTCALL calling convention
1740 #define IS_FASTCALL(cc_mask) (((cc_mask) & cc_bits) == cc_fastcall_set)
1743 * Sets the CDECL convention bits.
1745 #define SET_CDECL(cc_mask) (((cc_mask) & ~cc_bits) | cc_cdecl_set)
1748 * Set. the STDCALL convention bits.
1750 #define SET_STDCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_stdcall_set)
1753 * Sets the FASTCALL convention bits.
1755 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
1757 /** Returns the calling convention of an entities graph. */
1758 FIRM_API unsigned get_method_calling_convention(const ir_type *method);
1760 /** Sets the calling convention of an entities graph. */
1761 FIRM_API void set_method_calling_convention(ir_type *method, unsigned cc_mask);
1763 /** Returns the number of registers parameters, 0 means default. */
1764 FIRM_API unsigned get_method_n_regparams(ir_type *method);
1766 /** Sets the number of registers parameters, 0 means default. */
1767 FIRM_API void set_method_n_regparams(ir_type *method, unsigned n_regs);
1769 /** Returns true if a type is a method type. */
1770 FIRM_API int is_Method_type(const ir_type *method);
1773 * @page union_type Representation of a union (variant) type.
1775 * The union type represents union types. Note that this representation
1776 * resembles the C union type. For tagged variant types like in Pascal or Modula
1777 * a combination of a struct and a union type must be used.
1779 * - n_types: Number of unioned types.
1780 * - members: Entities for unioned types. Fixed length array.
1781 * This is a dynamic list that can be grown with an "add_" function,
1784 /** Creates a new type union. */
1785 FIRM_API ir_type *new_type_union(ident *name);
1787 /** Creates a new type union with debug information. */
1788 FIRM_API ir_type *new_d_type_union(ident *name, type_dbg_info* db);
1790 /* --- manipulate private fields of struct --- */
1792 /** return union identifier */
1793 FIRM_API ident *get_union_ident(const ir_type *uni);
1795 /** return union identifier as c-string */
1796 FIRM_API const char *get_union_name(const ir_type *uni);
1798 /** Returns the number of unioned types of this union */
1799 FIRM_API int get_union_n_members(const ir_type *uni);
1801 /** Returns the entity at position pos of a union */
1802 FIRM_API ir_entity *get_union_member(const ir_type *uni, int pos);
1804 /** Returns index of member in uni, -1 if not contained. */
1805 FIRM_API int get_union_member_index(const ir_type *uni, ir_entity *member);
1807 /** Returns true if a type is a union type. */
1808 FIRM_API int is_Union_type(const ir_type *uni);
1811 * @page array_type Representation of an array type
1813 * The array type represents rectangular multi dimensional arrays.
1814 * The constants representing the bounds must be allocated to
1815 * get_const_code_irg() by setting current_ir_graph accordingly.
1817 * - n_dimensions: Number of array dimensions.
1818 * - *lower_bound: Lower bounds of dimensions. Usually all 0.
1819 * - *upper_bound: Upper bounds or dimensions.
1820 * - *element_type: The type of the array elements.
1821 * - *element_ent: An entity for the array elements to be used for
1822 * element selection with Sel.
1825 /** Create a new type array.
1827 * Sets n_dimension to dimension and all dimension entries to NULL.
1828 * Initializes order to the order of the dimensions.
1829 * The entity for array elements is built automatically.
1830 * Set dimension sizes after call to constructor with set_* routines.
1832 FIRM_API ir_type *new_type_array(int n_dims, ir_type *element_type);
1834 /** Create a new type array with debug information.
1836 * Sets n_dimension to dimension and all dimension entries to NULL.
1837 * Initializes order to the order of the dimensions.
1838 * The entity for array elements is built automatically.
1839 * Set dimension sizes after call to constructor with set_* routines.
1840 * A legal array type must have at least one dimension set.
1842 FIRM_API ir_type *new_d_type_array(int n_dims, ir_type *element_type,
1845 /* --- manipulate private fields of array type --- */
1847 /** Returns the number of array dimensions of this type. */
1848 FIRM_API int get_array_n_dimensions(const ir_type *array);
1851 * Allocates Const nodes of mode_Is for one array dimension.
1852 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1854 FIRM_API void set_array_bounds_int(ir_type *array, int dimension,
1855 int lower_bound, int upper_bound);
1857 * Sets the bounds for one array dimension.
1858 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1860 FIRM_API void set_array_bounds(ir_type *array, int dimension,
1861 ir_node *lower_bound, ir_node *upper_bound);
1862 /** Sets the lower bound for one array dimension, i.e. [lower,upper[ */
1863 FIRM_API void set_array_lower_bound(ir_type *array, int dimension,
1864 ir_node *lower_bound);
1866 /** Allocates Const nodes of mode_Is for the lower bound of an array
1867 dimension, i.e. [lower,upper[ */
1868 FIRM_API void set_array_lower_bound_int(ir_type *array, int dimension,
1871 /** Sets the upper bound for one array dimension, i.e. [lower,upper[ */
1872 FIRM_API void set_array_upper_bound(ir_type *array, int dimension,
1873 ir_node *upper_bound);
1875 /** Allocates Const nodes of mode_Is for the upper bound of an array
1876 dimension, i.e. [lower,upper[. */
1877 FIRM_API void set_array_upper_bound_int(ir_type *array, int dimension,
1880 /** Returns true if lower bound != Unknown. */
1881 FIRM_API int has_array_lower_bound(const ir_type *array, int dimension);
1882 /** Returns the lower bound of an array. */
1883 FIRM_API ir_node *get_array_lower_bound(const ir_type *array, int dimension);
1884 /** Works only if bound is Const node with tarval that can be converted to long. */
1885 FIRM_API long get_array_lower_bound_int(const ir_type *array, int dimension);
1886 /** returns true if lower bound != Unknown */
1887 FIRM_API int has_array_upper_bound(const ir_type *array, int dimension);
1888 /** Returns the upper bound of an array. */
1889 FIRM_API ir_node *get_array_upper_bound(const ir_type *array, int dimension);
1890 /** Works only if bound is Const node with tarval that can be converted to long. */
1891 FIRM_API long get_array_upper_bound_int(const ir_type *array, int dimension);
1893 /** Sets an array dimension to a specific order. */
1894 FIRM_API void set_array_order(ir_type *array, int dimension, int order);
1896 /** Returns the order of an array dimension. */
1897 FIRM_API int get_array_order(const ir_type *array, int dimension);
1899 /** Find the array dimension that is placed at order order. */
1900 FIRM_API int find_array_dimension(const ir_type *array, int order);
1902 /** Sets the array element type. */
1903 FIRM_API void set_array_element_type(ir_type *array, ir_type* tp);
1905 /** Gets the array element type. */
1906 FIRM_API ir_type *get_array_element_type(const ir_type *array);
1908 /** Sets the array element entity. */
1909 FIRM_API void set_array_element_entity(ir_type *array, ir_entity *ent);
1911 /** Get the array element entity. */
1912 FIRM_API ir_entity *get_array_element_entity(const ir_type *array);
1914 /** Returns true if a type is an array type. */
1915 FIRM_API int is_Array_type(const ir_type *array);
1918 * @page enumeration_type Representation of an enumeration type
1920 * Enumeration types need not necessarily be represented explicitly
1921 * by Firm types, as the frontend can lower them to integer constants as
1922 * well. For debugging purposes or similar tasks this information is useful.
1923 * The type state layout_fixed is set, if all enumeration constant have
1924 * there tarvals assigned. Until then
1926 * - *const: The target values representing the constants used to
1927 * represent individual enumerations.
1930 /** Create a new type enumeration -- set the enumerators independently. */
1931 FIRM_API ir_type *new_type_enumeration(ident *name, int n_enums);
1933 /** Create a new type enumeration with debug information -- set the enumerators independently. */
1934 FIRM_API ir_type *new_d_type_enumeration(ident *name, int n_enums,
1937 /* --- manipulate fields of enumeration type. --- */
1939 /** return enumeration identifier */
1940 FIRM_API ident *get_enumeration_ident(const ir_type *enumeration);
1942 /** return enumeration identifier as c-string */
1943 FIRM_API const char *get_enumeration_name(const ir_type *enumeration);
1945 /** Set an enumeration constant to a enumeration type at a given position. */
1946 FIRM_API void set_enumeration_const(ir_type *enumeration, int pos,
1947 ident *nameid, ir_tarval *con);
1949 /** Returns the number of enumeration values of this enumeration */
1950 FIRM_API int get_enumeration_n_enums(const ir_type *enumeration);
1952 /** Returns the enumeration constant at a given position. */
1953 FIRM_API ir_enum_const *get_enumeration_const(const ir_type *enumeration,
1956 /** Returns the enumeration type owner of an enumeration constant. */
1957 FIRM_API ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst);
1959 /** Sets the enumeration constant value. */
1960 FIRM_API void set_enumeration_value(ir_enum_const *enum_cnst, ir_tarval *con);
1962 /** Returns the enumeration constant value. */
1963 FIRM_API ir_tarval *get_enumeration_value(const ir_enum_const *enum_cnst);
1965 /** Assign an ident to an enumeration constant. */
1966 FIRM_API void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
1968 /** Returns the assigned ident of an enumeration constant. */
1969 FIRM_API ident *get_enumeration_const_nameid(const ir_enum_const *enum_cnst);
1971 /** Returns the assigned name of an enumeration constant. */
1972 FIRM_API const char *get_enumeration_const_name(const ir_enum_const *enum_cnst);
1974 /** Returns true if a type is a enumeration type. */
1975 FIRM_API int is_Enumeration_type(const ir_type *enumeration);
1978 * @page pointer_type Representation of a pointer type
1981 * - points_to: The type of the entity this pointer points to.
1984 /** Creates a new type pointer. */
1985 FIRM_API ir_type *new_type_pointer(ir_type *points_to);
1987 /** Creates a new type pointer with debug information. */
1988 FIRM_API ir_type *new_d_type_pointer(ir_type *points_to, type_dbg_info* db);
1990 /* --- manipulate fields of type_pointer --- */
1992 /** Sets the type to which a pointer points to. */
1993 FIRM_API void set_pointer_points_to_type(ir_type *pointer, ir_type *tp);
1995 /** Returns the type to which a pointer points to. */
1996 FIRM_API ir_type *get_pointer_points_to_type(const ir_type *pointer);
1998 /** Returns true if a type is a pointer type. */
1999 FIRM_API int is_Pointer_type(const ir_type *pointer);
2001 /** Returns the first pointer type that has as points_to tp.
2002 * Not efficient: O(\#types).
2003 * If not found returns firm_unknown_type. */
2004 FIRM_API ir_type *find_pointer_type_to_type(ir_type *tp);
2007 * @page primitive_type Representation of a primitive type
2009 * Primitive types are types that represent atomic data values that
2010 * map directly to modes. They don't have private attributes. The
2011 * important information they carry is held in the common mode field.
2013 /** Creates a new primitive type. */
2014 FIRM_API ir_type *new_type_primitive(ir_mode *mode);
2016 /** Creates a new primitive type with debug information. */
2017 FIRM_API ir_type *new_d_type_primitive(ir_mode *mode, type_dbg_info* db);
2019 /** Returns true if a type is a primitive type. */
2020 FIRM_API int is_Primitive_type(const ir_type *primitive);
2022 /** Return the base type of a primitive (bitfield) type or NULL if none. */
2023 FIRM_API ir_type *get_primitive_base_type(const ir_type *tp);
2025 /** Sets the base type of a primitive (bitfield) type. */
2026 FIRM_API void set_primitive_base_type(ir_type *tp, ir_type *base_tp);
2029 * @page none_type The None type
2031 * This type is an auxiliary type dedicated to support type analyses.
2033 * The none type represents that there is no type. The type can be used to
2034 * initialize fields of type* that actually can not contain a type or that
2035 * are initialized for an analysis. There exists exactly one type none.
2036 * This type is not on the type list in ir_prog. It is
2037 * allocated when initializing the type module.
2039 * The following values are set:
2041 * - name: "type_none"
2042 * - state: layout_fixed
2045 /** A variable that contains the only none type. */
2046 FIRM_API ir_type *firm_none_type;
2048 /** A variable that contains the only code type. */
2049 FIRM_API ir_type *firm_code_type;
2051 /** Returns the none type. */
2052 FIRM_API ir_type *get_none_type(void);
2053 /** Returns the code type. */
2054 FIRM_API ir_type *get_code_type(void);
2057 * @page unknown_type The Unknown type
2059 * This type is an auxiliary type dedicated to support type analyses.
2061 * The unknown type represents that there could be a type, but it is not
2062 * known. This type can be used to initialize fields before an analysis (not known
2063 * yet) or to represent the top of a lattice (could not be determined). There exists
2064 * exactly one type unknown. This type is not on the type list in ir_prog. It is
2065 * allocated when initializing the type module.
2067 * The following values are set:
2069 * - name: "type_unknown"
2070 * - state: layout_fixed
2073 /** A variable that contains the only unknown type. */
2074 FIRM_API ir_type *firm_unknown_type;
2076 /** Returns the unknown type. */
2077 FIRM_API ir_type *get_unknown_type(void);
2081 * Checks whether a type is atomic.
2082 * @param tp any type
2083 * @return true if type is primitive, pointer or enumeration
2085 FIRM_API int is_atomic_type(const ir_type *tp);
2087 /* --- Support for compound types --- */
2090 * Gets the identifier of a compound type
2092 FIRM_API ident *get_compound_ident(const ir_type *tp);
2094 /** return compound identifier as c-string */
2095 FIRM_API const char *get_compound_name(const ir_type *tp);
2098 * Gets the number of elements in a Firm compound type.
2100 * This is just a comfortability function, because structs and
2101 * classes can often be treated be the same code, but they have
2102 * different access functions to their members.
2104 * @param tp The type (must be struct, union or class).
2106 * @return Number of members in the compound type.
2108 FIRM_API int get_compound_n_members(const ir_type *tp);
2111 * Gets the member of a Firm compound type at position pos.
2113 * @param tp The type (must be struct, union or class).
2114 * @param pos The number of the member.
2116 * @return The member entity at position pos.
2118 FIRM_API ir_entity *get_compound_member(const ir_type *tp, int pos);
2120 /** Returns index of member in tp, -1 if not contained. */
2121 FIRM_API int get_compound_member_index(const ir_type *tp, ir_entity *member);
2124 * layout members of a struct/union or class type in a default way.
2126 FIRM_API void default_layout_compound_type(ir_type *tp);
2129 * Checks whether a type is a compound type.
2131 * @param tp - any type
2133 * @return true if the type is class, structure, union or array type.
2135 FIRM_API int is_compound_type(const ir_type *tp);
2138 * Checks wether a type is a code type.
2140 FIRM_API int is_code_type(const ir_type *tp);
2143 * Checks, whether a type is a frame type.
2145 FIRM_API int is_frame_type(const ir_type *tp);
2148 * Checks, whether a type is a value parameter type.
2150 FIRM_API int is_value_param_type(const ir_type *tp);
2153 * Checks, whether a type is a lowered type.
2155 FIRM_API int is_lowered_type(const ir_type *tp);
2158 * Makes a new value type. Value types are struct types,
2159 * so all struct access functions work.
2160 * Value types are not in the global list of types.
2162 FIRM_API ir_type *new_type_value(void);
2165 * Makes a new frame type. Frame types are class types,
2166 * so all class access functions work.
2167 * Frame types are not in the global list of types.
2169 FIRM_API ir_type *new_type_frame(void);
2172 * Makes a clone of a frame type.
2173 * Sets entity links from old frame entities to new onces and
2176 FIRM_API ir_type *clone_frame_type(ir_type *type);
2179 * Sets a lowered type for a type. This sets both associations
2180 * and marks lowered_type as a "lowered" one.
2182 FIRM_API void set_lowered_type(ir_type *tp, ir_type *lowered_type);
2185 * Gets the lowered/unlowered type of a type or NULL if this type
2186 * has no lowered/unlowered one.
2188 FIRM_API ir_type *get_associated_type(const ir_type *tp);
2191 * Allocate an area of size bytes aligned at alignment
2192 * at the start or the end of a frame type.
2193 * The frame type must already have a fixed layout.
2195 * @param frame_type a frame type
2196 * @param size the size of the entity
2197 * @param alignment the alignment of the entity
2198 * @param at_start if true, put the area at the frame type's start, else at end
2200 * @return the entity representing the area
2202 FIRM_API ir_entity *frame_alloc_area(ir_type *frame_type, int size,
2203 unsigned alignment, int at_start);
2205 /*-----------------------------------------------------------------*/
2207 /*-----------------------------------------------------------------*/
2210 * Outputs a unique number for this type if libfirm is compiled for
2211 * debugging, (configure with --enable-debug) else returns the address
2212 * of the type cast to long.
2214 FIRM_API long get_type_nr(const ir_type *tp);
2216 /* ------------------------------------------------------------------------ */
2218 /** Type for a function that compares two types.
2220 * @param tp1 The first type to compare.
2221 * @param tp2 The second type to compare.
2223 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
2225 /* ------------------------------------------------------------------------ */
2227 /** A data type to treat types and entities as the same. */
2229 ir_type *typ; /**< points to a type */
2230 ir_entity *ent; /**< points to an entity */
2233 /** Type of argument functions for type walkers.
2235 * @param tore points to the visited type or entity
2236 * @param env free environment pointer
2238 typedef void type_walk_func(type_or_ent tore, void *env);
2240 /** The class walk function
2242 * @param clss points to the visited class
2243 * @param env free environment pointer
2245 typedef void class_walk_func(ir_type *clss, void *env);
2247 /** Touches every type and entity in unspecified order. If new
2248 * types/entities are created during the traversal these will
2250 * Does not touch frame types or types for value params ... */
2251 FIRM_API void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
2253 /** Touches every type, entity, frame type, and value param type in
2254 * unspecified order (also all segment types). */
2255 FIRM_API void type_walk_prog(type_walk_func *pre, type_walk_func *post,
2258 /** Walks over all type information reachable from an ir graph.
2260 * Walks over all type information reachable from irg, i.e., starts a
2261 * type walk at the irgs entity, the irgs frame type and all types and
2262 * entities that are attributes to firm nodes. */
2263 FIRM_API void type_walk_irg(ir_graph *irg, type_walk_func *pre,
2264 type_walk_func *post, void *env);
2267 * Touches every class in specified order:
2268 * - first the super class
2269 * - second the class itself
2270 * - third the sub classes. If new classes are created
2271 * during the traversal these will be visited, too.
2273 * @deprecated will be removed?
2275 FIRM_API void type_walk_super2sub(type_walk_func *pre, type_walk_func *post,
2278 /** Walker for class types in inheritance order.
2280 * Touches every class in specified order:
2281 * - first the super class
2282 * - second the class itself
2283 * If new classes are created during the traversal these
2284 * will be visited, too.
2285 * Starts the walk at arbitrary classes.
2286 * Executes pre when first visiting a class. Executes post after
2287 * visiting all superclasses.
2289 * The arguments pre, post, env may be NULL. */
2290 FIRM_API void type_walk_super(type_walk_func *pre, type_walk_func *post,
2293 /** Same as type_walk_super2sub, but visits only class types.
2294 Executes pre for a class if all superclasses have been visited.
2295 Then iterates to subclasses. Executes post after return from
2297 Does not visit global type, frame types.
2299 FIRM_API void class_walk_super2sub(class_walk_func *pre, class_walk_func *post,
2303 * the entity walk function. A function type for entity walkers.
2305 * @param ent points to the visited entity
2306 * @param env free environment pointer
2308 typedef void entity_walk_func(ir_entity *ent, void *env);
2311 * Walks over all entities in the type.
2313 * @param tp the type
2314 * @param doit the entity walker function
2315 * @param env environment, will be passed to the walker function
2317 FIRM_API void walk_types_entities(ir_type *tp, entity_walk_func *doit,
2321 * If we have the closed world assumption, we can calculate the
2322 * finalization of classes and entities by inspecting the class hierarchy.
2323 * After this is done, all classes and entities that are not overridden
2324 * anymore have the final property set.
2326 FIRM_API void types_calc_finalization(void);
2329 FIRM_API ir_visibility get_type_visibility(const ir_type *tp);
2331 FIRM_API void set_type_visibility(ir_type *tp, ir_visibility v);
2335 allocation_automatic,
2336 allocation_parameter,
2341 FIRM_API ir_allocation get_entity_allocation(const ir_entity *ent);
2343 FIRM_API void set_entity_allocation(ir_entity *ent, ir_allocation al);
2347 peculiarity_existent,
2348 peculiarity_description,
2349 peculiarity_inherited
2352 FIRM_API ir_peculiarity get_entity_peculiarity(const ir_entity *ent);
2354 FIRM_API void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec);
2357 FIRM_API int is_entity_final(const ir_entity *ent);
2359 FIRM_API void set_entity_final(ir_entity *ent, int final);
2362 FIRM_API ir_peculiarity get_class_peculiarity(const ir_type *clss);
2364 FIRM_API void set_class_peculiarity(ir_type *clss, ir_peculiarity pec);