2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * Project: libFIRM <br>
24 * File name: ir/tr/type.h <br>
25 * Purpose: Representation of types. <br>
26 * Author: Goetz Lindenmaier <br>
29 * Copyright: (c) 2001-2003 Universität Karlsruhe <br>
35 # ifndef _TYPE_IDENTIFY_H_
36 # define _TYPE_IDENTIFY_H_
38 #include "firm_types.h"
40 /* ------------------------------------------------------------------------ */
42 /** Type for a function that compares two types.
44 * @param tp1 The first type to compare.
45 * @param tp2 The second type to compare.
47 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
49 /** Compares two types by their name.
51 * Compares the opcode and the name of the types. If these are
52 * equal returns 0, else non-zero.
54 int compare_names (const void *tp1, const void *tp2);
56 /** Compares two types strict.
58 * returns 0 if tp1 == tp2, else non-zero
60 int compare_strict (const void *tp1, const void *tp2);
62 /* ------------------------------------------------------------------------ */
64 /** Type for a function that computes a hash value for a type.
66 * @param tp The type to compute a hash for.
68 typedef int (hash_types_func_t)(ir_type *tp);
70 /** Computes a hash value by the type name.
72 * Uses the name of the type and the type opcode to compute the hash.
74 int firm_hash_name (ir_type *tp);
76 /* ------------------------------------------------------------------------ */
78 /** Finalize type construction.
80 * Indicate that a type is so far completed that it can be
81 * distinguished from other types. Mature_type hashes the type into a
82 * table. It uses the function in compare_types_func to compare the
85 * If it finds a type identical to tp it returns this type. It turns
86 * tp into the Id type. All places formerly pointing to tp will now
87 * point to the found type. All entities of tp now refer to the found
88 * type as their owner, but they are not a member of this type. This
89 * is invalid firm -- the entities must be replaced by entities of the
90 * found type. The Id type will be removed from the representation
91 * automatically, but within an unknown time span. It occupies memory
94 * @param tp The type to mature.
96 ir_type * mature_type(ir_type *tp);
98 /** Finalize type construction.
100 * Indicate that a type is so far completed that it can be
101 * distinguished from other types. Mature_type hashes the type into a
102 * table. It uses the function in compare_types_func to compare the
105 * If it finds a type identical to tp it returns this type. It frees
106 * type tp and all its entities.
108 * @param tp The type to mature.
110 ir_type * mature_type_free(ir_type *tp);
112 /** Finalize type construction.
114 * Indicate that a type is so far completed that it can be
115 * distinguished from other types. Mature_type hashes the type into a
116 * table. It uses the function in compare_types_func to compare the
119 * If it find a type identical to tp it returns this type. It frees
120 * the entities and turns the type into an Id type. All places
121 * formerly pointing to tp will now point to the found type. The Id
122 * type will be removed from the representation automatically, but
123 * within an unknown time span. It occupies memory for this time.
125 * @param tp The type to mature.
127 ir_type * mature_type_free_entities(ir_type *tp);
130 * The interface type for the type identify module;
132 typedef struct _type_identify_if_t {
133 compare_types_func_t *cmp; /**< The function that should be used to compare two types.
134 If NULL, compare_strict() will be used. */
135 hash_types_func_t *hash; /**< The function that should be used to calculate a hash
136 value of a type. If NULL, hash_name() will be used. */
137 } type_identify_if_t;
140 * Initialise the type identifier module.
142 * @param ti_if The interface functions for this module.
144 * If the parameter ti_if is NULL, the default functions compare_strict() and
145 * firm_hash_name() will be used.
147 void init_type_identify(type_identify_if_t *ti_if);
149 # endif /* _TYPE_IDENTIFY_H_ */