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