2 * Copyright (C) 1995-2007 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
19 #ifndef FIRM_TYPEREP_H
20 #define FIRM_TYPEREP_H
22 #include "firm_types.h"
25 * @page entity Entity representation
27 * An entity is the representation of program known objects in Firm.
28 * The primary concept of entities is to represent members of complex
29 * types, i.e., fields and methods of classes. As not all programming
30 * language model all variables and methods as members of some class,
31 * the concept of entities is extended to cover also local and global
32 * variables, and arbitrary procedures.
34 * An entity always specifies the type of the object it represents and
35 * the type of the object it is a part of, the owner of the entity.
36 * Originally this is the type of the class of which the entity is a
38 * The owner of local variables is the procedure they are defined in.
39 * The owner of global variables and procedures visible in the whole
40 * program is a universally defined class type "GlobalType". The owner
41 * of procedures defined in the scope of an other procedure is the
42 * enclosing procedure.
44 * The type ir_entity is an abstract data type to represent program entities.
45 * If contains the following attributes:
47 * - owner: A compound type this entity is a part of.
48 * - type: The type of this entity.
49 * - name: The string that represents this entity in the source program. * - allocation: A flag saying whether the entity is dynamically or statically * allocated (values: dynamic_allocated, static_allocated,
50 * automatic_allocated).
51 * - visibility: A flag indicating the visibility of this entity (values: local,
52 * external_visible, external_allocated)
53 * - variability: A flag indicating the variability of this entity (values:
54 * uninitialized, initialized, part_constant, constant)
56 * - offset: The offset of the entity within the compound object in bytes. Only set
57 * if the owner in the state "layout_fixed".
58 * - offset_bits_remainder: The offset bit remainder of a bitfield entity (in a compound)
59 * in bits. Only set if the owner in the state "layout_fixed".
60 * - overwrites: A list of entities overwritten by this entity. This list is only
61 * existent if the owner of this entity is a class. The members in
62 * this list must be entities of super classes.
63 * - overwrittenby: A list of entities that overwrite 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 sub classes.
66 * - link: A void* to associate some additional information with the entity.
67 * - irg: If the entity is a method this is the ir graph that represents the
69 * - peculiarity: The peculiarity of the entity. If the entity is a method this
70 * indicates whether the entity represents
71 * a real method or whether it only exists to describe an interface.
72 * In that case there nowhere exists code for this entity and this entity
73 * is never dynamically used in the code.
74 * Values: description, existent. Default: existent.
75 * - visited: visited flag. Master flag is type_visited.
77 * These fields can only be accessed via access functions.
79 * @see ir_type, ir_entity
82 /** This enumeration flags the visibility of entities and types.
84 * This is necessary for partial compilation.
85 * We rely on the ordering of the flags.
88 visibility_local, /**< The entity is only visible locally. This is the default for
90 The type is only visible locally. All instances are allocated
91 locally, and no pointer to entities of this type are passed
92 out of this compilation unit. */
93 visibility_external_visible, /**< The entity is visible to other external program parts, but
94 it is defined here. It may not be optimized away. The entity must
96 For types: entities of this type can be accessed externally. No
97 instances of this type are allocated externally. */
98 visibility_external_allocated /**< The entity is defined and allocated externally. This compilation
99 must not allocate memory for this entity. The entity must
100 be static_allocated. This can also be an external defined
102 For types: entities of this type are allocated and accessed from
103 external code. Default for types. */
106 /** This enumeration flags the peculiarity of entities and types. */
108 peculiarity_description, /**< Represents only a description. The entity/type is never
109 allocated, no code/data exists for this entity/type.
110 @@@ eventually rename to descriptive (adjective as the others!)*/
111 peculiarity_inherited, /**< Describes explicitly that other entities are
112 inherited to the owner of this entity.
113 Overwrites must refer to at least one other
114 entity. If this is a method entity there exists
115 no irg for this entity, only for one of the
118 peculiarity_existent /**< The entity/type (can) exist.
119 @@@ eventually rename to 'real' i.e., 'echt'
120 This serves better as opposition to description _and_ inherited.*/
124 * Additional method type properties:
125 * Tell about special properties of a method type. Some
126 * of these may be discovered by analyses.
129 mtp_no_property = 0x00000000, /**< no additional properties, default */
130 mtp_property_const = 0x00000001, /**< This method did not access memory and calculates
131 its return values solely from its parameters.
132 GCC: __attribute__((const)). */
133 mtp_property_pure = 0x00000002, /**< This method did NOT write to memory and calculates
134 its return values solely from its parameters and
135 the memory they points to (or global vars).
136 GCC: __attribute__((pure)). */
137 mtp_property_noreturn = 0x00000004, /**< This method did not return due to an aborting system
139 GCC: __attribute__((noreturn)). */
140 mtp_property_nothrow = 0x00000008, /**< This method cannot throw an exception.
141 GCC: __attribute__((nothrow)). */
142 mtp_property_naked = 0x00000010, /**< This method is naked.
143 GCC: __attribute__((naked)). */
144 mtp_property_malloc = 0x00000020, /**< This method returns newly allocate memory.
145 GCC: __attribute__((malloc)). */
146 mtp_property_intrinsic = 0x00000040, /**< This method is intrinsic. It is expected that
147 a lowering phase will remove all calls to it. */
148 mtp_property_runtime = 0x00000080, /**< This method represents a runtime routine. */
149 mtp_property_private = 0x00000100, /**< All method invocations are known, the backend is free to
150 optimize the call in any possible way. */
151 mtp_property_inherited = (1<<31) /**< Internal. Used only in irg's, means property is
152 inherited from type. */
153 } mtp_additional_property;
156 * Creates a new entity.
158 * Automatically inserts the entity as a member of owner.
159 * Entity is automatic_allocated and uninitialized except if the type
160 * is type_method, then it is static_allocated and constant. The constant
161 * value is a pointer to the method.
162 * Visibility is local, offset -1, and it is not volatile.
164 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp);
167 * Creates a new entity.
169 * Automatically inserts the entity as a member of owner.
170 * The entity is automatic allocated and uninitialized except if the type
171 * is type_method, then it is static allocated and constant. The constant
172 * value is a pointer to the method.
173 * Visibility is local, offset -1, and it is not volatile.
175 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp, dbg_info *db);
178 * Copies the entity if the new_owner is different from the
179 * owner of the old entity, else returns the old entity.
181 * Automatically inserts the new entity as a member of owner.
182 * Resets the overwrites/overwritten_by fields.
183 * Keeps the old atomic value.
184 * @@@ Maybe we should change this. If peculiarity of a method
185 * is existent, we should add a new SymConst that points to
186 * itself and not to the origin. Right now we have to change
187 * the peculiarity and then set a new atomic value by hand.
189 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner);
192 * Copies the entity if the new_name is different from the
193 * name of the old entity, else returns the old entity.
195 * Automatically inserts the new entity as a member of owner.
196 * The mangled name ld_name is set to NULL.
197 * Overwrites relation is copied from old.
199 ir_entity *copy_entity_name(ir_entity *old, ident *new_name);
204 * The owner will still contain the pointer to this
205 * entity, as well as all other references!
207 void free_entity(ir_entity *ent);
209 /** Returns the name of an entity. */
210 const char *get_entity_name(const ir_entity *ent);
212 /** Returns the ident of an entity. */
213 ident *get_entity_ident(const ir_entity *ent);
215 /** Sets the ident of the entity. */
216 void set_entity_ident(ir_entity *ent, ident *id);
218 /** Returns the mangled name of the entity.
220 * If the mangled name is set it returns the existing name.
221 * Else it generates a name with mangle_entity()
222 * and remembers this new name internally.
224 ident *get_entity_ld_ident(ir_entity *ent);
226 /** Sets the mangled name of the entity. */
227 void set_entity_ld_ident(ir_entity *ent, ident *ld_ident);
229 /** Returns the mangled name of the entity as a string. */
230 const char *get_entity_ld_name(ir_entity *ent);
232 /** Returns the owner of the entity. */
233 ir_type *get_entity_owner(ir_entity *ent);
235 /** Sets the owner field in entity to owner. Don't forget to add
237 void set_entity_owner(ir_entity *ent, ir_type *owner);
239 /** Returns the type of an entity. */
240 ir_type *get_entity_type(ir_entity *ent);
242 /** Sets the type of an entity. */
243 void set_entity_type(ir_entity *ent, ir_type *tp);
245 /** The allocation type. */
247 allocation_automatic, /**< The entity is allocated during runtime, implicitly
248 as component of a compound type. This is the default. */
249 allocation_parameter, /**< The entity is a parameter. It is also automatic allocated.
250 We distinguish the allocation of parameters from the allocation
251 of local variables as their placement depends on the calling
253 allocation_dynamic, /**< The entity is allocated during runtime, explicitly
255 allocation_static /**< The entity is allocated statically. We can use a
256 Const as address of the entity. This is the default for methods. */
259 /** Returns the allocation type of an entity. */
260 ir_allocation get_entity_allocation(const ir_entity *ent);
262 /** Sets the allocation type of an entity. */
263 void set_entity_allocation(ir_entity *ent, ir_allocation al);
265 /** Return the name of the allocation type. */
266 const char *get_allocation_name(ir_allocation vis);
268 /** Returns the visibility of an entity. */
269 ir_visibility get_entity_visibility(const ir_entity *ent);
271 /** Sets the visibility of an entity. */
272 void set_entity_visibility(ir_entity *ent, ir_visibility vis);
274 /** Return the name of the visibility */
275 const char *get_visibility_name(ir_visibility vis);
277 /** This enumeration flags the variability of entities. */
279 variability_uninitialized, /**< The content of the entity is completely unknown. Default. */
280 variability_initialized, /**< After allocation the entity is initialized with the
281 value given somewhere in the entity. */
282 variability_part_constant, /**< For entities of compound types.
283 The members of the entity are mixed constant,
284 initialized or uninitialized. */
285 variability_constant /**< The entity is constant. */
288 /** Returns the variability of an entity. */
289 ir_variability get_entity_variability(const ir_entity *ent);
291 /** Sets the variability of an entity. */
292 void set_entity_variability(ir_entity *ent, ir_variability var);
294 /** Return the name of the variability. */
295 const char *get_variability_name(ir_variability var);
297 /** This enumeration flags the volatility of entities. */
299 volatility_non_volatile, /**< The entity is not volatile. Default. */
300 volatility_is_volatile /**< The entity is volatile */
303 /** Returns the volatility of an entity. */
304 ir_volatility get_entity_volatility(const ir_entity *ent);
306 /** Sets the volatility of an entity. */
307 void set_entity_volatility(ir_entity *ent, ir_volatility vol);
309 /** Return the name of the volatility. */
310 const char *get_volatility_name(ir_volatility var);
312 /** This enumeration flags the stickyness of an entity. */
314 stickyness_unsticky, /**< The entity can be removed from
315 the program, unless contraindicated
316 by other attributes. Default. */
317 stickyness_sticky /**< The entity must remain in the
318 program in any case. */
321 /** Get the entity's stickyness. */
322 ir_stickyness get_entity_stickyness(const ir_entity *ent);
324 /** Set the entity's stickyness. */
325 void set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness);
327 /** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */
328 int get_entity_offset(const ir_entity *ent);
330 /** Sets the offset of an entity (in a compound) in bytes. */
331 void set_entity_offset(ir_entity *ent, int offset);
333 /** Returns the offset bit remainder of a bitfield entity (in a compound) in bits. Only set if layout = fixed. */
334 unsigned char get_entity_offset_bits_remainder(const ir_entity *ent);
336 /** Sets the offset bit remainder of a bitfield entity (in a compound) in bits. */
337 void set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset);
339 /** Returns the stored intermediate information. */
340 void *get_entity_link(const ir_entity *ent);
342 /** Stores new intermediate information. */
343 void set_entity_link(ir_entity *ent, void *l);
345 /* -- Fields of method entities -- */
346 /** The entity knows the corresponding irg if the entity is a method.
347 This allows to get from a Call to the called irg.
348 Only entities of peculiarity "existent" can have a corresponding irg,
349 else the field is fixed to NULL. (Get returns NULL, set asserts.) */
350 ir_graph *get_entity_irg(const ir_entity *ent);
351 void set_entity_irg(ir_entity *ent, ir_graph *irg);
353 /** Gets the entity vtable number. */
354 unsigned get_entity_vtable_number(const ir_entity *ent);
356 /** Sets the entity vtable number. */
357 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number);
359 /** Return the peculiarity of an entity. */
360 ir_peculiarity get_entity_peculiarity(const ir_entity *ent);
362 /** Sets the peculiarity of an entity. */
363 void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec);
365 /** Checks if an entity cannot be overridden anymore. */
366 int is_entity_final(const ir_entity *ent);
368 /** Sets/resets the final flag of an entity. */
369 void set_entity_final(ir_entity *ent, int final);
371 /** Checks if an entity is compiler generated. */
372 int is_entity_compiler_generated(const ir_entity *ent);
374 /** Sets/resets the compiler generated flag. */
375 void set_entity_compiler_generated(ir_entity *ent, int flag);
377 /** Checks if an entity is marked by the backend. */
378 int is_entity_backend_marked(const ir_entity *ent);
380 /** Sets/resets the backend marker flag. */
381 void set_entity_backend_marked(ir_entity *ent, int flag);
384 * The state of the address_taken flag.
387 ir_address_not_taken = 0, /**< The address is NOT taken. */
388 ir_address_taken_unknown = 1, /**< The state of the address taken flag is unknown. */
389 ir_address_taken = 2 /**< The address IS taken. */
390 } ir_address_taken_state;
392 /** Return the state of the address taken flag of an entity. */
393 ir_address_taken_state get_entity_address_taken(const ir_entity *ent);
395 /** Sets/resets the state of the address taken flag of an entity. */
396 void set_entity_address_taken(ir_entity *ent, ir_address_taken_state flag);
398 /** Return the name of the address_taken state. */
399 const char *get_address_taken_state_name(ir_address_taken_state state);
402 * Returns the debug information of an entity.
404 * @param ent The entity.
406 dbg_info *get_entity_dbg_info(const ir_entity *ent);
409 * Sets the debug information of an entity.
411 * @param ent The entity.
412 * @param db The debug info.
414 void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
416 /* -- Representation of constant values of entities -- */
418 * Returns true if the the node is representable as code on
421 * @deprecated This function is not used by libFirm and stays here
422 * only as a helper for the old Jack frontend.
424 int is_irn_const_expression(ir_node *n);
427 * Copies a Firm subgraph that complies to the restrictions for
428 * constant expressions to current_block in current_ir_graph.
430 * @param dbg debug info for all newly created nodes
433 * Set current_ir_graph to get_const_code_irg() to generate a constant
436 ir_node *copy_const_value(dbg_info *dbg, ir_node *n);
438 /* Set has no effect for existent entities of type method. */
439 ir_node *get_atomic_ent_value(ir_entity *ent);
440 void set_atomic_ent_value(ir_entity *ent, ir_node *val);
442 /** Creates a new compound graph path. */
443 compound_graph_path *new_compound_graph_path(ir_type *tp, int length);
445 /** Returns non-zero if an object is a compound graph path */
446 int is_compound_graph_path(const void *thing);
448 /** Frees a graph path object */
449 void free_compound_graph_path (compound_graph_path *gr);
451 /** Returns the length of a graph path */
452 int get_compound_graph_path_length(const compound_graph_path *gr);
454 ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, int pos);
455 void set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node);
456 int get_compound_graph_path_array_index(const compound_graph_path *gr, int pos);
457 void set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index);
459 /** Checks whether the path up to pos is correct. If the path contains a NULL,
460 * assumes the path is not complete and returns non-zero. */
461 int is_proper_compound_graph_path(compound_graph_path *gr, int pos);
463 /* A value of a compound entity is a pair of a value and the description of the
464 corresponding access path to the member of the compound. */
465 void add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path);
466 void set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos);
467 /** Returns the number of constant values needed to initialize the entity.
469 * Asserts if the entity has variability_uninitialized.
471 int get_compound_ent_n_values(ir_entity *ent);
472 /** Returns a constant value given the position. */
473 ir_node *get_compound_ent_value(ir_entity *ent, int pos);
474 /** Returns the access path for value at position pos. */
475 compound_graph_path *get_compound_ent_value_path(ir_entity *ent, int pos);
476 /** Returns a constant value given the access path.
477 * The path must contain array indices for all array element entities. */
478 ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path);
480 /** Removes all constant entries where the path ends at value_ent. Does not
481 free the memory of the paths. (The same path might be used for several
482 constant entities. */
483 void remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent);
485 /* Some languages support only trivial access paths, i.e., the member is a
486 direct, atomic member of the constant entities type. In this case the
487 corresponding entity can be accessed directly. The following functions
488 allow direct access. */
490 /** Generates a Path with length 1.
491 Beware: Has a bad runtime for array elements (O(|array|) and should be
492 avoided there. Use add_compound_ent_value_w_path() instead and create
493 the path manually. */
494 void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member);
496 /** Returns the last member in the path */
497 ir_entity *get_compound_ent_value_member(ir_entity *ent, int pos);
499 /** Sets the path at pos 0 */
500 void set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos);
502 /** Initializes the entity ent which must be of a one dimensional
503 array type with the values given in the values array.
504 The array must have a lower and an upper bound. Keeps the
505 order of values. Does not test whether the number of values
506 fits into the given array size. Does not test whether the
507 values have the proper mode for the array. */
508 void set_array_entity_values(ir_entity *ent, tarval **values, int num_vals);
511 * Return the offset in bits from the last byte address.
513 * This requires that the layout of all concerned types is fixed.
515 * @param ent Any entity of compound type with at least pos initialization values.
516 * @param pos The position of the value for which the offset is requested.
518 int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos);
520 /** Return the overall offset of value at position pos in bytes.
522 * This requires that the layout of all concerned types is fixed.
523 * Asserts if bit offset is not byte aligned.
525 * @param ent Any entity of compound type with at least pos initialization values.
526 * @param pos The position of the value for which the offset is requested.
528 int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos);
530 /* --- Fields of entities with a class type as owner --- */
531 /* Overwrites is a field that specifies that an access to the overwritten
532 entity in the supertype must use this entity. It's a list as with
533 multiple inheritance several entities can be overwritten. This field
534 is mostly useful for method entities.
535 If a Sel node selects an entity that is overwritten by other entities it
536 must return a pointer to the entity of the dynamic type of the pointer
537 that is passed to it. Lowering of the Sel node must assure this.
538 Overwrittenby is the inverse of overwrites. Both add routines add
539 both relations, they only differ in the order of arguments. */
540 void add_entity_overwrites (ir_entity *ent, ir_entity *overwritten);
541 int get_entity_n_overwrites (ir_entity *ent);
542 int get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten);
543 ir_entity *get_entity_overwrites (ir_entity *ent, int pos);
544 void set_entity_overwrites (ir_entity *ent, int pos, ir_entity *overwritten);
545 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
547 void add_entity_overwrittenby (ir_entity *ent, ir_entity *overwrites);
548 int get_entity_n_overwrittenby (ir_entity *ent);
549 int get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites);
550 ir_entity *get_entity_overwrittenby (ir_entity *ent, int pos);
551 void set_entity_overwrittenby (ir_entity *ent, int pos, ir_entity *overwrites);
552 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites);
555 * Checks whether a pointer points to an entity.
557 * @param thing an arbitrary pointer
560 * true if the thing is an entity, else false
562 int is_entity (const void *thing);
564 /** Returns true if the type of the entity is a primitive, pointer
565 * enumeration or method type.
567 * @Note This is a different classification than from is_primitive_type().
569 int is_atomic_entity(ir_entity *ent);
570 /** Returns true if the type of the entity is a class, structure,
571 array or union type. */
572 int is_compound_entity(ir_entity *ent);
573 /** Returns true if the type of the entity is a Method type. */
574 int is_method_entity(ir_entity *ent);
576 /** Returns non-zero if ent1 and ent2 have are equal except for their owner.
577 Two entities are equal if
578 - they have the same type (the same C-struct)
581 int equal_entity(ir_entity *ent1, ir_entity *ent2);
583 /** Outputs a unique number for this entity if libfirm is compiled for
584 * debugging, (configure with --enable-debug) else returns the address
585 * of the type cast to long.
587 long get_entity_nr(const ir_entity *ent);
589 /** Returns the entities visited count. */
590 unsigned long get_entity_visited(ir_entity *ent);
592 /** Sets the entities visited count. */
593 void set_entity_visited(ir_entity *ent, unsigned long num);
595 /** Sets visited field in entity to entity_visited. */
596 void mark_entity_visited(ir_entity *ent);
598 /** Returns true if this entity was visited. */
599 int entity_visited(ir_entity *ent);
601 /** Returns true if this entity was not visited. */
602 int entity_not_visited(ir_entity *ent);
605 * Returns the mask of the additional entity properties.
606 * The properties are automatically inherited from the irg if available
607 * or from the method type if they were not set using
608 * set_entity_additional_properties() or
609 * set_entity_additional_property().
611 unsigned get_entity_additional_properties(ir_entity *ent);
613 /** Sets the mask of the additional graph properties. */
614 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask);
616 /** Sets one additional graph property. */
617 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag);
619 /** Returns the class type that this type info entity represents or NULL
620 if ent is no type info entity. */
621 ir_type *get_entity_repr_class(const ir_entity *ent);
624 * @page unknown_entity The Unknown entity
626 * This entity is an auxiliary entity dedicated to support analyses.
628 * The unknown entity represents that there could be an entity, but it is not
629 * known. This entity can be used to initialize fields before an analysis (not known
630 * yet) or to represent the top of a lattice (could not be determined). There exists
631 * exactly one entity unknown. This entity has as owner and as type the unknown type. It is
632 * allocated when initializing the entity module.
634 * The entity can take the role of any entity, also methods. It returns default
635 * values in these cases.
637 * The following values are set:
639 * - name = "unknown_entity"
640 * - ld_name = "unknown_entity"
641 * - owner = unknown_type
642 * - type = unknown_type
643 * - allocation = allocation_automatic
644 * - visibility = visibility_external_allocated
646 * - variability = variability_uninitialized
647 * - value = SymConst(unknown_entity)
650 * - peculiarity = peculiarity_existent
651 * - volatility = volatility_non_volatile
652 * - stickyness = stickyness_unsticky
654 * - overwrites = NULL
655 * - overwrittenby = NULL
659 /* A variable that contains the only unknown entity. */
660 extern ir_entity *unknown_entity;
662 /** Returns the @link unknown_entity unknown entity @endlink. */
663 ir_entity *get_unknown_entity(void);
665 /** Encodes how a pointer parameter is accessed. */
666 typedef enum acc_bits {
667 ptr_access_none = 0, /**< no access */
668 ptr_access_read = 1, /**< read access */
669 ptr_access_write = 2, /**< write access */
670 ptr_access_rw = ptr_access_read|ptr_access_write, /**< read AND write access */
671 ptr_access_store = 4, /**< the pointer is stored */
672 ptr_access_all = ptr_access_rw|ptr_access_store /**< all possible access */
675 #define IS_READ(a) ((a) & ptr_access_read)
676 #define IS_WRITTEN(a) ((a) & ptr_access_write)
677 #define IS_STORED(a) ((a) & ptr_access_store)
680 * Supported image sections.
681 * Currently only methods can be placed in different sections.
684 section_text, /**< The code segment. This is the default for methods. */
685 section_constructors /**< The constructor section. */
688 /** Returns the section of a method. */
689 ir_img_section get_method_img_section(const ir_entity *method);
691 /** Sets the section of a method. */
692 void set_method_img_section(ir_entity *method, ir_img_section section);
698 * @page tyop type operations
699 * This module specifies the kinds of types available in firm.
701 * They are called type opcodes. These include classes, structs, methods, unions,
702 * arrays, enumerations, pointers and primitive types.
703 * Special types with own opcodes are the id type, a type representing an unknown
704 * type and a type used to specify that something has no type.
710 * An enum for the type kinds.
711 * For each type kind exists a typecode to identify it.
714 tpo_uninitialized = 0, /* not a type opcode */
715 tpo_class, /**< A class type. */
716 tpo_struct, /**< A struct type. */
717 tpo_method, /**< A method type. */
718 tpo_union, /**< An union type. */
719 tpo_array, /**< An array type. */
720 tpo_enumeration, /**< An enumeration type. */
721 tpo_pointer, /**< A pointer type. */
722 tpo_primitive, /**< A primitive type. */
723 tpo_id, /**< Special Id tag used for type replacement. */
724 tpo_none, /**< Special type for the None type. */
725 tpo_unknown, /**< Special code for the Unknown type. */
726 tpo_max /* not a type opcode */
730 * A structure containing information about a kind of type.
731 * A structure containing information about a kind of type. So far
732 * this is only the kind name, an enum for case-switching and some
735 * @see get_tpop_name(), get_tpop_code(), get_tpop_ident()
737 typedef struct tp_op tp_op;
741 * Returns the string for the type opcode.
743 * @param op The type opcode to get the string from.
744 * @return a string. (@todo Null terminated?)
746 const char *get_tpop_name (const tp_op *op);
749 * Returns an enum for the type opcode.
751 * @param op The type opcode to get the enum from.
754 tp_opcode get_tpop_code (const tp_op *op);
757 * Returns the ident for the type opcode.
759 * @param op The type opcode to get the ident from.
762 ident *get_tpop_ident (const tp_op *op);
765 * This type opcode marks that the corresponding type is a class type.
767 * Consequently the type refers to supertypes, subtypes and entities.
768 * Entities can be any fields, but also methods.
769 * @@@ value class or not???
770 * This struct is dynamically allocated but constant for the lifetime
773 extern tp_op *type_class;
774 tp_op *get_tpop_class(void);
777 * This type opcode marks that the corresponding type is a compound type
780 * Consequently the type refers to a list of entities
781 * which may not be methods (but pointers to methods).
782 * This struct is dynamically allocated but constant for the lifetime
785 extern tp_op *type_struct;
786 tp_op *get_tpop_struct(void);
789 * This type opcode marks that the corresponding type is a method type.
791 * Consequently it refers to a list of arguments and results.
792 * This struct is dynamically allocated but constant for the lifetime
795 extern tp_op *type_method;
796 tp_op *get_tpop_method(void);
799 * This type opcode marks that the corresponding type is a union type.
801 * Consequently it refers to a list of unioned types.
802 * This struct is dynamically allocated but constant for the lifetime
805 extern tp_op *type_union;
806 tp_op *get_tpop_union(void);
809 * This type opcode marks that the corresponding type is an array type.
811 * Consequently it contains a list of dimensions (lower and upper bounds)
812 * and an element type.
813 * This struct is dynamically allocated but constant for the lifetime
816 extern tp_op *type_array;
817 tp_op *get_tpop_array(void);
820 * This type opcode marks that the corresponding type is an enumeration type.
822 * Consequently it contains a list of idents for the enumeration identifiers
823 * and a list of target values that are the constants used to implement
825 * This struct is dynamically allocated but constant for the lifetime
828 extern tp_op *type_enumeration;
829 tp_op *get_tpop_enumeration(void);
832 * This type opcode marks that the corresponding type is a pointer type.
834 * It contains a reference to the type the pointer points to.
835 * This struct is dynamically allocated but constant for the lifetime
838 extern tp_op *type_pointer;
839 tp_op *get_tpop_pointer(void);
842 * This type opcode marks that the corresponding type is a primitive type.
844 * Primitive types are types that are directly mapped to target machine
846 * This struct is dynamically allocated but constant for the lifetime
849 extern tp_op *type_primitive;
850 tp_op *get_tpop_primitive(void);
853 * This type opcode is an auxiliary opcode dedicated to support transformations
854 * of the type structure.
856 * If a type is changed to another type with another
857 * opcode the new type will be allocated with new memory. All nodes refering
858 * to the old type need to be changed to refer to the new one. This is simplified
859 * by turning the old type into an id type that merely forwards to the new type
860 * that now replaces the old one.
861 * type_ids should never be visible out of the type module. All access routines
862 * should automatically check for type_id and eventually follow the forward in
863 * type_id. Two types are exchanged by a call to exchange_types.
864 * If a type_id is visible externally report this as bug. If it is assured that
865 * this never happens this extern variable can be moved to tpop_t.h.
866 * This struct is dynamically allocated but constant for the lifetime
869 extern tp_op *type_id;
870 tp_op *get_tpop_id(void);
873 * This type opcode is an auxiliary opcode dedicated to support type analyses.
875 * Types with this opcode represents that there is no type.
876 * The type can be used to initialize fields of the type* that actually can not
877 * contain a type or that are initialized for an analysis. There exists exactly
878 * one type with this opcode.
880 extern tp_op *tpop_none;
881 tp_op *get_tpop_none(void);
884 * This type opcode is an auxiliary opcode dedicated to support type analyses.
886 * Types with this opcode represents that there could be a type, but it is not
887 * known. This type can be used to initialize fields before an analysis (not known
888 * yet) or to represent the top of a lattice (could not be determined). There exists
889 * exactly one type with this opcode.
891 extern tp_op *tpop_unknown;
892 tp_op *get_tpop_unknown(void);
894 /* ----------------------------------------------------------------------- */
895 /* Classify pairs of types/entities in the inheritance relations. */
896 /* ----------------------------------------------------------------------- */
898 /** Returns true if low is subclass of high.
900 * Low is a subclass of high if low == high or if low is a subclass of
901 * a subclass of high. I.e, we search in all subtypes of high for low.
902 * @@@ this can be implemented more efficient if we know the set of all
903 * subclasses of high. */
904 int is_SubClass_of(ir_type *low, ir_type *high);
906 /** Subclass check for pointers to classes.
908 * Dereferences at both types the same amount of pointer types (as
909 * many as possible). If the remaining types are both class types
910 * and subclasses, returns true, else false. Can also be called with
911 * two class types. */
912 int is_SubClass_ptr_of(ir_type *low, ir_type *high);
914 /** Returns true if high is superclass of low.
916 * Low is a subclass of high if low == high or if low is a subclass of
917 * a subclass of high. I.e, we search in all subtypes of high for low.
918 * @@@ this can be implemented more efficient if we know the set of all
919 * subclasses of high. */
920 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
922 /** Superclass check for pointers to classes.
924 * Dereferences at both types the same amount of pointer types (as
925 * many as possible). If the remaining types are both class types
926 * and superclasses, returns true, else false. Can also be called with
927 * two class types. */
928 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
930 /** Returns true if high is (transitive) overwritten by low.
932 * Returns false if high == low. */
933 int is_overwritten_by(ir_entity *high, ir_entity *low);
935 /** Resolve polymorphism in the inheritance relation.
937 * Returns the dynamically referenced entity if the static entity and the
938 * dynamic type are given.
939 * Searches downwards in overwritten tree. */
940 ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity* static_ent);
942 /* ----------------------------------------------------------------------- */
943 /* Resolve implicit inheritance. */
944 /* ----------------------------------------------------------------------- */
946 /** Default name mangling for inherited entities.
948 * Returns an ident that consists of the name of type followed by an
949 * underscore and the name (not ld_name) of the entity. */
950 ident *default_mangle_inherited_name(ir_entity *ent, ir_type *clss);
952 /** Type of argument functions for inheritance resolver.
954 * @param ent The entity in the super type that will be overwritten
955 * by the newly generated entity, for which this name is
957 * @param clss The class type in which the new entity will be placed.
959 typedef ident *mangle_inherited_name_func(ir_entity *ent, ir_type *clss);
961 /** Resolve implicit inheritance.
963 * Resolves the implicit inheritance supplied by firm. Firm defines,
964 * that each entity that is not overwritten in a subclass is
965 * inherited to this subclass without change implicitly. This
966 * function generates entities that explicitly represent this
967 * inheritance. It generates for each entity overwriting entities in
968 * all subclasses of the owner of the entity, if the entity is not
969 * overwritten in that subclass.
971 * The name of the new entity is generated with the function passed.
972 * If the function is NULL, the default_mangle_inherited_name() is
975 * This function was moved here from firmlower 3/2005.
977 void resolve_inheritance(mangle_inherited_name_func *mfunc);
980 /* ----------------------------------------------------------------------- */
981 /* The transitive closure of the subclass/superclass and */
982 /* overwrites/overwrittenby relation. */
984 /* A walk over the ir (O(#types+#entities)) computes the transitive */
985 /* closure. Adding a new type/entity or changing the basic relations in */
986 /* some other way invalidates the transitive closure, i.e., it is not */
987 /* updated by the basic functions. */
989 /* The transitive edges are held in a set, not in an array as the */
990 /* underlying relation. */
992 /* Do the sets contain the node itself? I assume NOT! */
993 /* ----------------------------------------------------------------------- */
995 /** The state of the transitive closure.
997 * @todo: we could manage the state for each relation separately. Invalidating
998 * the entity relations does not mean invalidating the class relation. */
1000 inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */
1001 inh_transitive_closure_valid, /**< Closure computed and valid. */
1002 inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */
1003 inh_transitive_closure_max /**< Invalid value. */
1004 } inh_transitive_closure_state;
1006 void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
1007 void invalidate_irp_inh_transitive_closure_state(void);
1008 inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
1011 /** Compute transitive closure of the subclass/superclass and
1012 * overwrites/overwrittenby relation.
1014 * This function walks over the ir (O(#types+#entities)) to compute the
1015 * transitive closure. */
1016 void compute_inh_transitive_closure(void);
1018 /** Free memory occupied by the transitive closure information. */
1019 void free_inh_transitive_closure(void);
1022 /* - subtype ------------------------------------------------------------- */
1024 /** Iterate over all transitive subtypes. */
1025 ir_type *get_class_trans_subtype_first(ir_type *tp);
1026 ir_type *get_class_trans_subtype_next (ir_type *tp);
1027 int is_class_trans_subtype (ir_type *tp, ir_type *subtp);
1029 /* - supertype ----------------------------------------------------------- */
1031 /** Iterate over all transitive supertypes. */
1032 ir_type *get_class_trans_supertype_first(ir_type *tp);
1033 ir_type *get_class_trans_supertype_next (ir_type *tp);
1035 /* - overwrittenby ------------------------------------------------------- */
1037 /** Iterate over all entities that transitive overwrite this entities. */
1038 ir_entity *get_entity_trans_overwrittenby_first(ir_entity *ent);
1039 ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent);
1041 /* - overwrites ---------------------------------------------------------- */
1043 /** Iterate over all transitive overwritten entities. */
1044 ir_entity *get_entity_trans_overwrites_first(ir_entity *ent);
1045 ir_entity *get_entity_trans_overwrites_next (ir_entity *ent);
1048 /* ----------------------------------------------------------------------- */
1049 /** The state of Cast operations that cast class types or pointers to class
1052 * The state expresses, how far Cast operations conform with the class
1056 * class B1 extends A {}
1057 * class B2 extends A {}
1058 * class C extends B1 {}
1059 * normalized: Cast operations conform with the inheritance relation.
1060 * I.e., the type of the operand of a Cast is either a super= or a sub-
1061 * type of the type casted to. Example: (A)((B2) (new C())).
1062 * transitive: Cast operations conform with the transitive inheritance
1063 * relation. Example: (A)(new C()).
1064 * any: Cast operations do not conform with the transitive inheritance
1065 * relation. Example: (B2)(new B1())
1069 /* ----------------------------------------------------------------------- */
1071 /** Flags for class cast state.
1073 * The state in irp is always smaller or equal to the state of any
1076 * We rely on the ordering of the enum. */
1078 ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with
1079 the class hierarchy. @@@ So far this does not happen in Firm. */
1080 ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */
1081 ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */
1082 ir_class_casts_state_max
1083 } ir_class_cast_state;
1084 char *get_class_cast_state_string(ir_class_cast_state s);
1086 void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s);
1087 ir_class_cast_state get_irg_class_cast_state(ir_graph *irg);
1088 void set_irp_class_cast_state(ir_class_cast_state s);
1089 ir_class_cast_state get_irp_class_cast_state(void);
1091 /** Verify the class cast state of an irg.
1093 * Asserts if state is to high, outputs warning if state is to low
1094 * and firm verbosity is set.
1096 void verify_irg_class_cast_state(ir_graph *irg);
1099 * possible trvrfy() error codes
1101 enum trvrfy_error_codes {
1102 no_error = 0, /**< no error */
1103 error_ent_not_cont, /**< overwritten entity not in superclass */
1104 error_null_mem, /**< compound contains NULL member */
1105 error_const_on_wrong_irg, /**< constant placed on wrong IRG */
1106 error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */
1107 error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */
1108 error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */
1109 error_glob_ent_allocation, /**< wrong allocation of a global entity */
1110 error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */
1111 error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */
1118 * 0 if no error encountered
1120 int check_type(ir_type *tp);
1123 * Check an entity. Currently, we check only if initialized constants
1124 * are build on the const irg graph.
1127 * 0 if no error encountered
1128 * != 0 a trvrfy_error_codes code
1130 int check_entity(ir_entity *ent);
1133 * Walks the type information and performs a set of sanity checks.
1135 * Currently, the following checks are executed:
1136 * - values of initialized entities must be allocated on the constant IRG
1137 * - class types: doesn't have NULL members
1138 * - class types: all overwrites are existent in the super type
1141 * 0 if graph is correct
1147 * If NDEBUG is defined performs nothing, else calls the tr_vrfy() function.
1152 #define TR_VRFY() tr_vrfy()
1158 * This module supplies routines that support changing the type graph.
1161 /** Replaces one type by the other.
1163 * Old type is replaced by new_type. All references to old_type
1164 * now point to new_type. The memory for the old type is destroyed,
1165 * but still used. Therefore it is not freed.
1166 * All referenced to this memory will be lost after a certain while.
1167 * An exception is the list of types in irp (irprog.h).
1168 * In the future there might be a routine to recover the memory, but
1169 * this will be at considerable runtime cost.
1171 * @param old_type - The old type that shall be replaced by the new type.
1172 * @param new_type - The new type that will replace old_type.
1175 void exchange_types(ir_type *old_type, ir_type *new_type);
1177 /** Skip id types until a useful type is reached.
1179 * @param tp - A type of arbitrary kind.
1182 * tp if it is not an id type.
1183 * If tp is an id type returns the real type it stands for.
1185 ir_type *skip_tid(ir_type *tp);
1188 * @page type representation of types
1190 * Datastructure to hold type information.
1192 * This module supplies a datastructure to represent all types
1193 * known in the compiled program. This includes types specified
1194 * in the program as well as types defined by the language. In the
1195 * view of the intermediate representation there is no difference
1196 * between these types. Finally it specifies some auxiliary types.
1198 * There exist several kinds of types, arranged by the structure of
1199 * the type. A type is described by a set of attributes. Some of
1200 * these attributes are common to all types, others depend on the
1203 * Types are different from the modes defined in irmode: Types are
1204 * on the level of the programming language, modes at the level of
1205 * the target processor.
1210 #include "typerep.h"
1212 /** Frees all entities associated with a type.
1213 * Does not free the array entity.
1214 * Warning: ensure these entities are not referenced anywhere else.
1216 void free_type_entities(ir_type *tp);
1218 /** Frees the memory used by the type.
1220 * Removes the type from the type list. Does not free the entities
1221 * belonging to the type, except for the array element entity. Does
1222 * not free if tp is "none" or "unknown". Frees entities in value
1223 * param subtypes of method types!!! Make sure these are not
1224 * referenced any more. Further make sure there is no pointer type
1225 * that refers to this type. */
1226 void free_type(ir_type *tp);
1228 const tp_op*get_type_tpop(const ir_type *tp);
1229 ident* get_type_tpop_nameid(const ir_type *tp);
1230 const char* get_type_tpop_name(const ir_type *tp);
1231 tp_opcode get_type_tpop_code(const ir_type *tp);
1233 ident* get_type_ident(const ir_type *tp);
1234 void set_type_ident(ir_type *tp, ident* id);
1235 const char* get_type_name(const ir_type *tp);
1237 /** The visibility of a type.
1239 * The visibility of a type indicates, whether entities of this type
1240 * are accessed or allocated in external code.
1242 * An entity of a type is allocated in external code, if the external
1243 * code declares a variable of this type, or dynamically allocates
1244 * an entity of this type. If the external code declares a (compound)
1245 * type, that contains entities of this type, the visibility also
1246 * must be external_allocated.
1248 * The visibility must be higher than that of all entities, if the
1249 * type is a compound. Here it is questionable, what happens with
1250 * static entities. If these are accessed external by direct reference,
1251 * (a static call to a method, that is also in the dispatch table)
1252 * it should not affect the visibility of the type.
1255 * @@@ Do we need a visibility for types?
1256 * I change the layout of types radically when doing type splitting.
1257 * I need to know, which fields of classes are accessed in the RTS,
1258 * e.g., [_length. I may not move [_length to the split part.
1259 * The layout though, is a property of the type.
1261 * One could also think of changing the mode of a type ...
1263 * But, we could also output macros to access the fields, e.g.,
1264 * ACCESS_[_length (X) X->length // conventional
1265 * ACCESS_[_length (X) X->_split_ref->length // with type splitting
1267 * For now I implement this function, that returns the visibility
1268 * based on the visibility of the entities of a compound ...
1270 * This function returns visibility_external_visible if one or more
1271 * entities of a compound type have visibility_external_visible.
1272 * Entities of types are never visibility_external_allocated (right?).
1273 * Else returns visibility_local.
1275 ir_visibility get_type_visibility(const ir_type *tp);
1276 void set_type_visibility(ir_type *tp, ir_visibility v);
1280 /** The state of the type layout. */
1282 layout_undefined, /**< The layout of this type is not defined.
1283 Address computation to access fields is not
1284 possible, fields must be accessed by Sel
1285 nodes. Enumeration constants might be undefined.
1286 This is the default value except for
1287 pointer, primitive and method types. */
1288 layout_fixed /**< The layout is fixed, all component/member entities
1289 have an offset assigned. Size of the type is known.
1290 Arrays can be accessed by explicit address
1291 computation. Enumeration constants must be defined.
1292 Default for pointer, primitive and method types. */
1295 /** Returns a human readable string for the enum entry. */
1296 const char *get_type_state_name(type_state s);
1298 /** Returns the type layout state of a type. */
1299 type_state get_type_state(const ir_type *tp);
1301 /** Sets the type layout state of a type.
1303 * For primitives, pointer and method types the layout is always fixed.
1304 * This call is legal but has no effect.
1306 void set_type_state(ir_type *tp, type_state state);
1308 /** Returns the mode of a type.
1310 * Returns NULL for all non atomic types.
1312 ir_mode* get_type_mode(const ir_type *tp);
1314 /** Sets the mode of a type.
1316 * Only has an effect on primitive, enumeration and pointer types.
1318 void set_type_mode(ir_type *tp, ir_mode* m);
1320 /** Returns the size of a type in bytes, returns -1 if the size is NOT
1321 * a byte size, i.e. not dividable by 8. */
1322 int get_type_size_bytes(const ir_type *tp);
1324 /** Returns the size of a type in bits. */
1325 int get_type_size_bits(const ir_type *tp);
1327 /** Sets the size of a type in bytes.
1329 * For primitive, enumeration, pointer and method types the size
1330 * is always fixed. This call is legal but has no effect.
1332 void set_type_size_bytes(ir_type *tp, int size);
1334 /** Sets the size of a type in bits.
1336 * For primitive, enumeration, pointer and method types the size
1337 * is always fixed. This call is legal but has no effect.
1339 void set_type_size_bits(ir_type *tp, int size);
1341 /** Returns the alignment of a type in bytes.
1343 * Returns -1 if the alignment is NOT
1344 * a byte size, i.e. not dividable by 8. Calls get_type_alignment_bits(). */
1345 int get_type_alignment_bytes(ir_type *tp);
1347 /** Returns the alignment of a type in bits.
1349 * If the alignment of a type is
1350 * not set, it is calculated here according to the following rules:
1351 * -#.) if a type has a mode, the alignment is the mode size.
1352 * -#.) compound types have the alignment of there biggest member.
1353 * -#.) array types have the alignment of there element type.
1354 * -#.) method types return 0 here.
1355 * -#.) all other types return 8 here (i.e. aligned at byte).
1357 int get_type_alignment_bits(ir_type *tp);
1359 /** Sets the alignment of a type in bytes. */
1360 void set_type_alignment_bytes(ir_type *tp, int size);
1362 /** Sets the alignment of a type in bits.
1364 * For method types the alignment is always fixed.
1365 * This call is legal but has no effect.
1367 void set_type_alignment_bits(ir_type *tp, int size);
1369 /** Returns the visited count of a type. */
1370 unsigned long get_type_visited(const ir_type *tp);
1371 /** Sets the visited count of a type to num. */
1372 void set_type_visited(ir_type *tp, unsigned long num);
1373 /** Sets visited field in type to type_visited. */
1374 void mark_type_visited(ir_type *tp);
1375 /** Returns non-zero if the type is already visited */
1376 int type_visited(const ir_type *tp);
1377 /** Returns non-zero if the type is not yet visited */
1378 int type_not_visited(const ir_type *tp);
1380 /** Returns the associated link field of a type. */
1381 void* get_type_link(const ir_type *tp);
1382 /** Sets the associated link field of a type. */
1383 void set_type_link(ir_type *tp, void *l);
1386 * Visited flag to traverse the type information.
1388 * Increase this flag by one before traversing the type information
1389 * using inc_master_type_visited().
1390 * Mark type nodes as visited by mark_type_visited(ir_type).
1391 * Check whether node was already visited by type_visited(ir_type)
1392 * and type_not_visited(ir_type).
1393 * Or use the function to walk all types.
1397 void set_master_type_visited(unsigned long val);
1398 unsigned long get_master_type_visited(void);
1399 void inc_master_type_visited(void);
1402 * Sets the debug information of a type.
1404 * @param tp The type.
1405 * @param db The debug info.
1407 void set_type_dbg_info(ir_type *tp, dbg_info *db);
1410 * Returns the debug information of a type.
1412 * @param tp The type.
1414 dbg_info *get_type_dbg_info(const ir_type *tp);
1417 * Checks whether a pointer points to a type.
1419 * @param thing an arbitrary pointer
1422 * true if the thing is a type, else false
1424 int is_type(const void *thing);
1427 * Checks whether two types are structurally equal.
1429 * @param typ1 the first type
1430 * @param typ2 the second type
1433 * true if the types are equal, else false.
1435 * Types are equal if :
1436 * - they are the same type kind
1437 * - they have the same name
1438 * - they have the same mode (if applicable)
1439 * - they have the same type_state and, ev., the same size
1440 * - they are class types and have:
1441 * - the same members (see same_entity in entity.h)
1442 * - the same supertypes -- the C-pointers are compared --> no recursive call.
1443 * - the same number of subtypes. Subtypes are not compared,
1444 * as this could cause a cyclic test.
1445 * - the same peculiarity
1446 * - they are structure types and have the same members
1447 * - they are method types and have
1448 * - the same parameter types
1449 * - the same result types
1450 * - they are union types and have the same members
1451 * - they are array types and have
1452 * - the same number of dimensions
1453 * - the same dimension bounds
1454 * - the same dimension order
1455 * - the same element type
1456 * - they are enumeration types and have the same enumerator names
1457 * - they are pointer types and have the identical points_to type
1458 * (i.e., the same C-struct to represent the type, type_id is skipped.
1459 * This is to avoid endless recursions; with pointer types cyclic
1460 * type graphs are possible.)
1462 int equal_type(ir_type *typ1, ir_type *typ2);
1465 * Checks whether two types are structural comparable.
1467 * @param st pointer type
1468 * @param lt pointer type
1471 * true if type st is smaller than type lt, i.e. whenever
1472 * lt is expected a st can be used.
1474 * - they are the same type kind
1475 * - mode(st) < mode (lt) (if applicable)
1476 * - they are class types and st is (transitive) subtype of lt,
1477 * - they are structure types and
1478 * - the members of st have exactly one counterpart in lt with the same name,
1479 * - the counterpart has a bigger type.
1480 * - they are method types and have
1481 * - the same number of parameter and result types,
1482 * - the parameter types of st are smaller than those of lt,
1483 * - the result types of st are smaller than those of lt
1484 * - they are union types and have the members of st have exactly one
1485 * @return counterpart in lt and the type is smaller
1486 * - they are array types and have
1487 * - the same number of dimensions
1488 * - all bounds of lt are bound of st
1489 * - the same dimension order
1490 * - the same element type
1492 * - the element type of st is smaller than that of lt
1493 * - the element types have the same size and fixed layout.
1494 * - they are enumeration types and have the same enumerator names
1495 * - they are pointer types and have the points_to type of st is
1496 * @return smaller than the points_to type of lt.
1499 int smaller_type(ir_type *st, ir_type *lt);
1502 * @page class_type Representation of a class type
1504 * If the type opcode is set to type_class the type represents class
1505 * types. A list of fields and methods is associated with a class.
1506 * Further a class can inherit from and bequest to other classes.
1508 * The following attributes are private to this type kind:
1509 * - member: All entities belonging to this class. This are method entities
1510 * which have type_method or fields that can have any of the
1511 * following type kinds: type_class, type_struct, type_union,
1512 * type_array, type_enumeration, type_pointer, type_primitive.
1514 * The following two are dynamic lists that can be grown with an "add_" function,
1517 * - subtypes: A list of direct subclasses.
1519 * - supertypes: A list of direct superclasses.
1521 * - peculiarity: The peculiarity of this class. If the class is of peculiarity
1522 * "description" it only is a description of requirements to a class,
1523 * as, e.g., a Java interface. The class will never be allocated.
1524 * Peculiarity inherited is only possible for entities. An entity
1525 * is of peculiarity inherited if the compiler generated the entity
1526 * to explicitly resolve inheritance. An inherited method entity has
1528 * Values: description, existent, inherited. Default: existent.
1530 * - type_info: An entity representing the type information of this class.
1531 * This entity can be of arbitrari type, Firm did not use it yet.
1532 * It allows to express the coupling of a type with an entity
1533 * representing this type. This information is useful for lowering
1534 * of InstOf and TypeChk nodes. Default: NULL
1536 * - vtable_size: The size of this class virtual function table.
1539 * - final: A final class is always a leaf in the class hierarchy. Final
1540 * classes cannot be super classes of other ones. As this information
1541 * can only be computed in whole world compilations, we allow to
1542 * set this flag. It is used in optimizations if get_opt_closed_world()
1543 * is false. Default: false
1545 * - interface: The class represents an interface. This flag can be set to distinguish
1546 * between interfaces, abstract classes and other classes that all may
1547 * have the peculiarity peculiarity_description. Depending on this flag
1548 * the lowering might do different actions. Default: false
1550 * - abstract : The class represents an abstract class. This flag can be set to distinguish
1551 * between interfaces, abstract classes and other classes that all may
1552 * have the peculiarity peculiarity_description. Depending on this flag
1553 * the lowering might do different actions. Default: false
1556 /** Creates a new class type. */
1557 ir_type *new_type_class (ident *name);
1559 /** Creates a new class type with debug information. */
1560 ir_type *new_d_type_class (ident *name, dbg_info *db);
1562 /* --- manipulate private fields of class type --- */
1564 /** Adds the entity as member of the class. */
1565 void add_class_member (ir_type *clss, ir_entity *member);
1567 /** Returns the number of members of this class. */
1568 int get_class_n_members (const ir_type *clss);
1570 /** Returns the member at position pos, 0 <= pos < n_member */
1571 ir_entity *get_class_member (const ir_type *clss, int pos);
1573 /** Returns index of mem in clss, -1 if not contained. */
1574 int get_class_member_index(const ir_type *clss, ir_entity *mem);
1576 /** Finds the member with name 'name'. If several members with the same
1577 * name returns one of them. Returns NULL if no member found. */
1578 ir_entity *get_class_member_by_name(ir_type *clss, ident *name);
1580 /** Overwrites the member at position pos, 0 <= pos < n_member with
1581 * the passed entity. */
1582 void set_class_member (ir_type *clss, ir_entity *member, int pos);
1584 /** Replaces complete member list in class type by the list passed.
1586 * Copies the list passed. This function is necessary to reduce the number of members.
1587 * members is an array of entities, num the size of this array. Sets all
1588 * owners of the members passed to clss. */
1589 void set_class_members (ir_type *clss, ir_entity *members[], int arity);
1591 /** Finds member in the list of members and removes it.
1593 * Shrinks the member list, so iterate from the end!!!
1594 * Does not deallocate the entity. */
1595 void remove_class_member(ir_type *clss, ir_entity *member);
1598 /** Adds subtype as subtype to clss.
1600 * Checks whether clss is a supertype of subtype. If not
1601 * adds also clss as supertype to subtype. */
1602 void add_class_subtype (ir_type *clss, ir_type *subtype);
1604 /** Returns the number of subtypes */
1605 int get_class_n_subtypes (const ir_type *clss);
1607 /** Gets the subtype at position pos, 0 <= pos < n_subtype. */
1608 ir_type *get_class_subtype (ir_type *clss, int pos);
1610 /** Returns the index to access subclass as subtype of class.
1612 * If subclass is no direct subtype of class returns -1.
1614 int get_class_subtype_index(ir_type *clss, const ir_type *subclass);
1616 /** Sets the subtype at position pos, 0 <= pos < n_subtype.
1618 * Does not set the corresponding supertype relation for subtype: this might
1619 * be a different position! */
1620 void set_class_subtype (ir_type *clss, ir_type *subtype, int pos);
1622 /** Finds subtype in the list of subtypes and removes it */
1623 void remove_class_subtype(ir_type *clss, ir_type *subtype);
1625 /* Convenience macros */
1626 #define add_class_derived_type(clss, drvtype) add_class_subtype(clss, drvtype)
1627 #define get_class_n_derived_types(clss) get_class_n_subtypes(clss)
1628 #define get_class_derived_type(clss, pos) get_class_subtype(clss, pos)
1629 #define get_class_derived_type_index(clss, drvtype) get_class_subtype_index(clss, drvtype)
1630 #define set_class_derived_type(clss, drvtype, pos) set_class_subtype(clss, drvtype, pos)
1631 #define remove_class_derived_type(clss, drvtype) remove_class_subtype(clss, drvtype)
1633 /** Adds supertype as supertype to class.
1635 * Checks whether clss is a subtype of supertype. If not
1636 * adds also clss as subtype to supertype. */
1637 void add_class_supertype (ir_type *clss, ir_type *supertype);
1639 /** Returns the number of supertypes */
1640 int get_class_n_supertypes (const ir_type *clss);
1642 /** Returns the index to access superclass as supertype of class.
1644 * If superclass is no direct supertype of class returns -1.
1646 int get_class_supertype_index(ir_type *clss, ir_type *super_clss);
1648 /** Gets the supertype at position pos, 0 <= pos < n_supertype. */
1649 ir_type *get_class_supertype (ir_type *clss, int pos);
1651 /** Sets the supertype at position pos, 0 <= pos < n_supertype.
1653 * Does not set the corresponding subtype relation for supertype: this might
1654 * be at a different position! */
1655 void set_class_supertype (ir_type *clss, ir_type *supertype, int pos);
1657 /** Finds supertype in the list of supertypes and removes it */
1658 void remove_class_supertype(ir_type *clss, ir_type *supertype);
1660 /** Convenience macro */
1661 #define add_class_base_type(clss, basetype) add_class_supertype(clss, basetype)
1662 #define get_class_n_base_types(clss) get_class_n_supertypes(clss)
1663 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
1664 #define get_class_base_type(clss, pos) get_class_supertype(clss, pos)
1665 #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos)
1666 #define remove_class_base_type(clss, basetype) remove_class_supertype(clss, basetype)
1668 /** Convenience macro */
1669 #define add_class_base_type(clss, basetype) add_class_supertype(clss, basetype)
1670 #define get_class_n_base_types(clss) get_class_n_supertypes(clss)
1671 #define get_class_base_type_index(clss, base_clss) get_class_supertype_index(clss, base_clss)
1672 #define get_class_base_type(clss, pos) get_class_supertype(clss, pos)
1673 #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos)
1674 #define remove_class_base_type(clss, basetype) remove_class_supertype(clss, basetype)
1676 /** Returns a human readable string for a peculiarity. */
1677 const char *get_peculiarity_name(ir_peculiarity p);
1679 /** Returns the peculiarity of the class. */
1680 ir_peculiarity get_class_peculiarity (const ir_type *clss);
1681 /** Sets the peculiarity of the class. */
1682 void set_class_peculiarity (ir_type *clss, ir_peculiarity pec);
1684 /** Returns the type info entity of a class. */
1685 ir_entity *get_class_type_info(const ir_type *clss);
1687 /** Set a type info entity for the class. */
1688 void set_class_type_info(ir_type *clss, ir_entity *ent);
1690 /** Returns the size of the virtual function table. */
1691 unsigned get_class_vtable_size(const ir_type *clss);
1693 /** Sets a new size of the virtual function table. */
1694 void set_class_vtable_size(ir_type *clss, unsigned size);
1696 /** Returns non-zero if a class is final. */
1697 int is_class_final(const ir_type *clss);
1699 /** Sets the class final flag. */
1700 void set_class_final(ir_type *clss, int flag);
1702 /** Return non-zero if a class is an interface */
1703 int is_class_interface(const ir_type *clss);
1705 /** Sets the class interface flag. */
1706 void set_class_interface(ir_type *clss, int flag);
1708 /** Return non-zero if a class is an abstract class. */
1709 int is_class_abstract(const ir_type *clss);
1711 /** Sets the class abstract flag. */
1712 void set_class_abstract(ir_type *clss, int flag);
1714 /** Set and get a class' dfn --
1715 @todo This is an undocumented field, subject to change! */
1716 void set_class_dfn (ir_type *clss, int dfn);
1717 int get_class_dfn (const ir_type *clss);
1719 /** Returns true if a type is a class type. */
1720 int is_Class_type(const ir_type *clss);
1723 * @page struct_type Representation of a struct type
1725 * A struct type represents aggregate types that consist of a list
1728 * The following attributes are private to this type kind:
1729 * - member: All entities belonging to this class. This are the fields
1730 * that can have any of the following types: type_class,
1731 * type_struct, type_union, type_array, type_enumeration,
1732 * type_pointer, type_primitive.
1733 * This is a dynamic list that can be grown with an "add_" function,
1735 * This is a dynamic list that can be grown with an "add_" function,
1738 /** Creates a new type struct */
1739 ir_type *new_type_struct (ident *name);
1740 /** Creates a new type struct with debug information. */
1741 ir_type *new_d_type_struct (ident *name, dbg_info* db);
1743 /* --- manipulate private fields of struct --- */
1745 /** Adds the entity as member of the struct. */
1746 void add_struct_member (ir_type *strct, ir_entity *member);
1748 /** Returns the number of members of this struct. */
1749 int get_struct_n_members (const ir_type *strct);
1751 /** Returns the member at position pos, 0 <= pos < n_member */
1752 ir_entity *get_struct_member (const ir_type *strct, int pos);
1754 /** Returns index of member in strct, -1 if not contained. */
1755 int get_struct_member_index(const ir_type *strct, ir_entity *member);
1757 /** Overwrites the member at position pos, 0 <= pos < n_member with
1758 the passed entity. */
1759 void set_struct_member (ir_type *strct, int pos, ir_entity *member);
1761 /** Finds member in the list of members and removes it. */
1762 void remove_struct_member (ir_type *strct, ir_entity *member);
1764 /** Returns true if a type is a struct type. */
1765 int is_Struct_type(const ir_type *strct);
1768 * @page method_type Representation of a method type
1770 * A method type represents a method, function or procedure type.
1771 * It contains a list of the parameter and result types, as these
1772 * are part of the type description. These lists should not
1773 * be changed by a optimization, as a change creates a new method
1774 * type. Therefore optimizations should allocated new method types.
1775 * The set_ routines are only for construction by a frontend.
1777 * - n_params: Number of parameters to the procedure.
1778 * A procedure in FIRM has only call by value parameters.
1780 * - param_type: A list with the types of parameters. This list is ordered.
1781 * The nth type in this list corresponds to the nth element
1782 * in the parameter tuple that is a result of the start node.
1783 * (See ircons.h for more information.)
1785 * - value_param_ents
1786 * A list of entities (whose owner is a struct private to the
1787 * method type) that represent parameters passed by value.
1789 * - n_res: The number of results of the method. In general, procedures
1790 * have zero results, functions one.
1792 * - res_type: A list with the types of parameters. This list is ordered.
1793 * The nth type in this list corresponds to the nth input to
1794 * Return nodes. (See ircons.h for more information.)
1797 * A list of entities (whose owner is a struct private to the
1798 * method type) that represent results passed by value.
1801 /* These macros define the suffixes for the types and entities used
1802 to represent value parameters / results. */
1803 #define VALUE_PARAMS_SUFFIX "val_param"
1804 #define VALUE_RESS_SUFFIX "val_res"
1806 /** Create a new method type.
1808 * @param name the name (ident) of this type
1809 * @param n_param the number of parameters
1810 * @param n_res the number of results
1812 * The arrays for the parameter and result types are not initialized by
1815 ir_type *new_type_method (ident *name, int n_param, int n_res);
1817 /** Create a new method type with debug information.
1819 * @param name the name (ident) of this type
1820 * @param n_param the number of parameters
1821 * @param n_res the number of results
1822 * @param db user defined debug information
1824 * The arrays for the parameter and result types are not initialized by
1827 ir_type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db);
1829 /* -- manipulate private fields of method. -- */
1831 /** Returns the number of parameters of this method. */
1832 int get_method_n_params (const ir_type *method);
1834 /** Returns the type of the parameter at position pos of a method. */
1835 ir_type *get_method_param_type(ir_type *method, int pos);
1836 /** Sets the type of the parameter at position pos of a method.
1837 Also changes the type in the pass-by-value representation by just
1838 changing the type of the corresponding entity if the representation is constructed. */
1839 void set_method_param_type(ir_type *method, int pos, ir_type *tp);
1840 /** Returns an entity that represents the copied value argument. Only necessary
1841 for compounds passed by value. This information is constructed only on demand. */
1842 ir_entity *get_method_value_param_ent(ir_type *method, int pos);
1844 * Returns a type that represents the copied value arguments if one
1845 * was allocated, else NULL.
1847 ir_type *get_method_value_param_type(const ir_type *method);
1848 /** Returns an ident representing the parameters name. Returns NULL if not set.
1849 For debug support only. */
1850 ident *get_method_param_ident(ir_type *method, int pos);
1851 /** Returns a string representing the parameters name. Returns NULL if not set.
1852 For debug support only. */
1853 const char *get_method_param_name(ir_type *method, int pos);
1854 /** Sets an ident representing the parameters name. For debug support only. */
1855 void set_method_param_ident(ir_type *method, int pos, ident *id);
1857 /** Returns the number of results of a method type. */
1858 int get_method_n_ress (const ir_type *method);
1859 /** Returns the return type of a method type at position pos. */
1860 ir_type *get_method_res_type(ir_type *method, int pos);
1861 /** Sets the type of the result at position pos of a method.
1862 Also changes the type in the pass-by-value representation by just
1863 changing the type of the corresponding entity if the representation is constructed. */
1864 void set_method_res_type(ir_type *method, int pos, ir_type *tp);
1865 /** Returns an entity that represents the copied value result. Only necessary
1866 for compounds passed by value. This information is constructed only on demand. */
1867 ir_entity *get_method_value_res_ent(ir_type *method, int pos);
1870 * Returns a type that represents the copied value results.
1872 ir_type *get_method_value_res_type(const ir_type *method);
1875 * This enum flags the variadicity of methods (methods with a
1876 * variable amount of arguments (e.g. C's printf). Default is
1879 typedef enum variadicity {
1880 variadicity_non_variadic, /**< non variadic */
1881 variadicity_variadic /**< variadic */
1884 /** Returns the null-terminated name of this variadicity. */
1885 const char *get_variadicity_name(variadicity vari);
1887 /** Returns the variadicity of a method. */
1888 variadicity get_method_variadicity(const ir_type *method);
1890 /** Sets the variadicity of a method. */
1891 void set_method_variadicity(ir_type *method, variadicity vari);
1894 * Returns the first variadic parameter index of a type.
1895 * If this index was NOT set, the index of the last parameter
1896 * of the method type plus one is returned for variadic functions.
1897 * Non-variadic function types always return -1 here.
1899 int get_method_first_variadic_param_index(const ir_type *method);
1902 * Sets the first variadic parameter index. This allows to specify
1903 * a complete call type (containing the type of all parameters)
1904 * but still have the knowledge, which parameter must be passed as
1907 void set_method_first_variadic_param_index(ir_type *method, int index);
1909 /** Returns the mask of the additional graph properties. */
1910 unsigned get_method_additional_properties(const ir_type *method);
1912 /** Sets the mask of the additional graph properties. */
1913 void set_method_additional_properties(ir_type *method, unsigned property_mask);
1915 /** Sets one additional graph property. */
1916 void set_method_additional_property(ir_type *method, mtp_additional_property flag);
1919 * Calling conventions: lower 24 bits are the number of register parameters,
1920 * upper 8 encode the calling conventions.
1923 cc_reg_param = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
1924 This flag may be set as default on some architectures. */
1925 cc_last_on_top = 0x02000000, /**< The last non-register parameter is transmitted on top of
1926 the stack. This is equivalent to the pascal
1927 calling convention. If this flag is not set, the first
1928 non-register parameter is used (stdcall or cdecl
1929 calling convention) */
1930 cc_callee_clear_stk = 0x04000000, /**< The callee clears the stack. This forbids variadic
1931 function calls (stdcall). */
1932 cc_this_call = 0x08000000, /**< The first parameter is a this pointer and is transmitted
1933 in a special way. */
1935 cc_bits = (0xFF << 24) /**< the calling convention bits */
1936 } calling_convention;
1938 /* some often used cases: made as defines because firmjni cannot handle two
1939 equal enum values. */
1941 /** cdecl calling convention */
1942 #define cc_cdecl_set (0)
1943 /** stdcall calling convention */
1944 #define cc_stdcall_set cc_callee_clear_stk
1945 /** fastcall calling convention */
1946 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
1948 /** Returns the default calling convention for method types. */
1949 unsigned get_default_cc_mask(void);
1952 * check for the CDECL calling convention
1954 #define IS_CDECL(cc_mask) (((cc_mask) & cc_bits) == cc_cdecl_set)
1957 * check for the STDCALL calling convention
1959 #define IS_STDCALL(cc_mask) (((cc_mask) & cc_bits) == cc_stdcall_set)
1962 * check for the FASTCALL calling convention
1964 #define IS_FASTCALL(cc_mask) (((cc_mask) & cc_bits) == cc_fastcall_set)
1967 * Sets the CDECL convention bits.
1969 #define SET_CDECL(cc_mask) (((cc_mask) & ~cc_bits) | cc_cdecl_set)
1972 * Set. the STDCALL convention bits.
1974 #define SET_STDCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_stdcall_set)
1977 * Sets the FASTCALL convention bits.
1979 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
1981 /** Returns the calling convention of an entities graph. */
1982 unsigned get_method_calling_convention(const ir_type *method);
1984 /** Sets the calling convention of an entities graph. */
1985 void set_method_calling_convention(ir_type *method, unsigned cc_mask);
1987 /** Returns the number of registers parameters, 0 means default. */
1988 unsigned get_method_n_regparams(ir_type *method);
1990 /** Sets the number of registers parameters, 0 means default. */
1991 void set_method_n_regparams(ir_type *method, unsigned n_regs);
1993 /** Returns true if a type is a method type. */
1994 int is_Method_type (const ir_type *method);
1997 * @page union_type Representation of a union (variant) type.
1999 * The union type represents union types. Note that this representation
2000 * resembles the C union type. For tagged variant types like in Pascal or Modula
2001 * a combination of a struct and a union type must be used.
2003 * - n_types: Number of unioned types.
2004 * - members: Entities for unioned types. Fixed length array.
2005 * This is a dynamic list that can be grown with an "add_" function,
2008 /** Creates a new type union. */
2009 ir_type *new_type_union (ident *name);
2011 /** Creates a new type union with debug information. */
2012 ir_type *new_d_type_union (ident *name, dbg_info* db);
2014 /* --- manipulate private fields of struct --- */
2016 /** Returns the number of unioned types of this union */
2017 int get_union_n_members (const ir_type *uni);
2019 /** Adds a new entity to a union type */
2020 void add_union_member (ir_type *uni, ir_entity *member);
2022 /** Returns the entity at position pos of a union */
2023 ir_entity *get_union_member (const ir_type *uni, int pos);
2025 /** Returns index of member in uni, -1 if not contained. */
2026 int get_union_member_index(const ir_type *uni, ir_entity *member);
2028 /** Overwrites a entity at position pos in a union type. */
2029 void set_union_member (ir_type *uni, int pos, ir_entity *member);
2031 /** Finds member in the list of members and removes it. */
2032 void remove_union_member (ir_type *uni, ir_entity *member);
2034 /** Returns true if a type is a union type. */
2035 int is_Union_type (const ir_type *uni);
2038 * @page array_type Representation of an array type
2040 * The array type represents rectangular multi dimensional arrays.
2041 * The constants representing the bounds must be allocated to
2042 * get_const_code_irg() by setting current_ir_graph accordingly.
2044 * - n_dimensions: Number of array dimensions.
2045 * - *lower_bound: Lower bounds of dimensions. Usually all 0.
2046 * - *upper_bound: Upper bounds or dimensions.
2047 * - *element_type: The type of the array elements.
2048 * - *element_ent: An entity for the array elements to be used for
2049 * element selection with Sel.
2051 * Do we need several entities? One might want
2052 * to select a dimension and not a single element in case of multi
2053 * dimensional arrays.
2056 /** Create a new type array.
2058 * Sets n_dimension to dimension and all dimension entries to NULL.
2059 * Initializes order to the order of the dimensions.
2060 * The entity for array elements is built automatically.
2061 * Set dimension sizes after call to constructor with set_* routines.
2063 ir_type *new_type_array (ident *name, int n_dimensions,
2064 ir_type *element_type);
2066 /** Create a new type array with debug information.
2068 * Sets n_dimension to dimension and all dimension entries to NULL.
2069 * Initializes order to the order of the dimensions.
2070 * The entity for array elements is built automatically.
2071 * Set dimension sizes after call to constructor with set_* routines.
2072 * A legal array type must have at least one dimension set.
2074 ir_type *new_d_type_array (ident *name, int n_dimensions,
2075 ir_type *element_type, dbg_info* db);
2077 /* --- manipulate private fields of array type --- */
2079 /** Returns the number of array dimensions of this type. */
2080 int get_array_n_dimensions (const ir_type *array);
2083 * Allocates Const nodes of mode_Is for one array dimension.
2084 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
2086 void set_array_bounds_int (ir_type *array, int dimension, int lower_bound,
2089 * Sets the bounds for one array dimension.
2090 * Upper bound in Firm is the element next to the last, i.e. [lower,upper[
2092 void set_array_bounds (ir_type *array, int dimension, ir_node *lower_bound,
2093 ir_node *upper_bound);
2094 /** Sets the lower bound for one array dimension, i.e. [lower,upper[ */
2095 void set_array_lower_bound (ir_type *array, int dimension, ir_node *lower_bound);
2097 /** Allocates Const nodes of mode_Is for the lower bound of an array
2098 dimension, i.e. [lower,upper[ */
2099 void set_array_lower_bound_int (ir_type *array, int dimension, int lower_bound);
2101 /** Sets the upper bound for one array dimension, i.e. [lower,upper[ */
2102 void set_array_upper_bound (ir_type *array, int dimension, ir_node *upper_bound);
2104 /** Allocates Const nodes of mode_Is for the upper bound of an array
2105 dimension, i.e. [lower,upper[. */
2106 void set_array_upper_bound_int (ir_type *array, int dimension, int upper_bound);
2108 /** Returns true if lower bound != Unknown. */
2109 int has_array_lower_bound (const ir_type *array, int dimension);
2110 /** Returns the lower bound of an array. */
2111 ir_node * get_array_lower_bound (const ir_type *array, int dimension);
2112 /** Works only if bound is Const node with tarval that can be converted to long. */
2113 long get_array_lower_bound_int (const ir_type *array, int dimension);
2114 /** returns true if lower bound != Unknown */
2115 int has_array_upper_bound (const ir_type *array, int dimension);
2116 /** Returns the upper bound of an array. */
2117 ir_node * get_array_upper_bound (const ir_type *array, int dimension);
2118 /** Works only if bound is Const node with tarval that can be converted to long. */
2119 long get_array_upper_bound_int (const ir_type *array, int dimension);
2121 /** Sets an array dimension to a specific order. */
2122 void set_array_order (ir_type *array, int dimension, int order);
2124 /** Returns the order of an array dimension. */
2125 int get_array_order (const ir_type *array, int dimension);
2127 /** Find the array dimension that is placed at order order. */
2128 int find_array_dimension(const ir_type *array, int order);
2130 /** Sets the array element type. */
2131 void set_array_element_type (ir_type *array, ir_type* tp);
2133 /** Gets the array element type. */
2134 ir_type *get_array_element_type (ir_type *array);
2136 /** Sets the array element entity. */
2137 void set_array_element_entity (ir_type *array, ir_entity *ent);
2139 /** Get the array element entity. */
2140 ir_entity *get_array_element_entity (const ir_type *array);
2142 /** Returns true if a type is an array type. */
2143 int is_Array_type(const ir_type *array);
2146 * @page enumeration_type Representation of an enumeration type
2148 * Enumeration types need not necessarily be represented explicitly
2149 * by Firm types, as the frontend can lower them to integer constants as
2150 * well. For debugging purposes or similar tasks this information is useful.
2151 * The type state layout_fixed is set, if all enumeration constant have
2152 * there tarvals assigned. Until then
2154 * - *const: The target values representing the constants used to
2155 * represent individual enumerations.
2158 /** Create a new type enumeration -- set the enumerators independently. */
2159 ir_type *new_type_enumeration(ident *name, int n_enums);
2161 /** Create a new type enumeration with debug information -- set the enumerators independently. */
2162 ir_type *new_d_type_enumeration(ident *name, int n_enums, dbg_info *db);
2164 /* --- manipulate fields of enumeration type. --- */
2166 /** Set an enumeration constant to a enumeration type at a given position. */
2167 void set_enumeration_const(ir_type *enumeration, int pos, ident *nameid, tarval *con);
2169 /** Returns the number of enumeration values of this enumeration */
2170 int get_enumeration_n_enums(const ir_type *enumeration);
2172 /** Returns the enumeration constant at a given position. */
2173 ir_enum_const *get_enumeration_const(const ir_type *enumeration, int pos);
2175 /** Returns the enumeration type owner of an enumeration constant. */
2176 ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst);
2178 /** Sets the enumeration constant value. */
2179 void set_enumeration_value(ir_enum_const *enum_cnst, tarval *con);
2181 /** Returns the enumeration constant value. */
2182 tarval *get_enumeration_value(const ir_enum_const *enum_cnst);
2184 /** Assign an ident to an enumeration constant. */
2185 void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
2187 /** Returns the assigned ident of an enumeration constant. */
2188 ident *get_enumeration_nameid(const ir_enum_const *enum_cnst);
2190 /** Returns the assigned name of an enumeration constant. */
2191 const char *get_enumeration_name(const ir_enum_const *enum_cnst);
2193 /** Returns true if a type is a enumeration type. */
2194 int is_Enumeration_type(const ir_type *enumeration);
2197 * @page pointer_type Representation of a pointer type
2199 * The mode of the pointer type must be a reference mode.
2202 * - points_to: The type of the entity this pointer points to.
2205 /** Creates a new type pointer. */
2206 ir_type *new_type_pointer (ident *name, ir_type *points_to, ir_mode *ptr_mode);
2208 /** Creates a new type pointer with debug information. */
2209 ir_type *new_d_type_pointer (ident *name, ir_type *points_to, ir_mode *ptr_mode, dbg_info* db);
2211 /* --- manipulate fields of type_pointer --- */
2213 /** Sets the type to which a pointer points to. */
2214 void set_pointer_points_to_type (ir_type *pointer, ir_type *tp);
2216 /** Returns the type to which a pointer points to. */
2217 ir_type *get_pointer_points_to_type (ir_type *pointer);
2219 /** Returns true if a type is a pointer type. */
2220 int is_Pointer_type (const ir_type *pointer);
2222 /** Returns the first pointer type that has as points_to tp.
2223 * Not efficient: O(#types).
2224 * If not found returns firm_unknown_type. */
2225 ir_type *find_pointer_type_to_type (ir_type *tp);
2228 * @page primitive_type Representation of a primitive type
2230 * Primitive types are types that represent atomic data values that
2231 * map directly to modes. They don't have private attributes. The
2232 * important information they carry is held in the common mode field.
2234 /** Creates a new primitive type. */
2235 ir_type *new_type_primitive(ident *name, ir_mode *mode);
2237 /** Creates a new primitive type with debug information. */
2238 ir_type *new_d_type_primitive(ident *name, ir_mode *mode, dbg_info* db);
2240 /** Returns true if a type is a primitive type. */
2241 int is_Primitive_type(const ir_type *primitive);
2245 * @page none_type The None type
2247 * This type is an auxiliary type dedicated to support type analyses.
2249 * The none type represents that there is no type. The type can be used to
2250 * initialize fields of type* that actually can not contain a type or that
2251 * are initialized for an analysis. There exists exactly one type none.
2252 * This type is not on the type list in ir_prog. It is
2253 * allocated when initializing the type module.
2255 * The following values are set:
2257 * - name: "type_none"
2258 * - state: layout_fixed
2261 /** A variable that contains the only none type. */
2262 extern ir_type *firm_none_type;
2264 /** Returns the none type. */
2265 ir_type *get_none_type(void);
2268 * @page unknown_type The Unknown type
2270 * This type is an auxiliary type dedicated to support type analyses.
2272 * The unknown type represents that there could be a type, but it is not
2273 * known. This type can be used to initialize fields before an analysis (not known
2274 * yet) or to represent the top of a lattice (could not be determined). There exists
2275 * exactly one type unknown. This type is not on the type list in ir_prog. It is
2276 * allocated when initializing the type module.
2278 * The following values are set:
2280 * - name: "type_unknown"
2281 * - state: layout_fixed
2284 /** A variable that contains the only unknown type. */
2285 extern ir_type *firm_unknown_type;
2287 /** Returns the unknown type. */
2288 ir_type *get_unknown_type(void);
2292 * Checks whether a type is atomic.
2293 * @param tp any type
2294 * @return true if type is primitive, pointer or enumeration
2296 int is_atomic_type(const ir_type *tp);
2298 /* --- Support for compound types --- */
2301 * Gets the number of elements in a Firm compound type.
2303 * This is just a comfortability function, because structs and
2304 * classes can often be treated be the same code, but they have
2305 * different access functions to their members.
2307 * @param tp The type (must be struct, union or class).
2309 * @return Number of members in the compound type.
2311 int get_compound_n_members(const ir_type *tp);
2314 * Gets the member of a Firm compound type at position pos.
2316 * @param tp The type (must be struct, union or class).
2317 * @param pos The number of the member.
2319 * @return The member entity at position pos.
2321 * @see get_compound_n_members() for justification of existence.
2323 ir_entity *get_compound_member(const ir_type *tp, int pos);
2325 /** Returns index of member in tp, -1 if not contained. */
2326 int get_compound_member_index(const ir_type *tp, ir_entity *member);
2329 * Checks whether a type is a compound type.
2331 * @param tp - any type
2333 * @return true if the type is class, structure, union or array type.
2335 int is_compound_type(const ir_type *tp);
2338 * Checks, whether a type is a frame type.
2340 int is_frame_type(const ir_type *tp);
2343 * Checks, whether a type is a value parameter type.
2345 int is_value_param_type(const ir_type *tp);
2348 * Checks, whether a type is a lowered type.
2350 int is_lowered_type(const ir_type *tp);
2353 * Makes a new frame type. Frame types are class types,
2354 * so all class access functions work.
2355 * Frame types are not in the global list of types.
2357 ir_type *new_type_frame(ident *name);
2360 * Sets a lowered type for a type. This sets both associations
2361 * and marks lowered_type as a "lowered" one.
2363 void set_lowered_type(ir_type *tp, ir_type *lowered_type);
2366 * Gets the lowered/unlowered type of a type or NULL if this type
2367 * has no lowered/unlowered one.
2369 ir_type *get_associated_type(const ir_type *tp);
2372 * Allocate an area of size bytes aligned at alignment
2373 * at the start or the end of a frame type.
2374 * The frame type must already have a fixed layout.
2376 * @param frame_type a frame type
2377 * @param size the size of the entity
2378 * @param alignment the alignment of the entity
2379 * @param at_start if true, put the area at the frame type's start, else at end
2381 * @return the entity representing the area
2383 ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at_start);
2385 /*-----------------------------------------------------------------*/
2387 /*-----------------------------------------------------------------*/
2390 * Outputs a unique number for this type if libfirm is compiled for
2391 * debugging, (configure with --enable-debug) else returns the address
2392 * of the type cast to long.
2394 long get_type_nr(const ir_type *tp);
2396 /* ------------------------------------------------------------------------ */
2398 /** Type for a function that compares two types.
2400 * @param tp1 The first type to compare.
2401 * @param tp2 The second type to compare.
2403 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
2405 /** Compares two types by their name.
2407 * Compares the opcode and the name of the types. If these are
2408 * equal returns 0, else non-zero.
2410 int compare_names (const void *tp1, const void *tp2);
2412 /** Compares two types strict.
2414 * returns 0 if tp1 == tp2, else non-zero
2416 int compare_strict (const void *tp1, const void *tp2);
2418 /* ------------------------------------------------------------------------ */
2420 /** Type for a function that computes a hash value for a type.
2422 * @param tp The type to compute a hash for.
2424 typedef int (hash_types_func_t)(ir_type *tp);
2426 /** Computes a hash value by the type name.
2428 * Uses the name of the type and the type opcode to compute the hash.
2430 int firm_hash_name (ir_type *tp);
2432 /* ------------------------------------------------------------------------ */
2434 /** Finalize type construction.
2436 * Indicate that a type is so far completed that it can be
2437 * distinguished from other types. Mature_type hashes the type into a
2438 * table. It uses the function in compare_types_func to compare the
2441 * If it finds a type identical to tp it returns this type. It turns
2442 * tp into the Id type. All places formerly pointing to tp will now
2443 * point to the found type. All entities of tp now refer to the found
2444 * type as their owner, but they are not a member of this type. This
2445 * is invalid firm -- the entities must be replaced by entities of the
2446 * found type. The Id type will be removed from the representation
2447 * automatically, but within an unknown time span. It occupies memory
2450 * @param tp The type to mature.
2452 ir_type * mature_type(ir_type *tp);
2454 /** Finalize type construction.
2456 * Indicate that a type is so far completed that it can be
2457 * distinguished from other types. Mature_type hashes the type into a
2458 * table. It uses the function in compare_types_func to compare the
2461 * If it finds a type identical to tp it returns this type. It frees
2462 * type tp and all its entities.
2464 * @param tp The type to mature.
2466 ir_type * mature_type_free(ir_type *tp);
2468 /** Finalize type construction.
2470 * Indicate that a type is so far completed that it can be
2471 * distinguished from other types. Mature_type hashes the type into a
2472 * table. It uses the function in compare_types_func to compare the
2475 * If it find a type identical to tp it returns this type. It frees
2476 * the entities and turns the type into an Id type. All places
2477 * formerly pointing to tp will now point to the found type. The Id
2478 * type will be removed from the representation automatically, but
2479 * within an unknown time span. It occupies memory for this time.
2481 * @param tp The type to mature.
2483 ir_type * mature_type_free_entities(ir_type *tp);
2486 * The interface type for the type identify module;
2488 typedef struct _type_identify_if_t {
2489 compare_types_func_t *cmp; /**< The function that should be used to compare two types.
2490 If NULL, compare_strict() will be used. */
2491 hash_types_func_t *hash; /**< The function that should be used to calculate a hash
2492 value of a type. If NULL, hash_name() will be used. */
2493 } type_identify_if_t;
2496 * Initialise the type identifier module.
2498 * @param ti_if The interface functions for this module.
2500 * If the parameter ti_if is NULL, the default functions compare_strict() and
2501 * firm_hash_name() will be used.
2503 void init_type_identify(type_identify_if_t *ti_if);
2505 /** A data type to treat types and entities as the same. */
2507 ir_type *typ; /**< points to a type */
2508 ir_entity *ent; /**< points to an entity */
2511 /** Type of argument functions for type walkers.
2513 * @param tore points to the visited type or entity
2514 * @param env free environment pointer
2516 typedef void type_walk_func(type_or_ent *tore, void *env);
2518 /** The class walk function
2520 * @param clss points to the visited class
2521 * @param env free environment pointer
2523 typedef void class_walk_func(ir_type *clss, void *env);
2525 /** Touches every type and entity in unspecified order. If new
2526 * types/entities are created during the traversal these will
2528 * Does not touch frame types or types for value params ... */
2529 void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
2531 /** Walks over all type information reachable from an ir graph.
2533 * Walks over all type information reachable from irg, i.e., starts a
2534 * type walk at the irgs entity, the irgs frame type and all types and
2535 * entities that are attributes to firm nodes. */
2536 void type_walk_irg(ir_graph *irg, type_walk_func *pre, type_walk_func *post,
2540 Touches every class in specified order:
2541 - first the super class
2542 - second the class itself
2543 - third the sub classes. If new classes are created
2544 during the traversal these will be visited, too.
2546 @todo should be named class-walk
2548 @deprecated will be removed?
2550 void type_walk_super2sub(type_walk_func *pre, type_walk_func *post, void *env);
2552 /** Walker for class types in inheritance order.
2554 * Touches every class in specified order:
2555 * - first the super class
2556 * - second the class itself
2557 * If new classes are created during the traversal these
2558 * will be visited, too.
2559 * Starts the walk at arbitrary classes.
2560 * Executes pre when first visiting a class. Executes post after
2561 * visiting all superclasses.
2563 * The arguments pre, post, env may be NULL. */
2564 void type_walk_super(type_walk_func *pre, type_walk_func *post, void *env);
2566 /** Same as type_walk_super2sub, but visits only class types.
2567 Executes pre for a class if all superclasses have been visited.
2568 Then iterates to subclasses. Executes post after return from
2570 Does not visit global type, frame types.
2572 @bug ?? something is wrong with this.
2574 void class_walk_super2sub(class_walk_func *pre, class_walk_func *post,
2578 * the entity walk function. A function type for entity walkers.
2580 * @param ent points to the visited entity
2581 * @param env free environment pointer
2583 typedef void entity_walk_func(ir_entity *ent, void *env);
2586 * Walks over all entities in the type.
2588 * @param tp the type
2589 * @param doit the entity walker function
2590 * @param env environment, will be passed to the walker function
2592 void walk_types_entities(ir_type *tp, entity_walk_func *doit, void *env);