4 * Project: libFIRM <br>
5 * File name: ir/tr/type.h <br>
6 * Purpose: Representation of types. <br>
7 * Author: Goetz Lindenmaier <br>
10 * Copyright: (c) 2001-2003 Universität Karlsruhe <br>
11 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. <br>
17 # ifndef _TYPE_IDENTIFY_H_
18 # define _TYPE_IDENTIFY_H_
20 #include "firm_types.h"
22 /* ------------------------------------------------------------------------ */
24 /** Type for a function that compares two types.
26 * @param tp1 The first type to compare.
27 * @param tp2 The second type to compare.
29 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
31 /** Compares two types by their name.
33 * Compares the opcode and the name of the types. If these are
34 * equal returns 0, else non-zero.
36 int compare_names (const void *tp1, const void *tp2);
38 /** Compares two types strict.
40 * returns 0 if tp1 == tp2, else non-zero
42 int compare_strict (const void *tp1, const void *tp2);
44 /* ------------------------------------------------------------------------ */
46 /** Type for a function that computes a hash value for a type.
48 * @param tp The type to compute a hash for.
50 typedef int (hash_types_func_t)(ir_type *tp);
52 /** Computes a hash value by the type name.
54 * Uses the name of the type and the type opcode to compute the hash.
56 int firm_hash_name (ir_type *tp);
58 /* ------------------------------------------------------------------------ */
60 /** Finalize type construction.
62 * Indicate that a type is so far completed that it can be
63 * distinguished from other types. Mature_type hashes the type into a
64 * table. It uses the function in compare_types_func to compare the
67 * If it finds a type identical to tp it returns this type. It turns
68 * tp into the Id type. All places formerly pointing to tp will now
69 * point to the found type. All entities of tp now refer to the found
70 * type as their owner, but they are not a member of this type. This
71 * is invalid firm -- the entities must be replaced by entities of the
72 * found type. The Id type will be removed from the representation
73 * automatically, but within an unknown time span. It occupies memory
76 * @param tp The type to mature.
78 ir_type * mature_type(ir_type *tp);
80 /** Finalize type construction.
82 * Indicate that a type is so far completed that it can be
83 * distinguished from other types. Mature_type hashes the type into a
84 * table. It uses the function in compare_types_func to compare the
87 * If it finds a type identical to tp it returns this type. It frees
88 * type tp and all its entities.
90 * @param tp The type to mature.
92 ir_type * mature_type_free(ir_type *tp);
94 /** Finalize type construction.
96 * Indicate that a type is so far completed that it can be
97 * distinguished from other types. Mature_type hashes the type into a
98 * table. It uses the function in compare_types_func to compare the
101 * If it find a type identical to tp it returns this type. It frees
102 * the entities and turns the type into an Id type. All places
103 * formerly pointing to tp will now point to the found type. The Id
104 * type will be removed from the representation automatically, but
105 * within an unknown time span. It occupies memory for this time.
107 * @param tp The type to mature.
109 ir_type * mature_type_free_entities(ir_type *tp);
112 * The interface type for the type identify module;
114 typedef struct _type_identify_if_t {
115 compare_types_func_t *cmp; /**< The function that should be used to compare two types.
116 If NULL, compare_strict() will be used. */
117 hash_types_func_t *hash; /**< The function that should be used to calculate a hash
118 value of a type. If NULL, hash_name() will be used. */
119 } type_identify_if_t;
122 * Initialise the type identifier module.
124 * @param ti_if The interface functions for this module.
126 * If the parameter ti_if is NULL, the default functions compare_strict() and
127 * firm_hash_name() will be used.
129 void init_type_identify(type_identify_if_t *ti_if);
131 # endif /* _TYPE_IDENTIFY_H_ */