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
21 * @file type_identify.h
22 * @brief Representation of types.
23 * @author Goetz Lindenmaier
26 #ifndef FIRM_TR_TYPE_IDENTIFY_H
27 #define FIRM_TR_TYPE_IDENTIFY_H
29 #include "firm_types.h"
31 /* ------------------------------------------------------------------------ */
33 /** Type for a function that compares two types.
35 * @param tp1 The first type to compare.
36 * @param tp2 The second type to compare.
38 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
40 /** Compares two types by their name.
42 * Compares the opcode and the name of the types. If these are
43 * equal returns 0, else non-zero.
45 int compare_names (const void *tp1, const void *tp2);
47 /** Compares two types strict.
49 * returns 0 if tp1 == tp2, else non-zero
51 int compare_strict (const void *tp1, const void *tp2);
53 /* ------------------------------------------------------------------------ */
55 /** Type for a function that computes a hash value for a type.
57 * @param tp The type to compute a hash for.
59 typedef int (hash_types_func_t)(ir_type *tp);
61 /** Computes a hash value by the type name.
63 * Uses the name of the type and the type opcode to compute the hash.
65 int firm_hash_name (ir_type *tp);
67 /* ------------------------------------------------------------------------ */
69 /** Finalize type construction.
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
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
85 * @param tp The type to mature.
87 ir_type * mature_type(ir_type *tp);
89 /** Finalize type construction.
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
96 * If it finds a type identical to tp it returns this type. It frees
97 * type tp and all its entities.
99 * @param tp The type to mature.
101 ir_type * mature_type_free(ir_type *tp);
103 /** Finalize type construction.
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
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.
116 * @param tp The type to mature.
118 ir_type * mature_type_free_entities(ir_type *tp);
121 * The interface type for the type identify module;
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;
131 * Initialise the type identifier module.
133 * @param ti_if The interface functions for this module.
135 * If the parameter ti_if is NULL, the default functions compare_strict() and
136 * firm_hash_name() will be used.
138 void init_type_identify(type_identify_if_t *ti_if);
140 #endif /* FIRM_TR_TYPE_IDENTIFY_H */