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
27 #include "firm_types.h"
31 * @page entity Entity representation
33 * An entity is the representation of program known objects in Firm.
34 * The primary concept of entities is to represent members of complex
35 * types, i.e., fields and methods of classes. As not all programming
36 * language model all variables and methods as members of some class,
37 * the concept of entities is extended to cover also local and global
38 * variables, and arbitrary procedures.
40 * An entity always specifies the type of the object it represents and
41 * the type of the object it is a part of, the owner of the entity.
42 * Originally this is the type of the class of which the entity is a
44 * The owner of local variables is the procedure they are defined in.
45 * The owner of global variables and procedures visible in the whole
46 * program is a universally defined class type "GlobalType". The owner
47 * of procedures defined in the scope of an other procedure is the
48 * enclosing procedure.
50 * The type ir_entity is an abstract data type to represent program entities.
51 * If contains the following attributes:
53 * - owner: A compound type this entity is a part of.
54 * - type: The type of this entity.
55 * - name: The string that represents this entity in the source program
56 * - linkage: A flag indicating how the linker treats a symbol
57 * - offset: The offset of the entity within the compound object in bytes. Only set
58 * if the owner in the state "layout_fixed".
59 * - offset_bits_remainder: The offset bit remainder of a bitfield entity (in a compound)
60 * in bits. Only set if the owner in the state "layout_fixed".
61 * - overwrites: A list of entities overwritten by this entity. This list is only
62 * existent if the owner of this entity is a class. The members in
63 * this list must be entities of super classes.
64 * - overwrittenby: A list of entities that overwrite this entity. This list is only
65 * existent if the owner of this entity is a class. The members in
66 * this list must be entities of sub classes.
67 * - link: A void* to associate some additional information with the entity.
68 * - irg: If the entity is a method this is the ir graph that represents the
70 * - visited: visited flag. Master flag is type_visited.
72 * These fields can only be accessed via access functions.
74 * @see ir_type, ir_entity
78 * Visibility classed for entities.
82 * The entity is visible outside the compilation unit, but it is defined
85 ir_visibility_default,
87 * The entity is local to the compilation unit.
88 * A local entity is not visible in other compilation units.
89 * Note that the entity might still be accessed indirectly from other units
94 * The entity is defined outside the compilation unit but potentially used
97 ir_visibility_external,
99 * This has the same semantic as visibility_local. Additionally the symbol is
100 * completely hidden from the linker (it only appears in the assembly).
101 * While visibility_local is probably still visible to debuggers,
102 * visibility_private symbols aren't and probably won't appear in the object
105 ir_visibility_private
109 * linkage specifies how the linker treats symbols
112 IR_LINKAGE_DEFAULT = 0,
114 * A symbol whose definition won't change in a program.
115 * Optimisation might replace loads from this entity with constants.
116 * Also most linkers put such data in a constant segment which is shared
117 * between multiple running instances of the same application.
119 IR_LINKAGE_CONSTANT = 1 << 0,
121 * The entity is a weak symbol.
122 * A weak symbol is overridden by a non-weak symbol if one exists.
123 * Most linkers only support the IR_LINKAGE_WEAK in combination with
126 IR_LINKAGE_WEAK = 1 << 1,
128 * The entity may be removed when it isn't referenced anywhere in the
129 * compilation unit even if it is exported (non-local).
130 * Typically used for C++ instantiated template code (,,COMDAT'' section).
132 IR_LINKAGE_GARBAGE_COLLECT = 1 << 2,
134 * The linker will try to merge entities with same name from different
135 * compilation units. This is the usual behaviour for global variables
136 * without explicit initialisation in C (``COMMON'' symbols). It's also
137 * typically used in C++ for instantiated template code (,,COMDAT'' section)
139 IR_LINKAGE_MERGE = 1 << 3,
141 * Some entity uses are potentially hidden from the compiler.
142 * (For example because they happen in an asm("") statement. This flag
143 * should be set for __attribute__((used)) in C code).
144 * Setting this flag prohibits that the compiler making assumptions about
145 * read/write behaviour to global variables or changing calling conventions
146 * from cdecl to fastcall.
148 IR_LINKAGE_HIDDEN_USER = 1 << 4
152 * Return the visibility class of an entity
154 ir_visibility get_entity_visibility(const ir_entity *entity);
157 * Set visibility class of an entity
159 void set_entity_visibility(ir_entity *entity, ir_visibility visibility);
162 * Return 1 if the entity is visible outside the current compilation unit
163 * or to unknown callers (like asm statements).
164 * (The entity might still be accessible indirectly through pointers)
165 * This is a convenience function and does the same as
166 * get_entity_visibility(entity) != ir_visibility_local ||
167 * (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER)
169 int entity_is_externally_visible(const ir_entity *entity);
172 * Return 1 if the entity has a definition (initializer) in the current
175 int entity_has_definition(const ir_entity *entity);
178 * Creates a new entity.
180 * Automatically inserts the entity as a member of owner.
181 * Entity is automatic_allocated and uninitialized except if the type
182 * is type_method, then it is static_allocated and constant. The constant
183 * value is a pointer to the method.
184 * Visibility is local, offset -1, and it is not volatile.
186 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp);
189 * Creates a new entity.
191 * Automatically inserts the entity as a member of owner.
192 * The entity is automatic allocated and uninitialized except if the type
193 * is type_method, then it is static allocated and constant. The constant
194 * value is a pointer to the method.
195 * Visibility is local, offset -1, and it is not volatile.
197 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp, dbg_info *db);
200 * Copies the entity if the new_owner is different from the
201 * owner of the old entity, else returns the old entity.
203 * Automatically inserts the new entity as a member of owner.
204 * Resets the overwrites/overwritten_by fields.
205 * Keeps the old atomic value.
207 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner);
210 * Copies the entity if the new_name is different from the
211 * name of the old entity, else returns the old entity.
213 * Automatically inserts the new entity as a member of owner.
214 * The mangled name ld_name is set to NULL.
215 * Overwrites relation is copied from old.
217 ir_entity *copy_entity_name(ir_entity *old, ident *new_name);
222 * The owner will still contain the pointer to this
223 * entity, as well as all other references!
225 void free_entity(ir_entity *ent);
227 /** Returns the name of an entity. */
228 const char *get_entity_name(const ir_entity *ent);
230 /** Returns the ident of an entity. */
231 ident *get_entity_ident(const ir_entity *ent);
233 /** Sets the ident of the entity. */
234 void set_entity_ident(ir_entity *ent, ident *id);
236 /** Returns the mangled name of the entity.
238 * If the mangled name is set it returns the existing name.
239 * Else it generates a name with mangle_entity()
240 * and remembers this new name internally.
242 ident *get_entity_ld_ident(const ir_entity *ent);
244 /** Sets the mangled name of the entity. */
245 void set_entity_ld_ident(ir_entity *ent, ident *ld_ident);
247 /** Returns the mangled name of the entity as a string. */
248 const char *get_entity_ld_name(const ir_entity *ent);
250 /** Returns the owner of the entity. */
251 ir_type *get_entity_owner(const ir_entity *ent);
253 /** Sets the owner field in entity to owner. Don't forget to add
255 void set_entity_owner(ir_entity *ent, ir_type *owner);
257 /** Returns the type of an entity. */
258 ir_type *get_entity_type(const ir_entity *ent);
260 /** Sets the type of an entity. */
261 void set_entity_type(ir_entity *ent, ir_type *tp);
263 /** Returns the linkage of an entity. */
264 ir_linkage get_entity_linkage(const ir_entity *entity);
266 /** Sets the linkage of an entity. */
267 void set_entity_linkage(ir_entity *entity, ir_linkage linkage);
268 void add_entity_linkage(ir_entity *entity, ir_linkage linkage);
269 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage);
271 /** Returns 1 if the value of a global symbol never changes in a program */
272 int is_entity_constant(const ir_entity *ent);
275 * This enumeration flags the volatility of entities and Loads/Stores.
279 volatility_non_volatile, /**< The entity is not volatile. Default. */
280 volatility_is_volatile /**< The entity is volatile. */
284 * Returns the volatility of an entity.
287 ir_volatility get_entity_volatility(const ir_entity *ent);
290 * Sets the volatility of an entity.
293 void set_entity_volatility(ir_entity *ent, ir_volatility vol);
295 /** Return the name of the volatility. */
296 const char *get_volatility_name(ir_volatility var);
298 /** Returns alignment of entity in bytes */
299 unsigned get_entity_alignment(const ir_entity *entity);
301 /** Allows you to override the type alignment for an entity.
302 * @param entity the entity
303 * @param alignment alignment in bytes
305 void set_entity_alignment(ir_entity *entity, unsigned alignment);
309 * This enumeration flags the align of Loads/Stores.
313 align_non_aligned, /**< The entity is not aligned. */
314 align_is_aligned /**< The entity is aligned. Default */
318 * Returns indication wether entity is aligned in memory.
321 ir_align get_entity_aligned(const ir_entity *ent);
324 * Sets indication wether entity is aligned in memory
327 void set_entity_aligned(ir_entity *ent, ir_align a);
329 /** Return the name of the alignment. */
330 const char *get_align_name(ir_align a);
332 /** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */
333 int get_entity_offset(const ir_entity *ent);
335 /** Sets the offset of an entity (in a compound) in bytes. */
336 void set_entity_offset(ir_entity *ent, int offset);
338 /** Returns the offset bit remainder of a bitfield entity (in a compound) in bits. Only set if layout = fixed. */
339 unsigned char get_entity_offset_bits_remainder(const ir_entity *ent);
341 /** Sets the offset bit remainder of a bitfield entity (in a compound) in bits. */
342 void set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset);
344 /** Returns the stored intermediate information. */
345 void *get_entity_link(const ir_entity *ent);
347 /** Stores new intermediate information. */
348 void set_entity_link(ir_entity *ent, void *l);
350 /* -- Fields of method entities -- */
351 /** The entity knows the corresponding irg if the entity is a method.
352 This allows to get from a Call to the called irg. */
353 ir_graph *get_entity_irg(const ir_entity *ent);
354 void set_entity_irg(ir_entity *ent, ir_graph *irg);
356 /** Gets the entity vtable number. */
357 unsigned get_entity_vtable_number(const ir_entity *ent);
359 /** Sets the entity vtable number. */
360 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number);
362 /** Set label number of an entity with code type */
363 void set_entity_label(ir_entity *ent, ir_label_t label);
364 /** Return label number of an entity with code type */
365 ir_label_t get_entity_label(const ir_entity *ent);
367 /** Checks if an entity is compiler generated. */
368 int is_entity_compiler_generated(const ir_entity *ent);
370 /** Sets/resets the compiler generated flag. */
371 void set_entity_compiler_generated(ir_entity *ent, int flag);
374 * Bitfield type indicating the way an entity is used.
377 ir_usage_none = 0, /**< This entity is unused. */
378 ir_usage_address_taken = 1 << 0, /**< The address of this entity was taken. */
379 ir_usage_write = 1 << 1, /**< The entity was written to. */
380 ir_usage_read = 1 << 2, /**< The entity was read. */
381 ir_usage_reinterpret_cast = 1 << 3, /**< The entity was read but with a wrong mode
382 (an implicit reinterpret cast) */
383 /** Unknown access */
385 = ir_usage_address_taken | ir_usage_write | ir_usage_read
386 | ir_usage_reinterpret_cast
389 /** Return the entity usage */
390 ir_entity_usage get_entity_usage(const ir_entity *ent);
392 /** Sets/resets the state of the address taken flag of an entity. */
393 void set_entity_usage(ir_entity *ent, ir_entity_usage flag);
396 * Returns the debug information of an entity.
398 * @param ent The entity.
400 dbg_info *get_entity_dbg_info(const ir_entity *ent);
403 * Sets the debug information of an entity.
405 * @param ent The entity.
406 * @param db The debug info.
408 void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
410 /* -- Representation of constant values of entities -- */
412 * Returns true if the the node is representable as code on
415 * @deprecated This function is not used by libFirm and stays here
416 * only as a helper for the old Jack frontend.
418 int is_irn_const_expression(ir_node *n);
421 * Copies a Firm subgraph that complies to the restrictions for
422 * constant expressions to current_block in current_ir_graph.
424 * @param dbg debug info for all newly created nodes
427 * Set current_ir_graph to get_const_code_irg() to generate a constant
430 ir_node *copy_const_value(dbg_info *dbg, ir_node *n);
432 /* Set has no effect for existent entities of type method. */
433 ir_node *get_atomic_ent_value(ir_entity *ent);
434 void set_atomic_ent_value(ir_entity *ent, ir_node *val);
436 /** the kind (type) of an initializer */
437 typedef enum ir_initializer_kind_t {
438 /** initializer containing an ir_node from the const-code irg */
439 IR_INITIALIZER_CONST,
440 /** initializer containing a tarval */
441 IR_INITIALIZER_TARVAL,
442 /** initializes type with default values (usually 0) */
444 /** list of initializers used to initializer a compound or array type */
445 IR_INITIALIZER_COMPOUND
446 } ir_initializer_kind_t;
448 /** returns kind of an initializer */
449 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer);
451 /** Return the name of the initializer kind. */
452 const char *get_initializer_kind_name(ir_initializer_kind_t ini);
455 * returns the null initializer (there's only one instance of it in a program )
457 ir_initializer_t *get_initializer_null(void);
460 * creates an initializer containing a reference to a node on the const-code
463 ir_initializer_t *create_initializer_const(ir_node *value);
465 /** creates an initializer containing a single tarval value */
466 ir_initializer_t *create_initializer_tarval(tarval *tv);
468 /** return value contained in a const initializer */
469 ir_node *get_initializer_const_value(const ir_initializer_t *initializer);
471 /** return value contained in a tarval initializer */
472 tarval *get_initializer_tarval_value(const ir_initializer_t *initialzier);
474 /** creates a compound initializer which holds @p n_entries entries */
475 ir_initializer_t *create_initializer_compound(unsigned n_entries);
477 /** returns the number of entries in a compound initializer */
478 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer);
480 /** sets entry with index @p index to the initializer @p value */
481 void set_initializer_compound_value(ir_initializer_t *initializer,
482 unsigned index, ir_initializer_t *value);
484 /** returns the value with index @p index of a compound initializer */
485 ir_initializer_t *get_initializer_compound_value(
486 const ir_initializer_t *initializer, unsigned index);
488 /** Sets the new style initializers of an entity. */
489 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer);
491 /** Returns true, if an entity has new style initializers. */
492 int has_entity_initializer(const ir_entity *entity);
494 /** Return the new style initializers of an entity. */
495 ir_initializer_t *get_entity_initializer(const ir_entity *entity);
497 /* --- Fields of entities with a class type as owner --- */
498 /* Overwrites is a field that specifies that an access to the overwritten
499 entity in the supertype must use this entity. It's a list as with
500 multiple inheritance several entities can be overwritten. This field
501 is mostly useful for method entities.
502 If a Sel node selects an entity that is overwritten by other entities it
503 must return a pointer to the entity of the dynamic type of the pointer
504 that is passed to it. Lowering of the Sel node must assure this.
505 Overwrittenby is the inverse of overwrites. Both add routines add
506 both relations, they only differ in the order of arguments. */
507 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
508 int get_entity_n_overwrites(const ir_entity *ent);
509 int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten);
510 ir_entity *get_entity_overwrites(const ir_entity *ent, int pos);
511 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten);
512 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
514 void add_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
515 int get_entity_n_overwrittenby(const ir_entity *ent);
516 int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites);
517 ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos);
518 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites);
519 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
522 * Checks whether a pointer points to an entity.
524 * @param thing an arbitrary pointer
527 * true if the thing is an entity, else false
529 int is_entity(const void *thing);
531 /** Returns true if the type of the entity is a primitive, pointer
532 * enumeration or method type.
534 * @note This is a different classification than from is_primitive_type().
536 int is_atomic_entity(const ir_entity *ent);
537 /** Returns true if the type of the entity is a class, structure,
538 array or union type. */
539 int is_compound_entity(const ir_entity *ent);
540 /** Returns true if the type of the entity is a Method type. */
541 int is_method_entity(const ir_entity *ent);
543 /** Outputs a unique number for this entity if libfirm is compiled for
544 * debugging, (configure with --enable-debug) else returns the address
545 * of the type cast to long.
547 long get_entity_nr(const ir_entity *ent);
549 /** Returns the entities visited count. */
550 ir_visited_t get_entity_visited(const ir_entity *ent);
552 /** Sets the entities visited count. */
553 void set_entity_visited(ir_entity *ent, ir_visited_t num);
555 /** Sets visited field in entity to entity_visited. */
556 void mark_entity_visited(ir_entity *ent);
558 /** Returns true if this entity was visited. */
559 int entity_visited(const ir_entity *ent);
561 /** Returns true if this entity was not visited. */
562 int entity_not_visited(const ir_entity *ent);
565 * Returns the mask of the additional entity properties.
566 * The properties are automatically inherited from the irg if available
567 * or from the method type if they were not set using
568 * set_entity_additional_properties() or
569 * set_entity_additional_property().
571 unsigned get_entity_additional_properties(const ir_entity *ent);
573 /** Sets the mask of the additional graph properties. */
574 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask);
576 /** Sets one additional graph property. */
577 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag);
579 /** Returns the class type that this type info entity represents or NULL
580 if ent is no type info entity. */
581 ir_type *get_entity_repr_class(const ir_entity *ent);
584 * @page unknown_entity The Unknown entity
586 * This entity is an auxiliary entity dedicated to support analyses.
588 * The unknown entity represents that there could be an entity, but it is not
589 * known. This entity can be used to initialize fields before an analysis (not known
590 * yet) or to represent the top of a lattice (could not be determined). There exists
591 * exactly one entity unknown. This entity has as owner and as type the unknown type. It is
592 * allocated when initializing the entity module.
594 * The entity can take the role of any entity, also methods. It returns default
595 * values in these cases.
597 * The following values are set:
599 * - name = "unknown_entity"
600 * - ld_name = "unknown_entity"
601 * - owner = unknown_type
602 * - type = unknown_type
604 * - value = SymConst(unknown_entity)
607 * - volatility = volatility_non_volatile
608 * - stickyness = stickyness_unsticky
610 * - overwrites = NULL
611 * - overwrittenby = NULL
616 /** A variable that contains the only unknown entity. */
617 extern ir_entity *unknown_entity;
619 /** Returns the @link unknown_entity unknown entity @endlink. */
620 ir_entity *get_unknown_entity(void);
622 /** Encodes how a pointer parameter is accessed. */
623 typedef enum acc_bits {
624 ptr_access_none = 0, /**< no access */
625 ptr_access_read = 1, /**< read access */
626 ptr_access_write = 2, /**< write access */
627 ptr_access_rw = ptr_access_read|ptr_access_write, /**< read AND write access */
628 ptr_access_store = 4, /**< the pointer is stored */
629 ptr_access_all = ptr_access_rw|ptr_access_store /**< all possible access */
632 #define IS_READ(a) ((a) & ptr_access_read)
633 #define IS_WRITTEN(a) ((a) & ptr_access_write)
634 #define IS_STORED(a) ((a) & ptr_access_store)
637 * @page tyop type operations
638 * This module specifies the kinds of types available in firm.
640 * They are called type opcodes. These include classes, structs, methods, unions,
641 * arrays, enumerations, pointers and primitive types.
642 * Special types with own opcodes are the id type, a type representing an unknown
643 * type and a type used to specify that something has no type.
647 * An enum for the type kinds.
648 * For each type kind exists a typecode to identify it.
651 tpo_uninitialized = 0, /* not a type opcode */
652 tpo_class, /**< A class type. */
653 tpo_struct, /**< A struct type. */
654 tpo_method, /**< A method type. */
655 tpo_union, /**< An union type. */
656 tpo_array, /**< An array type. */
657 tpo_enumeration, /**< An enumeration type. */
658 tpo_pointer, /**< A pointer type. */
659 tpo_primitive, /**< A primitive type. */
660 tpo_code, /**< a piece of code (a basic block) */
661 tpo_none, /**< Special type for the None type. */
662 tpo_unknown, /**< Special code for the Unknown type. */
663 tpo_last = tpo_unknown /* not a type opcode */
667 * A structure containing information about a kind of type.
668 * A structure containing information about a kind of type. So far
669 * this is only the kind name, an enum for case-switching and some
672 * @see get_tpop_name(), get_tpop_code()
674 typedef struct tp_op tp_op;
678 * Returns the string for the type opcode.
680 * @param op The type opcode to get the string from.
681 * @return a string. (@todo Null terminated?)
683 const char *get_tpop_name(const tp_op *op);
686 * Returns an enum for the type opcode.
688 * @param op The type opcode to get the enum from.
691 tp_opcode get_tpop_code(const tp_op *op);
694 * This type opcode marks that the corresponding type is a class type.
696 * Consequently the type refers to supertypes, subtypes and entities.
697 * Entities can be any fields, but also methods.
698 * @@@ value class or not???
699 * This struct is dynamically allocated but constant for the lifetime
702 extern const tp_op *type_class;
703 const tp_op *get_tpop_class(void);
706 * This type opcode marks that the corresponding type is a compound type
709 * Consequently the type refers to a list of entities
710 * which may not be methods (but pointers to methods).
711 * This struct is dynamically allocated but constant for the lifetime
714 extern const tp_op *type_struct;
715 const tp_op *get_tpop_struct(void);
718 * This type opcode marks that the corresponding type is a method type.
720 * Consequently it refers to a list of arguments and results.
721 * This struct is dynamically allocated but constant for the lifetime
724 extern const tp_op *type_method;
725 const tp_op *get_tpop_method(void);
728 * This type opcode marks that the corresponding type is a union type.
730 * Consequently it refers to a list of unioned types.
731 * This struct is dynamically allocated but constant for the lifetime
734 extern const tp_op *type_union;
735 const tp_op *get_tpop_union(void);
738 * This type opcode marks that the corresponding type is an array type.
740 * Consequently it contains a list of dimensions (lower and upper bounds)
741 * and an element type.
742 * This struct is dynamically allocated but constant for the lifetime
745 extern const tp_op *type_array;
746 const tp_op *get_tpop_array(void);
749 * This type opcode marks that the corresponding type is an enumeration type.
751 * Consequently it contains a list of idents for the enumeration identifiers
752 * and a list of target values that are the constants used to implement
754 * This struct is dynamically allocated but constant for the lifetime
757 extern const tp_op *type_enumeration;
758 const tp_op *get_tpop_enumeration(void);
761 * This type opcode marks that the corresponding type is a pointer type.
763 * It contains a reference to the type the pointer points to.
764 * This struct is dynamically allocated but constant for the lifetime
767 extern const tp_op *type_pointer;
768 const tp_op *get_tpop_pointer(void);
771 * This type opcode marks that the corresponding type is a primitive type.
773 * Primitive types are types that are directly mapped to target machine
775 * This struct is dynamically allocated but constant for the lifetime
778 extern const tp_op *type_primitive;
779 const tp_op *get_tpop_primitive(void);
782 * The code type is used to mark pieces of code (basic blocks)
784 extern const tp_op *tpop_code;
785 const tp_op *get_tpop_code_type(void);
788 * This type opcode is an auxiliary opcode dedicated to support type analyses.
790 * Types with this opcode represents that there is no type.
791 * The type can be used to initialize fields of the type* that actually can not
792 * contain a type or that are initialized for an analysis. There exists exactly
793 * one type with this opcode.
795 extern const tp_op *tpop_none;
796 const tp_op *get_tpop_none(void);
799 * This type opcode is an auxiliary opcode dedicated to support type analyses.
801 * Types with this opcode represents that there could be a type, but it is not
802 * known. This type can be used to initialize fields before an analysis (not known
803 * yet) or to represent the top of a lattice (could not be determined). There exists
804 * exactly one type with this opcode.
806 extern const tp_op *tpop_unknown;
807 const tp_op *get_tpop_unknown(void);
809 /* ----------------------------------------------------------------------- */
810 /* Classify pairs of types/entities in the inheritance relations. */
811 /* ----------------------------------------------------------------------- */
813 /** Returns true if low is subclass of high.
815 * Low is a subclass of high if low == high or if low is a subclass of
816 * a subclass of high. I.e, we search in all subtypes of high for low.
817 * @@@ this can be implemented more efficient if we know the set of all
818 * subclasses of high. */
819 int is_SubClass_of(ir_type *low, ir_type *high);
821 /** Subclass check for pointers to classes.
823 * Dereferences at both types the same amount of pointer types (as
824 * many as possible). If the remaining types are both class types
825 * and subclasses, returns true, else false. Can also be called with
826 * two class types. */
827 int is_SubClass_ptr_of(ir_type *low, ir_type *high);
829 /** Returns true if high is superclass of low.
831 * Low is a subclass of high if low == high or if low is a subclass of
832 * a subclass of high. I.e, we search in all subtypes of high for low.
833 * @@@ this can be implemented more efficient if we know the set of all
834 * subclasses of high. */
835 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
837 /** Superclass check for pointers to classes.
839 * Dereferences at both types the same amount of pointer types (as
840 * many as possible). If the remaining types are both class types
841 * and superclasses, returns true, else false. Can also be called with
842 * two class types. */
843 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
845 /** Returns true if high is (transitive) overwritten by low.
847 * Returns false if high == low. */
848 int is_overwritten_by(ir_entity *high, ir_entity *low);
850 /** Resolve polymorphism in the inheritance relation.
852 * Returns the dynamically referenced entity if the static entity and the
853 * dynamic type are given.
854 * Searches downwards in overwritten tree. */
855 ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity* static_ent);
857 /* ----------------------------------------------------------------------- */
858 /* Resolve implicit inheritance. */
859 /* ----------------------------------------------------------------------- */
861 /** Default name mangling for inherited entities.
863 * Returns an ident that consists of the name of type followed by an
864 * underscore and the name (not ld_name) of the entity. */
865 ident *default_mangle_inherited_name(const ir_entity *ent, const ir_type *clss);
867 /** Type of argument functions for inheritance resolver.
869 * @param ent The entity in the super type that will be overwritten
870 * by the newly generated entity, for which this name is
872 * @param clss The class type in which the new entity will be placed.
874 typedef ident *mangle_inherited_name_func(const ir_entity *ent, const ir_type *clss);
876 /** Resolve implicit inheritance.
878 * Resolves the implicit inheritance supplied by firm. Firm defines,
879 * that each entity that is not overwritten in a subclass is
880 * inherited to this subclass without change implicitly. This
881 * function generates entities that explicitly represent this
882 * inheritance. It generates for each entity overwriting entities in
883 * all subclasses of the owner of the entity, if the entity is not
884 * overwritten in that subclass.
886 * The name of the new entity is generated with the function passed.
887 * If the function is NULL, the default_mangle_inherited_name() is
890 * This function was moved here from firmlower 3/2005.
892 void resolve_inheritance(mangle_inherited_name_func *mfunc);
895 /* ----------------------------------------------------------------------- */
896 /* The transitive closure of the subclass/superclass and */
897 /* overwrites/overwrittenby relation. */
899 /* A walk over the ir (O(#types+#entities)) computes the transitive */
900 /* closure. Adding a new type/entity or changing the basic relations in */
901 /* some other way invalidates the transitive closure, i.e., it is not */
902 /* updated by the basic functions. */
904 /* The transitive edges are held in a set, not in an array as the */
905 /* underlying relation. */
907 /* Do the sets contain the node itself? I assume NOT! */
908 /* ----------------------------------------------------------------------- */
910 /** The state of the transitive closure.
912 * @todo: we could manage the state for each relation separately. Invalidating
913 * the entity relations does not mean invalidating the class relation. */
915 inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */
916 inh_transitive_closure_valid, /**< Closure computed and valid. */
917 inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */
918 inh_transitive_closure_max /**< Invalid value. */
919 } inh_transitive_closure_state;
921 void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
922 void invalidate_irp_inh_transitive_closure_state(void);
923 inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
926 /** Compute transitive closure of the subclass/superclass and
927 * overwrites/overwrittenby relation.
929 * This function walks over the ir (O(\#types+\#entities)) to compute the
930 * transitive closure. */
931 void compute_inh_transitive_closure(void);
933 /** Free memory occupied by the transitive closure information. */
934 void free_inh_transitive_closure(void);
937 /* - subtype ------------------------------------------------------------- */
939 /** Iterate over all transitive subtypes. */
940 ir_type *get_class_trans_subtype_first(const ir_type *tp);
941 ir_type *get_class_trans_subtype_next(const ir_type *tp);
942 int is_class_trans_subtype(const ir_type *tp, const ir_type *subtp);
944 /* - supertype ----------------------------------------------------------- */
946 /** Iterate over all transitive supertypes. */
947 ir_type *get_class_trans_supertype_first(const ir_type *tp);
948 ir_type *get_class_trans_supertype_next(const ir_type *tp);
950 /* - overwrittenby ------------------------------------------------------- */
952 /** Iterate over all entities that transitive overwrite this entities. */
953 ir_entity *get_entity_trans_overwrittenby_first(const ir_entity *ent);
954 ir_entity *get_entity_trans_overwrittenby_next(const ir_entity *ent);
956 /* - overwrites ---------------------------------------------------------- */
958 /** Iterate over all transitive overwritten entities. */
959 ir_entity *get_entity_trans_overwrites_first(const ir_entity *ent);
960 ir_entity *get_entity_trans_overwrites_next(const ir_entity *ent);
963 /* ----------------------------------------------------------------------- */
964 /** The state of Cast operations that cast class types or pointers to class
967 * The state expresses, how far Cast operations conform with the class
971 * class B1 extends A {}
972 * class B2 extends A {}
973 * class C extends B1 {}
974 * normalized: Cast operations conform with the inheritance relation.
975 * I.e., the type of the operand of a Cast is either a super= or a sub-
976 * type of the type casted to. Example: (A)((B2) (new C())).
977 * transitive: Cast operations conform with the transitive inheritance
978 * relation. Example: (A)(new C()).
979 * any: Cast operations do not conform with the transitive inheritance
980 * relation. Example: (B2)(new B1())
982 /* ----------------------------------------------------------------------- */
984 /** Flags for class cast state.
986 * The state in irp is always smaller or equal to the state of any
989 * We rely on the ordering of the enum. */
991 ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with
992 the class hierarchy. @@@ So far this does not happen in Firm. */
993 ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */
994 ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */
995 ir_class_casts_state_max
996 } ir_class_cast_state;
997 const char *get_class_cast_state_string(ir_class_cast_state s);
999 void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s);
1000 ir_class_cast_state get_irg_class_cast_state(const ir_graph *irg);
1001 void set_irp_class_cast_state(ir_class_cast_state s);
1002 ir_class_cast_state get_irp_class_cast_state(void);
1004 /** Verify the class cast state of an irg.
1006 * Asserts if state is to high, outputs debug warning if state is to low
1007 * and firm verbosity is set.
1009 void verify_irg_class_cast_state(ir_graph *irg);
1012 * possible trvrfy() error codes
1014 enum trvrfy_error_codes {
1015 no_error = 0, /**< no error */
1016 error_ent_not_cont, /**< overwritten entity not in superclass */
1017 error_null_mem, /**< compound contains NULL member */
1018 error_const_on_wrong_irg, /**< constant placed on wrong IRG */
1019 error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */
1020 error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */
1021 error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */
1022 error_glob_ent_allocation, /**< wrong allocation of a global entity */
1023 error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */
1024 error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */
1031 * 0 if no error encountered
1033 int check_type(ir_type *tp);
1036 * Check an entity. Currently, we check only if initialized constants
1037 * are build on the const irg graph.
1040 * 0 if no error encountered
1041 * != 0 a trvrfy_error_codes code
1043 int check_entity(ir_entity *ent);
1046 * Walks the type information and performs a set of sanity checks.
1048 * Currently, the following checks are executed:
1049 * - values of initialized entities must be allocated on the constant IRG
1050 * - class types: doesn't have NULL members
1051 * - class types: all overwrites are existent in the super type
1054 * 0 if graph is correct
1060 * If NDEBUG is defined performs nothing, else calls the tr_vrfy() function.
1065 #define TR_VRFY() tr_vrfy()
1069 * @page type representation of types
1071 * Datastructure to hold type information.
1073 * This module supplies a datastructure to represent all types
1074 * known in the compiled program. This includes types specified
1075 * in the program as well as types defined by the language. In the
1076 * view of the intermediate representation there is no difference
1077 * between these types. Finally it specifies some auxiliary types.
1079 * There exist several kinds of types, arranged by the structure of
1080 * the type. A type is described by a set of attributes. Some of
1081 * these attributes are common to all types, others depend on the
1084 * Types are different from the modes defined in irmode: Types are
1085 * on the level of the programming language, modes at the level of
1086 * the target processor.
1089 /** Frees all entities associated with a type.
1090 * Does not free the array entity.
1091 * Warning: ensure these entities are not referenced anywhere else.
1093 void free_type_entities(ir_type *tp);
1095 /** Frees the memory used by the type.
1097 * Removes the type from the type list. Does not free the entities
1098 * belonging to the type, except for the array element entity. Does
1099 * not free if tp is "none" or "unknown". Frees entities in value
1100 * param subtypes of method types!!! Make sure these are not
1101 * referenced any more. Further make sure there is no pointer type
1102 * that refers to this type. */
1103 void free_type(ir_type *tp);
1105 const tp_op *get_type_tpop(const ir_type *tp);
1106 ident *get_type_tpop_nameid(const ir_type *tp);
1107 const char *get_type_tpop_name(const ir_type *tp);
1108 tp_opcode get_type_tpop_code(const ir_type *tp);
1111 * construct a string representing the type.
1112 * This uses the info retrieved by the type_dbg_info if available.
1113 * Otherwise it tries to create an approximate textual representation of the
1115 * Keep in mind that this representation is not unique for each type,
1116 * might abstract away some details. The main intention of this is creating
1117 * human redable strings giving an idea of the type.
1119 void ir_print_type(char *buffer, size_t buffer_size, const ir_type *tp);
1121 /** The state of the type layout. */
1123 layout_undefined, /**< The layout of this type is not defined.
1124 Address computation to access fields is not
1125 possible, fields must be accessed by Sel
1126 nodes. Enumeration constants might be undefined.
1127 This is the default value except for
1128 pointer, primitive and method types. */
1129 layout_fixed /**< The layout is fixed, all component/member entities
1130 have an offset assigned. Size of the type is known.
1131 Arrays can be accessed by explicit address
1132 computation. Enumeration constants must be defined.
1133 Default for pointer, primitive and method types. */
1136 /** Returns a human readable string for the enum entry. */
1137 const char *get_type_state_name(ir_type_state s);
1139 /** Returns the type layout state of a type. */
1140 ir_type_state get_type_state(const ir_type *tp);
1142 /** Sets the type layout state of a type.
1144 * For primitives, pointer and method types the layout is always fixed.
1145 * This call is legal but has no effect.
1147 void set_type_state(ir_type *tp, ir_type_state state);
1149 /** Returns the mode of a type.
1151 * Returns NULL for all non atomic types.
1153 ir_mode *get_type_mode(const ir_type *tp);
1155 /** Sets the mode of a type.
1157 * Only has an effect on primitive, enumeration and pointer types.
1159 void set_type_mode(ir_type *tp, ir_mode* m);
1161 /** Returns the size of a type in bytes. */
1162 unsigned get_type_size_bytes(const ir_type *tp);
1164 /** Sets the size of a type in bytes.
1166 * For primitive, enumeration, pointer and method types the size
1167 * is always fixed. This call is legal but has no effect.
1169 void set_type_size_bytes(ir_type *tp, unsigned size);
1171 /** Returns the alignment of a type in bytes. */
1172 unsigned get_type_alignment_bytes(ir_type *tp);
1174 /** Returns the alignment of a type in bits.
1176 * If the alignment of a type is
1177 * not set, it is calculated here according to the following rules:
1178 * -#.) if a type has a mode, the alignment is the mode size.
1179 * -#.) compound types have the alignment of there biggest member.
1180 * -#.) array types have the alignment of there element type.
1181 * -#.) method types return 0 here.
1182 * -#.) all other types return 1 here (i.e. aligned at byte).
1184 void set_type_alignment_bytes(ir_type *tp, unsigned align);
1186 /** Returns the visited count of a type. */
1187 ir_visited_t get_type_visited(const ir_type *tp);
1188 /** Sets the visited count of a type to num. */
1189 void set_type_visited(ir_type *tp, ir_visited_t num);
1190 /** Sets visited field in type to type_visited. */
1191 void mark_type_visited(ir_type *tp);
1192 /** Returns non-zero if the type is already visited */
1193 int type_visited(const ir_type *tp);
1194 /** Returns non-zero if the type is not yet visited */
1195 int type_not_visited(const ir_type *tp);
1197 /** Returns the associated link field of a type. */
1198 void *get_type_link(const ir_type *tp);
1199 /** Sets the associated link field of a type. */
1200 void set_type_link(ir_type *tp, void *l);
1203 * Visited flag to traverse the type information.
1205 * Increase this flag by one before traversing the type information
1206 * using inc_master_type_visited().
1207 * Mark type nodes as visited by mark_type_visited(ir_type).
1208 * Check whether node was already visited by type_visited(ir_type)
1209 * and type_not_visited(ir_type).
1210 * Or use the function to walk all types.
1214 void set_master_type_visited(ir_visited_t val);
1215 ir_visited_t get_master_type_visited(void);
1216 void inc_master_type_visited(void);
1219 * Sets the debug information of a type.
1221 * @param tp The type.
1222 * @param db The debug info.
1224 void set_type_dbg_info(ir_type *tp, type_dbg_info *db);
1227 * Returns the debug information of a type.
1229 * @param tp The type.
1231 type_dbg_info *get_type_dbg_info(const ir_type *tp);
1234 * Checks whether a pointer points to a type.
1236 * @param thing an arbitrary pointer
1239 * true if the thing is a type, else false
1241 int is_type(const void *thing);
1244 * Checks whether two types are structurally equal.
1246 * @param typ1 the first type
1247 * @param typ2 the second type
1250 * true if the types are equal, else false.
1252 * Types are equal if :
1253 * - they are the same type kind
1254 * - they have the same name
1255 * - they have the same mode (if applicable)
1256 * - they have the same type_state and, ev., the same size
1257 * - they are class types and have:
1258 * - the same members (see same_entity in entity.h)
1259 * - the same supertypes -- the C-pointers are compared --> no recursive call.
1260 * - the same number of subtypes. Subtypes are not compared,
1261 * as this could cause a cyclic test.
1262 * - they are structure types and have the same members
1263 * - they are method types and have
1264 * - the same parameter types
1265 * - the same result types
1266 * - they are union types and have the same members
1267 * - they are array types and have
1268 * - the same number of dimensions
1269 * - the same dimension bounds
1270 * - the same dimension order
1271 * - the same element type
1272 * - they are enumeration types and have the same enumerator names
1273 * - they are pointer types and have the identical points_to type
1274 * (i.e., the same C-struct to represent the type.
1275 * This is to avoid endless recursions; with pointer types cyclic
1276 * type graphs are possible.)
1278 int equal_type(ir_type *typ1, ir_type *typ2);
1281 * Checks whether two types are structural comparable.
1283 * @param st pointer type
1284 * @param lt pointer type
1287 * true if type st is smaller than type lt, i.e. whenever
1288 * lt is expected a st can be used.
1290 * - they are the same type kind
1291 * - mode(st) < mode (lt) (if applicable)
1292 * - they are class types and st is (transitive) subtype of lt,
1293 * - they are structure types and
1294 * - the members of st have exactly one counterpart in lt with the same name,
1295 * - the counterpart has a bigger type.
1296 * - they are method types and have
1297 * - the same number of parameter and result types,
1298 * - the parameter types of st are smaller than those of lt,
1299 * - the result types of st are smaller than those of lt
1300 * - they are union types and have the members of st have exactly one
1301 * @return counterpart in lt and the type is smaller
1302 * - they are array types and have
1303 * - the same number of dimensions
1304 * - all bounds of lt are bound of st
1305 * - the same dimension order
1306 * - the same element type
1308 * - the element type of st is smaller than that of lt
1309 * - the element types have the same size and fixed layout.
1310 * - they are enumeration types and have the same enumerator names
1311 * - they are pointer types and have the points_to type of st is
1312 * @return smaller than the points_to type of lt.
1315 int smaller_type(ir_type *st, ir_type *lt);
1318 * @page class_type Representation of a class type
1320 * If the type opcode is set to type_class the type represents class
1321 * types. A list of fields and methods is associated with a class.
1322 * Further a class can inherit from and bequest to other classes.
1324 * The following attributes are private to this type kind:
1325 * - member: All entities belonging to this class. This are method entities
1326 * which have type_method or fields that can have any of the
1327 * following type kinds: type_class, type_struct, type_union,
1328 * type_array, type_enumeration, type_pointer, type_primitive.
1330 * The following two are dynamic lists that can be grown with an "add_" function,
1333 * - subtypes: A list of direct subclasses.
1335 * - supertypes: A list of direct superclasses.
1337 * - type_info: An entity representing the type information of this class.
1338 * This entity can be of arbitrari type, Firm did not use it yet.
1339 * It allows to express the coupling of a type with an entity
1340 * representing this type. This information is useful for lowering
1341 * of InstOf and TypeChk nodes. Default: NULL
1343 * - vtable_size: The size of this class virtual function table.
1346 * - final: A final class is always a leaf in the class hierarchy. Final
1347 * classes cannot be super classes of other ones. As this information
1348 * can only be computed in whole world compilations, we allow to
1349 * set this flag. It is used in optimizations if get_opt_closed_world()
1350 * is false. Default: false
1352 * - interface: The class represents an interface. This flag can be set to distinguish
1353 * between interfaces, abstract classes and other classes that all may
1354 * have the peculiarity peculiarity_description. Depending on this flag
1355 * the lowering might do different actions. Default: false
1357 * - abstract : The class represents an abstract class. 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
1363 /** Creates a new class type. */
1364 ir_type *new_type_class(ident *name);
1366 /** Creates a new class type with debug information. */
1367 ir_type *new_d_type_class(ident *name, type_dbg_info *db);
1369 /* --- manipulate private fields of class type --- */
1371 /** return identifier of the class type */
1372 ident *get_class_ident(const ir_type *clss);
1374 /** return identifier of the class type */
1375 const char *get_class_name(const ir_type *clss);
1377 /** Adds the entity as member of the class. */
1378 void add_class_member(ir_type *clss, ir_entity *member);
1380 /** Returns the number of members of this class. */
1381 int get_class_n_members(const ir_type *clss);
1383 /** Returns the member at position pos, 0 <= pos < n_member */
1384 ir_entity *get_class_member(const ir_type *clss, int pos);
1386 /** Returns index of mem in clss, -1 if not contained. */
1387 int get_class_member_index(const ir_type *clss, ir_entity *mem);
1389 /** Finds the member with name 'name'. If several members with the same
1390 * name returns one of them. Returns NULL if no member found. */
1391 ir_entity *get_class_member_by_name(ir_type *clss, ident *name);
1393 /** Overwrites the member at position pos, 0 <= pos < n_member with
1394 * the passed entity. */
1395 void set_class_member(ir_type *clss, ir_entity *member, int pos);
1397 /** Replaces complete member list in class type by the list passed.
1399 * Copies the list passed. This function is necessary to reduce the number of members.
1400 * members is an array of entities, num the size of this array. Sets all
1401 * owners of the members passed to clss. */
1402 void set_class_members(ir_type *clss, ir_entity *members[], int arity);
1404 /** Finds member in the list of members and removes it.
1406 * Shrinks the member list, so iterate from the end!!!
1407 * Does not deallocate the entity. */
1408 void remove_class_member(ir_type *clss, ir_entity *member);
1411 /** Adds subtype as subtype to clss.
1413 * Checks whether clss is a supertype of subtype. If not
1414 * adds also clss as supertype to subtype. */
1415 void add_class_subtype(ir_type *clss, ir_type *subtype);
1417 /** Returns the number of subtypes */
1418 int get_class_n_subtypes(const ir_type *clss);
1420 /** Gets the subtype at position pos, 0 <= pos < n_subtype. */
1421 ir_type *get_class_subtype(ir_type *clss, int pos);
1423 /** Returns the index to access subclass as subtype of class.
1425 * If subclass is no direct subtype of class returns -1.
1427 int get_class_subtype_index(ir_type *clss, const ir_type *subclass);
1429 /** Sets the subtype at position pos, 0 <= pos < n_subtype.
1431 * Does not set the corresponding supertype relation for subtype: this might
1432 * be a different position! */
1433 void set_class_subtype(ir_type *clss, ir_type *subtype, int pos);
1435 /** Finds subtype in the list of subtypes and removes it */
1436 void remove_class_subtype(ir_type *clss, ir_type *subtype);
1438 /* Convenience macros */
1439 #define add_class_derived_type(clss, drvtype) add_class_subtype(clss, drvtype)
1440 #define get_class_n_derived_types(clss) get_class_n_subtypes(clss)
1441 #define get_class_derived_type(clss, pos) get_class_subtype(clss, pos)
1442 #define get_class_derived_type_index(clss, drvtype) get_class_subtype_index(clss, drvtype)
1443 #define set_class_derived_type(clss, drvtype, pos) set_class_subtype(clss, drvtype, pos)
1444 #define remove_class_derived_type(clss, drvtype) remove_class_subtype(clss, drvtype)
1446 /** Adds supertype as supertype to class.
1448 * Checks whether clss is a subtype of supertype. If not
1449 * adds also clss as subtype to supertype. */
1450 void add_class_supertype(ir_type *clss, ir_type *supertype);
1452 /** Returns the number of supertypes */
1453 int get_class_n_supertypes(const ir_type *clss);
1455 /** Returns the index to access superclass as supertype of class.
1457 * If superclass is no direct supertype of class returns -1.
1459 int get_class_supertype_index(ir_type *clss, ir_type *super_clss);
1461 /** Gets the supertype at position pos, 0 <= pos < n_supertype. */
1462 ir_type *get_class_supertype(ir_type *clss, int pos);
1464 /** Sets the supertype at position pos, 0 <= pos < n_supertype.
1466 * Does not set the corresponding subtype relation for supertype: this might
1467 * be at a different position! */
1468 void set_class_supertype(ir_type *clss, ir_type *supertype, int pos);
1470 /** Finds supertype in the list of supertypes and removes it */
1471 void remove_class_supertype(ir_type *clss, ir_type *supertype);
1473 /** Convenience macro */
1474 #define add_class_base_type(clss, basetype) add_class_supertype(clss, basetype)
1475 #define get_class_n_base_types(clss) get_class_n_supertypes(clss)
1476 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
1477 #define get_class_base_type(clss, pos) get_class_supertype(clss, pos)
1478 #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos)
1479 #define remove_class_base_type(clss, basetype) remove_class_supertype(clss, basetype)
1481 /** Returns the type info entity of a class. */
1482 ir_entity *get_class_type_info(const ir_type *clss);
1484 /** Set a type info entity for the class. */
1485 void set_class_type_info(ir_type *clss, ir_entity *ent);
1487 /** Returns the size of the virtual function table. */
1488 unsigned get_class_vtable_size(const ir_type *clss);
1490 /** Sets a new size of the virtual function table. */
1491 void set_class_vtable_size(ir_type *clss, unsigned size);
1493 /** Returns non-zero if a class is final. */
1494 int is_class_final(const ir_type *clss);
1496 /** Sets the class final flag. */
1497 void set_class_final(ir_type *clss, int flag);
1499 /** Return non-zero if a class is an interface */
1500 int is_class_interface(const ir_type *clss);
1502 /** Sets the class interface flag. */
1503 void set_class_interface(ir_type *clss, int flag);
1505 /** Return non-zero if a class is an abstract class. */
1506 int is_class_abstract(const ir_type *clss);
1508 /** Sets the class abstract flag. */
1509 void set_class_abstract(ir_type *clss, int flag);
1511 /** Set and get a class' dfn --
1512 @todo This is an undocumented field, subject to change! */
1513 void set_class_dfn(ir_type *clss, int dfn);
1514 int get_class_dfn(const ir_type *clss);
1516 /** Returns true if a type is a class type. */
1517 int is_Class_type(const ir_type *clss);
1520 * @page struct_type Representation of a struct type
1522 * A struct type represents aggregate types that consist of a list
1525 * The following attributes are private to this type kind:
1526 * - member: All entities belonging to this class. This are the fields
1527 * that can have any of the following types: type_class,
1528 * type_struct, type_union, type_array, type_enumeration,
1529 * type_pointer, type_primitive.
1530 * This is a dynamic list that can be grown with an "add_" function,
1532 * This is a dynamic list that can be grown with an "add_" function,
1535 /** Creates a new type struct */
1536 ir_type *new_type_struct(ident *name);
1537 /** Creates a new type struct with debug information. */
1538 ir_type *new_d_type_struct(ident *name, type_dbg_info* db);
1540 /* --- manipulate private fields of struct --- */
1542 /** return struct identifier */
1543 ident *get_struct_ident(const ir_type *strct);
1545 /** return struct identifier as c-string*/
1546 const char *get_struct_name(const ir_type *strct);
1548 /** Adds the entity as member of the struct. */
1549 void add_struct_member(ir_type *strct, ir_entity *member);
1551 /** Returns the number of members of this struct. */
1552 int get_struct_n_members(const ir_type *strct);
1554 /** Returns the member at position pos, 0 <= pos < n_member */
1555 ir_entity *get_struct_member(const ir_type *strct, int pos);
1557 /** Returns index of member in strct, -1 if not contained. */
1558 int get_struct_member_index(const ir_type *strct, ir_entity *member);
1560 /** Overwrites the member at position pos, 0 <= pos < n_member with
1561 the passed entity. */
1562 void set_struct_member(ir_type *strct, int pos, ir_entity *member);
1564 /** Finds member in the list of members and removes it. */
1565 void remove_struct_member(ir_type *strct, ir_entity *member);
1567 /** Returns true if a type is a struct type. */
1568 int is_Struct_type(const ir_type *strct);
1571 * @page method_type Representation of a method type
1573 * A method type represents a method, function or procedure type.
1574 * It contains a list of the parameter and result types, as these
1575 * are part of the type description. These lists should not
1576 * be changed by a optimization, as a change creates a new method
1577 * type. Therefore optimizations should allocated new method types.
1578 * The set_ routines are only for construction by a frontend.
1580 * - n_params: Number of parameters to the procedure.
1581 * A procedure in FIRM has only call by value parameters.
1583 * - param_type: A list with the types of parameters. This list is ordered.
1584 * The nth type in this list corresponds to the nth element
1585 * in the parameter tuple that is a result of the start node.
1586 * (See ircons.h for more information.)
1588 * - value_param_ents
1589 * A list of entities (whose owner is a struct private to the
1590 * method type) that represent parameters passed by value.
1592 * - n_res: The number of results of the method. In general, procedures
1593 * have zero results, functions one.
1595 * - res_type: A list with the types of parameters. This list is ordered.
1596 * The nth type in this list corresponds to the nth input to
1597 * Return nodes. (See ircons.h for more information.)
1600 * A list of entities (whose owner is a struct private to the
1601 * method type) that represent results passed by value.
1604 /* These macros define the suffixes for the types and entities used
1605 to represent value parameters / results. */
1606 #define VALUE_PARAMS_SUFFIX "val_param"
1607 #define VALUE_RESS_SUFFIX "val_res"
1609 /** Create a new method type.
1611 * @param n_param the number of parameters
1612 * @param n_res the number of results
1614 * The arrays for the parameter and result types are not initialized by
1617 ir_type *new_type_method(int n_param, int n_res);
1619 /** Create a new method type with debug information.
1621 * @param n_param the number of parameters
1622 * @param n_res the number of results
1623 * @param db user defined debug information
1625 * The arrays for the parameter and result types are not initialized by
1628 ir_type *new_d_type_method(int n_param, int n_res, type_dbg_info *db);
1630 /* -- manipulate private fields of method. -- */
1632 /** Returns the number of parameters of this method. */
1633 int get_method_n_params(const ir_type *method);
1635 /** Returns the type of the parameter at position pos of a method. */
1636 ir_type *get_method_param_type(ir_type *method, int pos);
1637 /** Sets the type of the parameter 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 void set_method_param_type(ir_type *method, int pos, ir_type *tp);
1641 /** Returns an entity that represents the copied value argument. Only necessary
1642 for compounds passed by value. This information is constructed only on demand. */
1643 ir_entity *get_method_value_param_ent(ir_type *method, int pos);
1645 * Sets the type that represents the copied value arguments.
1647 void set_method_value_param_type(ir_type *method, ir_type *tp);
1649 * Returns a type that represents the copied value arguments if one
1650 * was allocated, else NULL.
1652 ir_type *get_method_value_param_type(const ir_type *method);
1653 /** Returns an ident representing the parameters name. Returns NULL if not set.
1654 For debug support only. */
1655 ident *get_method_param_ident(ir_type *method, int pos);
1656 /** Returns a string representing the parameters name. Returns NULL if not set.
1657 For debug support only. */
1658 const char *get_method_param_name(ir_type *method, int pos);
1659 /** Sets an ident representing the parameters name. For debug support only. */
1660 void set_method_param_ident(ir_type *method, int pos, ident *id);
1662 /** Returns the number of results of a method type. */
1663 int get_method_n_ress(const ir_type *method);
1664 /** Returns the return type of a method type at position pos. */
1665 ir_type *get_method_res_type(ir_type *method, int pos);
1666 /** Sets the type of the result at position pos of a method.
1667 Also changes the type in the pass-by-value representation by just
1668 changing the type of the corresponding entity if the representation is constructed. */
1669 void set_method_res_type(ir_type *method, int pos, ir_type *tp);
1670 /** Returns an entity that represents the copied value result. Only necessary
1671 for compounds passed by value. This information is constructed only on demand. */
1672 ir_entity *get_method_value_res_ent(ir_type *method, int pos);
1675 * Returns a type that represents the copied value results.
1677 ir_type *get_method_value_res_type(const ir_type *method);
1680 * This enum flags the variadicity of methods (methods with a
1681 * variable amount of arguments (e.g. C's printf). Default is
1684 typedef enum ir_variadicity {
1685 variadicity_non_variadic, /**< non variadic */
1686 variadicity_variadic /**< variadic */
1689 /** Returns the null-terminated name of this variadicity. */
1690 const char *get_variadicity_name(ir_variadicity vari);
1692 /** Returns the variadicity of a method. */
1693 ir_variadicity get_method_variadicity(const ir_type *method);
1695 /** Sets the variadicity of a method. */
1696 void set_method_variadicity(ir_type *method, ir_variadicity vari);
1699 * Returns the first variadic parameter index of a type.
1700 * If this index was NOT set, the index of the last parameter
1701 * of the method type plus one is returned for variadic functions.
1702 * Non-variadic function types always return -1 here.
1704 int get_method_first_variadic_param_index(const ir_type *method);
1707 * Sets the first variadic parameter index. This allows to specify
1708 * a complete call type (containing the type of all parameters)
1709 * but still have the knowledge, which parameter must be passed as
1712 void set_method_first_variadic_param_index(ir_type *method, int index);
1714 /** Returns the mask of the additional graph properties. */
1715 unsigned get_method_additional_properties(const ir_type *method);
1717 /** Sets the mask of the additional graph properties. */
1718 void set_method_additional_properties(ir_type *method, unsigned property_mask);
1720 /** Sets one additional graph property. */
1721 void set_method_additional_property(ir_type *method, mtp_additional_property flag);
1724 * Calling conventions: lower 24 bits are the number of register parameters,
1725 * upper 8 encode the calling conventions.
1728 cc_reg_param = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
1729 This flag may be set as default on some architectures. */
1730 cc_last_on_top = 0x02000000, /**< The last non-register parameter is transmitted on top of
1731 the stack. This is equivalent to the pascal
1732 calling convention. If this flag is not set, the first
1733 non-register parameter is used (stdcall or cdecl
1734 calling convention) */
1735 cc_callee_clear_stk = 0x04000000, /**< The callee clears the stack. This forbids variadic
1736 function calls (stdcall). */
1737 cc_this_call = 0x08000000, /**< The first parameter is a this pointer and is transmitted
1738 in a special way. */
1739 cc_compound_ret = 0x10000000, /**< The method returns a compound type. */
1740 cc_frame_on_caller_stk = 0x20000000, /**< The method did not allocate an own stack frame, instead the
1741 caller must reserve size on its own stack. */
1742 cc_fpreg_param = 0x40000000, /**< Transmit floating point parameters in registers, else the stack is used. */
1743 cc_bits = (0xFF << 24)/**< The calling convention bits. */
1744 } calling_convention;
1746 /* some often used cases: made as defines because firmjni cannot handle two
1747 equal enum values. */
1749 /** cdecl calling convention */
1750 #define cc_cdecl_set (0)
1751 /** stdcall calling convention */
1752 #define cc_stdcall_set cc_callee_clear_stk
1753 /** fastcall calling convention */
1754 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
1756 /** Returns the default calling convention for method types. */
1757 unsigned get_default_cc_mask(void);
1760 * check for the CDECL calling convention
1762 #define IS_CDECL(cc_mask) (((cc_mask) & cc_bits) == cc_cdecl_set)
1765 * check for the STDCALL calling convention
1767 #define IS_STDCALL(cc_mask) (((cc_mask) & cc_bits) == cc_stdcall_set)
1770 * check for the FASTCALL calling convention
1772 #define IS_FASTCALL(cc_mask) (((cc_mask) & cc_bits) == cc_fastcall_set)
1775 * Sets the CDECL convention bits.
1777 #define SET_CDECL(cc_mask) (((cc_mask) & ~cc_bits) | cc_cdecl_set)
1780 * Set. the STDCALL convention bits.
1782 #define SET_STDCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_stdcall_set)
1785 * Sets the FASTCALL convention bits.
1787 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
1789 /** Returns the calling convention of an entities graph. */
1790 unsigned get_method_calling_convention(const ir_type *method);
1792 /** Sets the calling convention of an entities graph. */
1793 void set_method_calling_convention(ir_type *method, unsigned cc_mask);
1795 /** Returns the number of registers parameters, 0 means default. */
1796 unsigned get_method_n_regparams(ir_type *method);
1798 /** Sets the number of registers parameters, 0 means default. */
1799 void set_method_n_regparams(ir_type *method, unsigned n_regs);
1801 /** Returns true if a type is a method type. */
1802 int is_Method_type(const ir_type *method);
1805 * @page union_type Representation of a union (variant) type.
1807 * The union type represents union types. Note that this representation
1808 * resembles the C union type. For tagged variant types like in Pascal or Modula
1809 * a combination of a struct and a union type must be used.
1811 * - n_types: Number of unioned types.
1812 * - members: Entities for unioned types. Fixed length array.
1813 * This is a dynamic list that can be grown with an "add_" function,
1816 /** Creates a new type union. */
1817 ir_type *new_type_union(ident *name);
1819 /** Creates a new type union with debug information. */
1820 ir_type *new_d_type_union(ident *name, type_dbg_info* db);
1822 /* --- manipulate private fields of struct --- */
1824 /** return union identifier */
1825 ident *get_union_ident(const ir_type *uni);
1827 /** return union identifier as c-string */
1828 const char *get_union_name(const ir_type *uni);
1830 /** Returns the number of unioned types of this union */
1831 int get_union_n_members(const ir_type *uni);
1833 /** Adds a new entity to a union type */
1834 void add_union_member(ir_type *uni, ir_entity *member);
1836 /** Returns the entity at position pos of a union */
1837 ir_entity *get_union_member(const ir_type *uni, int pos);
1839 /** Returns index of member in uni, -1 if not contained. */
1840 int get_union_member_index(const ir_type *uni, ir_entity *member);
1842 /** Overwrites a entity at position pos in a union type. */
1843 void set_union_member(ir_type *uni, int pos, ir_entity *member);
1845 /** Finds member in the list of members and removes it. */
1846 void remove_union_member(ir_type *uni, ir_entity *member);
1848 /** Returns true if a type is a union type. */
1849 int is_Union_type(const ir_type *uni);
1852 * @page array_type Representation of an array type
1854 * The array type represents rectangular multi dimensional arrays.
1855 * The constants representing the bounds must be allocated to
1856 * get_const_code_irg() by setting current_ir_graph accordingly.
1858 * - n_dimensions: Number of array dimensions.
1859 * - *lower_bound: Lower bounds of dimensions. Usually all 0.
1860 * - *upper_bound: Upper bounds or dimensions.
1861 * - *element_type: The type of the array elements.
1862 * - *element_ent: An entity for the array elements to be used for
1863 * element selection with Sel.
1865 * Do we need several entities? One might want
1866 * to select a dimension and not a single element in case of multi
1867 * dimensional arrays.
1870 /** Create a new type array.
1872 * Sets n_dimension to dimension and all dimension entries to NULL.
1873 * Initializes order to the order of the dimensions.
1874 * The entity for array elements is built automatically.
1875 * Set dimension sizes after call to constructor with set_* routines.
1877 ir_type *new_type_array(int n_dims, ir_type *element_type);
1879 /** Create a new type array with debug information.
1881 * Sets n_dimension to dimension and all dimension entries to NULL.
1882 * Initializes order to the order of the dimensions.
1883 * The entity for array elements is built automatically.
1884 * Set dimension sizes after call to constructor with set_* routines.
1885 * A legal array type must have at least one dimension set.
1887 ir_type *new_d_type_array(int n_dims, ir_type *element_type, type_dbg_info* db);
1889 /* --- manipulate private fields of array type --- */
1891 /** Returns the number of array dimensions of this type. */
1892 int get_array_n_dimensions(const ir_type *array);
1895 * Allocates Const nodes of mode_Is for one array dimension.
1896 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1898 void set_array_bounds_int(ir_type *array, int dimension, int lower_bound,
1901 * Sets the bounds for one array dimension.
1902 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
1904 void set_array_bounds(ir_type *array, int dimension, ir_node *lower_bound,
1905 ir_node *upper_bound);
1906 /** Sets the lower bound for one array dimension, i.e. [lower,upper[ */
1907 void set_array_lower_bound(ir_type *array, int dimension, ir_node *lower_bound);
1909 /** Allocates Const nodes of mode_Is for the lower bound of an array
1910 dimension, i.e. [lower,upper[ */
1911 void set_array_lower_bound_int(ir_type *array, int dimension, int lower_bound);
1913 /** Sets the upper bound for one array dimension, i.e. [lower,upper[ */
1914 void set_array_upper_bound(ir_type *array, int dimension, ir_node *upper_bound);
1916 /** Allocates Const nodes of mode_Is for the upper bound of an array
1917 dimension, i.e. [lower,upper[. */
1918 void set_array_upper_bound_int(ir_type *array, int dimension, int upper_bound);
1920 /** Returns true if lower bound != Unknown. */
1921 int has_array_lower_bound(const ir_type *array, int dimension);
1922 /** Returns the lower bound of an array. */
1923 ir_node *get_array_lower_bound(const ir_type *array, int dimension);
1924 /** Works only if bound is Const node with tarval that can be converted to long. */
1925 long get_array_lower_bound_int(const ir_type *array, int dimension);
1926 /** returns true if lower bound != Unknown */
1927 int has_array_upper_bound(const ir_type *array, int dimension);
1928 /** Returns the upper bound of an array. */
1929 ir_node *get_array_upper_bound(const ir_type *array, int dimension);
1930 /** Works only if bound is Const node with tarval that can be converted to long. */
1931 long get_array_upper_bound_int(const ir_type *array, int dimension);
1933 /** Sets an array dimension to a specific order. */
1934 void set_array_order(ir_type *array, int dimension, int order);
1936 /** Returns the order of an array dimension. */
1937 int get_array_order(const ir_type *array, int dimension);
1939 /** Find the array dimension that is placed at order order. */
1940 int find_array_dimension(const ir_type *array, int order);
1942 /** Sets the array element type. */
1943 void set_array_element_type(ir_type *array, ir_type* tp);
1945 /** Gets the array element type. */
1946 ir_type *get_array_element_type(const ir_type *array);
1948 /** Sets the array element entity. */
1949 void set_array_element_entity(ir_type *array, ir_entity *ent);
1951 /** Get the array element entity. */
1952 ir_entity *get_array_element_entity(const ir_type *array);
1954 /** Returns true if a type is an array type. */
1955 int is_Array_type(const ir_type *array);
1958 * @page enumeration_type Representation of an enumeration type
1960 * Enumeration types need not necessarily be represented explicitly
1961 * by Firm types, as the frontend can lower them to integer constants as
1962 * well. For debugging purposes or similar tasks this information is useful.
1963 * The type state layout_fixed is set, if all enumeration constant have
1964 * there tarvals assigned. Until then
1966 * - *const: The target values representing the constants used to
1967 * represent individual enumerations.
1970 /** Create a new type enumeration -- set the enumerators independently. */
1971 ir_type *new_type_enumeration(ident *name, int n_enums);
1973 /** Create a new type enumeration with debug information -- set the enumerators independently. */
1974 ir_type *new_d_type_enumeration(ident *name, int n_enums, type_dbg_info *db);
1976 /* --- manipulate fields of enumeration type. --- */
1978 /** return enumeration identifier */
1979 ident *get_enumeration_ident(const ir_type *enumeration);
1981 /** return enumeration identifier as c-string */
1982 const char *get_enumeration_name(const ir_type *enumeration);
1984 /** Set an enumeration constant to a enumeration type at a given position. */
1985 void set_enumeration_const(ir_type *enumeration, int pos, ident *nameid, tarval *con);
1987 /** Returns the number of enumeration values of this enumeration */
1988 int get_enumeration_n_enums(const ir_type *enumeration);
1990 /** Returns the enumeration constant at a given position. */
1991 ir_enum_const *get_enumeration_const(const ir_type *enumeration, int pos);
1993 /** Returns the enumeration type owner of an enumeration constant. */
1994 ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst);
1996 /** Sets the enumeration constant value. */
1997 void set_enumeration_value(ir_enum_const *enum_cnst, tarval *con);
1999 /** Returns the enumeration constant value. */
2000 tarval *get_enumeration_value(const ir_enum_const *enum_cnst);
2002 /** Assign an ident to an enumeration constant. */
2003 void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
2005 /** Returns the assigned ident of an enumeration constant. */
2006 ident *get_enumeration_const_nameid(const ir_enum_const *enum_cnst);
2008 /** Returns the assigned name of an enumeration constant. */
2009 const char *get_enumeration_const_name(const ir_enum_const *enum_cnst);
2011 /** Returns true if a type is a enumeration type. */
2012 int is_Enumeration_type(const ir_type *enumeration);
2015 * @page pointer_type Representation of a pointer type
2018 * - points_to: The type of the entity this pointer points to.
2021 /** Creates a new type pointer. */
2022 ir_type *new_type_pointer(ir_type *points_to);
2024 /** Creates a new type pointer with debug information. */
2025 ir_type *new_d_type_pointer(ir_type *points_to, type_dbg_info* db);
2027 /* --- manipulate fields of type_pointer --- */
2029 /** Sets the type to which a pointer points to. */
2030 void set_pointer_points_to_type(ir_type *pointer, ir_type *tp);
2032 /** Returns the type to which a pointer points to. */
2033 ir_type *get_pointer_points_to_type(const ir_type *pointer);
2035 /** Returns true if a type is a pointer type. */
2036 int is_Pointer_type(const ir_type *pointer);
2038 /** Returns the first pointer type that has as points_to tp.
2039 * Not efficient: O(\#types).
2040 * If not found returns firm_unknown_type. */
2041 ir_type *find_pointer_type_to_type(ir_type *tp);
2044 * @page primitive_type Representation of a primitive type
2046 * Primitive types are types that represent atomic data values that
2047 * map directly to modes. They don't have private attributes. The
2048 * important information they carry is held in the common mode field.
2050 /** Creates a new primitive type. */
2051 ir_type *new_type_primitive(ir_mode *mode);
2053 /** Creates a new primitive type with debug information. */
2054 ir_type *new_d_type_primitive(ir_mode *mode, type_dbg_info* db);
2056 /** Returns true if a type is a primitive type. */
2057 int is_Primitive_type(const ir_type *primitive);
2059 /** Return the base type of a primitive (bitfield) type or NULL if none. */
2060 ir_type *get_primitive_base_type(const ir_type *tp);
2062 /** Sets the base type of a primitive (bitfield) type. */
2063 void set_primitive_base_type(ir_type *tp, ir_type *base_tp);
2066 * @page none_type The None type
2068 * This type is an auxiliary type dedicated to support type analyses.
2070 * The none type represents that there is no type. The type can be used to
2071 * initialize fields of type* that actually can not contain a type or that
2072 * are initialized for an analysis. There exists exactly one type none.
2073 * This type is not on the type list in ir_prog. It is
2074 * allocated when initializing the type module.
2076 * The following values are set:
2078 * - name: "type_none"
2079 * - state: layout_fixed
2082 /** A variable that contains the only none type. */
2083 extern ir_type *firm_none_type;
2085 /** A variable that contains the only code type. */
2086 extern ir_type *firm_code_type;
2088 /** Returns the none type. */
2089 ir_type *get_none_type(void);
2090 /** Returns the code type. */
2091 ir_type *get_code_type(void);
2094 * @page unknown_type The Unknown type
2096 * This type is an auxiliary type dedicated to support type analyses.
2098 * The unknown type represents that there could be a type, but it is not
2099 * known. This type can be used to initialize fields before an analysis (not known
2100 * yet) or to represent the top of a lattice (could not be determined). There exists
2101 * exactly one type unknown. This type is not on the type list in ir_prog. It is
2102 * allocated when initializing the type module.
2104 * The following values are set:
2106 * - name: "type_unknown"
2107 * - state: layout_fixed
2110 /** A variable that contains the only unknown type. */
2111 extern ir_type *firm_unknown_type;
2113 /** Returns the unknown type. */
2114 ir_type *get_unknown_type(void);
2118 * Checks whether a type is atomic.
2119 * @param tp any type
2120 * @return true if type is primitive, pointer or enumeration
2122 int is_atomic_type(const ir_type *tp);
2124 /* --- Support for compound types --- */
2127 * Gets the identifier of a compound type
2129 ident *get_compound_ident(const ir_type *tp);
2131 /** return compound identifier as c-string */
2132 const char *get_compound_name(const ir_type *tp);
2135 * Gets the number of elements in a Firm compound type.
2137 * This is just a comfortability function, because structs and
2138 * classes can often be treated be the same code, but they have
2139 * different access functions to their members.
2141 * @param tp The type (must be struct, union or class).
2143 * @return Number of members in the compound type.
2145 int get_compound_n_members(const ir_type *tp);
2148 * Gets the member of a Firm compound type at position pos.
2150 * @param tp The type (must be struct, union or class).
2151 * @param pos The number of the member.
2153 * @return The member entity at position pos.
2155 ir_entity *get_compound_member(const ir_type *tp, int pos);
2157 /** Returns index of member in tp, -1 if not contained. */
2158 int get_compound_member_index(const ir_type *tp, ir_entity *member);
2161 * layout members of a struct/union or class type in a default way.
2163 void default_layout_compound_type(ir_type *tp);
2166 * Checks whether a type is a compound type.
2168 * @param tp - any type
2170 * @return true if the type is class, structure, union or array type.
2172 int is_compound_type(const ir_type *tp);
2175 * Checks wether a type is a code type.
2177 int is_code_type(const ir_type *tp);
2180 * Checks, whether a type is a frame type.
2182 int is_frame_type(const ir_type *tp);
2185 * Checks, whether a type is a value parameter type.
2187 int is_value_param_type(const ir_type *tp);
2190 * Checks, whether a type is a lowered type.
2192 int is_lowered_type(const ir_type *tp);
2195 * Makes a new value type. Value types are struct types,
2196 * so all struct access functions work.
2197 * Value types are not in the global list of types.
2199 ir_type *new_type_value(void);
2202 * Makes a new frame type. Frame types are class types,
2203 * so all class access functions work.
2204 * Frame types are not in the global list of types.
2206 ir_type *new_type_frame(void);
2209 * Makes a clone of a frame type.
2210 * Sets entity links from old frame entities to new onces and
2213 ir_type *clone_frame_type(ir_type *type);
2216 * Sets a lowered type for a type. This sets both associations
2217 * and marks lowered_type as a "lowered" one.
2219 void set_lowered_type(ir_type *tp, ir_type *lowered_type);
2222 * Gets the lowered/unlowered type of a type or NULL if this type
2223 * has no lowered/unlowered one.
2225 ir_type *get_associated_type(const ir_type *tp);
2228 * Allocate an area of size bytes aligned at alignment
2229 * at the start or the end of a frame type.
2230 * The frame type must already have a fixed layout.
2232 * @param frame_type a frame type
2233 * @param size the size of the entity
2234 * @param alignment the alignment of the entity
2235 * @param at_start if true, put the area at the frame type's start, else at end
2237 * @return the entity representing the area
2239 ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, int at_start);
2241 /*-----------------------------------------------------------------*/
2243 /*-----------------------------------------------------------------*/
2246 * Outputs a unique number for this type if libfirm is compiled for
2247 * debugging, (configure with --enable-debug) else returns the address
2248 * of the type cast to long.
2250 long get_type_nr(const ir_type *tp);
2252 /* ------------------------------------------------------------------------ */
2254 /** Type for a function that compares two types.
2256 * @param tp1 The first type to compare.
2257 * @param tp2 The second type to compare.
2259 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
2261 /** Compares two types by their name.
2263 * Compares the opcode and the name of the types. If these are
2264 * equal returns 0, else non-zero.
2266 int compare_names(const void *tp1, const void *tp2);
2268 /** Compares two types strict.
2270 * returns 0 if tp1 == tp2, else non-zero
2272 int compare_strict(const void *tp1, const void *tp2);
2274 /* ------------------------------------------------------------------------ */
2276 /** Computes a hash value by the type name.
2278 * Uses the name of the type and the type opcode to compute the hash.
2280 int firm_hash_name(ir_type *tp);
2282 /* ------------------------------------------------------------------------ */
2284 /** Finalize type construction.
2286 * Indicate that a type is so far completed that it can be
2287 * distinguished from other types. Mature_type hashes the type into a
2288 * table. It uses the function in compare_types_func to compare the
2291 * If it finds a type identical to tp it returns this type. It turns
2292 * tp into the Id type. All places formerly pointing to tp will now
2293 * point to the found type. All entities of tp now refer to the found
2294 * type as their owner, but they are not a member of this type. This
2295 * is invalid firm -- the entities must be replaced by entities of the
2296 * found type. The Id type will be removed from the representation
2297 * automatically, but within an unknown time span. It occupies memory
2300 * @param tp The type to mature.
2302 ir_type *mature_type(ir_type *tp);
2304 /** Finalize type construction.
2306 * Indicate that a type is so far completed that it can be
2307 * distinguished from other types. mature_type() hashes the type into a
2308 * table. It uses the function in compare_types_func to compare the
2311 * If it finds a type identical to tp it returns this type. It frees
2312 * type tp and all its entities.
2314 * @param tp The type to mature.
2316 ir_type *mature_type_free(ir_type *tp);
2318 /** Finalize type construction.
2320 * Indicate that a type is so far completed that it can be
2321 * distinguished from other types. Mature_type hashes the type into a
2322 * table. It uses the function in compare_types_func to compare the
2325 * If it find a type identical to tp it returns this type. It frees
2326 * the entities and turns the type into an Id type. All places
2327 * formerly pointing to tp will now point to the found type. The Id
2328 * type will be removed from the representation automatically, but
2329 * within an unknown time span. It occupies memory for this time.
2331 * @param tp The type to mature.
2333 ir_type *mature_type_free_entities(ir_type *tp);
2335 /** A data type to treat types and entities as the same. */
2337 ir_type *typ; /**< points to a type */
2338 ir_entity *ent; /**< points to an entity */
2341 /** Type of argument functions for type walkers.
2343 * @param tore points to the visited type or entity
2344 * @param env free environment pointer
2346 typedef void type_walk_func(type_or_ent tore, void *env);
2348 /** The class walk function
2350 * @param clss points to the visited class
2351 * @param env free environment pointer
2353 typedef void class_walk_func(ir_type *clss, void *env);
2355 /** Touches every type and entity in unspecified order. If new
2356 * types/entities are created during the traversal these will
2358 * Does not touch frame types or types for value params ... */
2359 void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
2361 /** Touches every type, entity, frame type, and value param type in
2362 * unspecified order (also all segment types). */
2363 void type_walk_prog(type_walk_func *pre, type_walk_func *post, void *env);
2365 /** Walks over all type information reachable from an ir graph.
2367 * Walks over all type information reachable from irg, i.e., starts a
2368 * type walk at the irgs entity, the irgs frame type and all types and
2369 * entities that are attributes to firm nodes. */
2370 void type_walk_irg(ir_graph *irg, type_walk_func *pre, type_walk_func *post,
2374 Touches every class in specified order:
2375 - first the super class
2376 - second the class itself
2377 - third the sub classes. If new classes are created
2378 during the traversal these will be visited, too.
2380 @todo should be named class-walk
2382 @deprecated will be removed?
2384 void type_walk_super2sub(type_walk_func *pre, type_walk_func *post, void *env);
2386 /** Walker for class types in inheritance order.
2388 * Touches every class in specified order:
2389 * - first the super class
2390 * - second the class itself
2391 * If new classes are created during the traversal these
2392 * will be visited, too.
2393 * Starts the walk at arbitrary classes.
2394 * Executes pre when first visiting a class. Executes post after
2395 * visiting all superclasses.
2397 * The arguments pre, post, env may be NULL. */
2398 void type_walk_super(type_walk_func *pre, type_walk_func *post, void *env);
2400 /** Same as type_walk_super2sub, but visits only class types.
2401 Executes pre for a class if all superclasses have been visited.
2402 Then iterates to subclasses. Executes post after return from
2404 Does not visit global type, frame types.
2406 void class_walk_super2sub(class_walk_func *pre, class_walk_func *post,
2410 * the entity walk function. A function type for entity walkers.
2412 * @param ent points to the visited entity
2413 * @param env free environment pointer
2415 typedef void entity_walk_func(ir_entity *ent, void *env);
2418 * Walks over all entities in the type.
2420 * @param tp the type
2421 * @param doit the entity walker function
2422 * @param env environment, will be passed to the walker function
2424 void walk_types_entities(ir_type *tp, entity_walk_func *doit, void *env);
2427 * If we have the closed world assumption, we can calculate the
2428 * finalization of classes and entities by inspecting the class hierarchy.
2429 * After this is done, all classes and entities that are not overridden
2430 * anymore have the final property set.
2432 void types_calc_finalization(void);
2435 ir_visibility get_type_visibility(const ir_type *tp);
2437 void set_type_visibility(ir_type *tp, ir_visibility v);
2441 allocation_automatic,
2442 allocation_parameter,
2447 ir_allocation get_entity_allocation(const ir_entity *ent);
2449 void set_entity_allocation(ir_entity *ent, ir_allocation al);
2453 peculiarity_existent,
2454 peculiarity_description,
2455 peculiarity_inherited
2458 ir_peculiarity get_entity_peculiarity(const ir_entity *ent);
2460 void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec);
2463 int is_entity_final(const ir_entity *ent);
2465 void set_entity_final(ir_entity *ent, int final);
2468 ir_peculiarity get_class_peculiarity(const ir_type *clss);
2470 void set_class_peculiarity(ir_type *clss, ir_peculiarity pec);