added new licence header
[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.h
22  *
23  * Project:     libFIRM                                                   <br>
24  * File name:   ir/tr/type.h                                              <br>
25  * Purpose:     Representation of types.                                  <br>
26  * Author:      Goetz Lindenmaier                                         <br>
27  * Modified by:                                                           <br>
28  * Created:                                                               <br>
29  * Copyright:   (c) 2001-2003 Universität Karlsruhe                       <br>
30  * CVS-ID:      $Id$
31  *
32  *
33  */
34
35 # ifndef _TYPE_IDENTIFY_H_
36 # define _TYPE_IDENTIFY_H_
37
38 #include "firm_types.h"
39
40 /* ------------------------------------------------------------------------ */
41
42 /**  Type for a function that compares two types.
43  *
44  *   @param tp1  The first type to compare.
45  *   @param tp2  The second type to compare.
46  */
47 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
48
49 /** Compares two types by their name.
50  *
51  * Compares the opcode and the name of the types. If these are
52  * equal returns 0, else non-zero.
53  */
54 int compare_names (const void *tp1, const void *tp2);
55
56 /** Compares two types strict.
57  *
58  * returns 0 if tp1 == tp2, else non-zero
59  */
60 int compare_strict (const void *tp1, const void *tp2);
61
62 /* ------------------------------------------------------------------------ */
63
64 /**  Type for a function that computes a hash value for a type.
65  *
66  *   @param tp The type to compute a hash for.
67  */
68 typedef int (hash_types_func_t)(ir_type *tp);
69
70 /** Computes a hash value by the type name.
71  *
72  * Uses the name of the type and the type opcode to compute the hash.
73  */
74 int firm_hash_name (ir_type *tp);
75
76 /* ------------------------------------------------------------------------ */
77
78 /** Finalize type construction.
79  *
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
83  * types.
84  *
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
92  * for this time.
93  *
94  * @param tp     The type to mature.
95  */
96 ir_type *    mature_type(ir_type *tp);
97
98 /** Finalize type construction.
99  *
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
103  * types.
104  *
105  * If it finds a type identical to tp it returns this type.  It frees
106  * type tp and all its entities.
107  *
108  * @param tp     The type to mature.
109  */
110 ir_type *    mature_type_free(ir_type *tp);
111
112 /** Finalize type construction.
113  *
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
117  * types.
118  *
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.
124  *
125  * @param tp     The type to mature.
126  */
127 ir_type *    mature_type_free_entities(ir_type *tp);
128
129 /**
130  * The interface type for the type identify module;
131  */
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;
138
139 /**
140  * Initialise the type identifier module.
141  *
142  * @param ti_if    The interface functions for this module.
143  *
144  * If the parameter ti_if is NULL, the default functions compare_strict() and
145  * firm_hash_name() will be used.
146  */
147 void init_type_identify(type_identify_if_t *ti_if);
148
149 # endif /* _TYPE_IDENTIFY_H_ */