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 #ifndef _TYPE_TYPEDEF_
21 #define _TYPE_TYPEDEF_
22 typedef struct type type;
25 /* ------------------------------------------------------------------------ */
27 /** Type for a function that compares two types.
29 * @param tp1 The first type to compare.
30 * @param tp2 The second type to compare.
32 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
34 /** Compares two types by their name.
36 * Compares the opcode and the name of the types. If these are
37 * equal returns 0, else non-zero.
39 int compare_names (const void *tp1, const void *tp2);
41 /** Compares two types strict.
43 * returns 0 if tp1 == tp2, else non-zero
45 int compare_strict (const void *tp1, const void *tp2);
47 /* ------------------------------------------------------------------------ */
49 /** Type for a function that computes a hash value for a type.
51 * @param tp The type to compute a hash for.
53 typedef int (hash_types_func_t)(type *tp);
55 /** Computes a hash value by the type name.
57 * Uses the name of the type and the type opcode to compute the hash.
59 int hash_name (type *tp);
61 /* ------------------------------------------------------------------------ */
63 /** Finalize type construction.
65 * Indicate that a type is so far completed that it can be
66 * distinguished from other types. Mature_type hashes the type into a
67 * table. It uses the function in compare_types_func to compare the
70 * If it finds a type identical to tp it returns this type. It turns
71 * tp into the Id type. All places formerly pointing to tp will now
72 * point to the found type. All entities of tp now refer to the found
73 * type as their owner, but they are not a member of this type. This
74 * is invalid firm -- the entities must be replaced by entities of the
75 * found type. The Id type will be removed from the representation
76 * automatically, but within an unknown time span. It occupies memory
79 * @param tp The type to mature.
81 type * mature_type(type *tp);
83 /** Finalize type construction.
85 * Indicate that a type is so far completed that it can be
86 * distinguished from other types. Mature_type hashes the type into a
87 * table. It uses the function in compare_types_func to compare the
90 * If it finds a type identical to tp it returns this type. It frees
91 * type tp and all its entities.
93 * @param tp The type to mature.
95 type * mature_type_free(type *tp);
97 /** Finalize type construction.
99 * Indicate that a type is so far completed that it can be
100 * distinguished from other types. Mature_type hashes the type into a
101 * table. It uses the function in compare_types_func to compare the
104 * If it find a type identical to tp it returns this type. It frees
105 * the entities and turns the type into an Id type. All places
106 * formerly pointing to tp will now point to the found type. The Id
107 * type will be removed from the representation automatically, but
108 * within an unknown time span. It occupies memory for this time.
110 * @param tp The type to mature.
112 type * mature_type_free_entities(type *tp);
115 * Initialise the type identifier module.
117 * @param cmp The function that should be used to compare two types.
118 * If NULL, compare_strict() will be used.
119 * @param hash The function that should be used to calculate a hash
120 * value of a type. If NULL, hash_name() will be used.
122 void init_type_identify(compare_types_func_t *cmp, hash_types_func_t *hash);
124 # endif /* _TYPE_IDENTIFY_H_ */