Fixed the last fix again:
[libfirm] / ir / tr / type_identify.h
1 /*
2  * Copyright (C) 1995-2007 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    type_identify.h
22  * @brief   Representation of types.
23  * @author  Goetz Lindenmaier
24  * @version $Id$
25  */
26 #ifndef FIRM_TR_TYPE_IDENTIFY_H
27 #define FIRM_TR_TYPE_IDENTIFY_H
28
29 #include "firm_types.h"
30
31 /* ------------------------------------------------------------------------ */
32
33 /**  Type for a function that compares two types.
34  *
35  *   @param tp1  The first type to compare.
36  *   @param tp2  The second type to compare.
37  */
38 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
39
40 /** Compares two types by their name.
41  *
42  * Compares the opcode and the name of the types. If these are
43  * equal returns 0, else non-zero.
44  */
45 int compare_names (const void *tp1, const void *tp2);
46
47 /** Compares two types strict.
48  *
49  * returns 0 if tp1 == tp2, else non-zero
50  */
51 int compare_strict (const void *tp1, const void *tp2);
52
53 /* ------------------------------------------------------------------------ */
54
55 /**  Type for a function that computes a hash value for a type.
56  *
57  *   @param tp The type to compute a hash for.
58  */
59 typedef int (hash_types_func_t)(ir_type *tp);
60
61 /** Computes a hash value by the type name.
62  *
63  * Uses the name of the type and the type opcode to compute the hash.
64  */
65 int firm_hash_name (ir_type *tp);
66
67 /* ------------------------------------------------------------------------ */
68
69 /** Finalize type construction.
70  *
71  * Indicate that a type is so far completed that it can be
72  * distinguished from other types.  Mature_type hashes the type into a
73  * table.  It uses the function in compare_types_func to compare the
74  * types.
75  *
76  * If it finds a type identical to tp it returns this type.  It turns
77  * tp into the Id type.  All places formerly pointing to tp will now
78  * point to the found type.  All entities of tp now refer to the found
79  * type as their owner, but they are not a member of this type.  This
80  * is invalid firm -- the entities must be replaced by entities of the
81  * found type.  The Id type will be removed from the representation
82  * automatically, but within an unknown time span.  It occupies memory
83  * for this time.
84  *
85  * @param tp     The type to mature.
86  */
87 ir_type *    mature_type(ir_type *tp);
88
89 /** Finalize type construction.
90  *
91  * Indicate that a type is so far completed that it can be
92  * distinguished from other types.  Mature_type hashes the type into a
93  * table.  It uses the function in compare_types_func to compare the
94  * types.
95  *
96  * If it finds a type identical to tp it returns this type.  It frees
97  * type tp and all its entities.
98  *
99  * @param tp     The type to mature.
100  */
101 ir_type *    mature_type_free(ir_type *tp);
102
103 /** Finalize type construction.
104  *
105  * Indicate that a type is so far completed that it can be
106  * distinguished from other types.  Mature_type hashes the type into a
107  * table.  It uses the function in compare_types_func to compare the
108  * types.
109  *
110  * If it find a type identical to tp it returns this type.  It frees
111  * the entities and turns the type into an Id type.  All places
112  * formerly pointing to tp will now point to the found type.  The Id
113  * type will be removed from the representation automatically, but
114  * within an unknown time span.  It occupies memory for this time.
115  *
116  * @param tp     The type to mature.
117  */
118 ir_type *    mature_type_free_entities(ir_type *tp);
119
120 /**
121  * The interface type for the type identify module;
122  */
123 typedef struct _type_identify_if_t {
124         compare_types_func_t *cmp;    /**< The function that should be used to compare two types.
125                                            If NULL, compare_strict() will be used. */
126         hash_types_func_t *hash;      /**< The function that should be used to calculate a hash
127                                            value of a type. If NULL, hash_name() will be used. */
128 } type_identify_if_t;
129
130 /**
131  * Initialise the type identifier module.
132  *
133  * @param ti_if    The interface functions for this module.
134  *
135  * If the parameter ti_if is NULL, the default functions compare_strict() and
136  * firm_hash_name() will be used.
137  */
138 void init_type_identify(type_identify_if_t *ti_if);
139
140 #endif /* FIRM_TR_TYPE_IDENTIFY_H */