added statistics for blocks
[libfirm] / ir / tr / type_identify.h
1 /**
2  *
3  * @file type.h
4  *
5  * Project:     libFIRM                                                   <br>
6  * File name:   ir/tr/type.h                                              <br>
7  * Purpose:     Representation of types.                                  <br>
8  * Author:      Goetz Lindenmaier                                         <br>
9  * Modified by:                                                           <br>
10  * Created:                                                               <br>
11  * Copyright:   (c) 2001-2003 Universität Karlsruhe                       <br>
12  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE. <br>
13  * CVS-ID:      $Id$
14  *
15  *
16  */
17
18 # ifndef _TYPE_IDENTIFY_H_
19 # define _TYPE_IDENTIFY_H_
20
21 #ifndef _TYPE_TYPEDEF_
22 #define _TYPE_TYPEDEF_
23 typedef struct type type;
24 #endif
25
26 /* ------------------------------------------------------------------------ */
27
28 /**  Type for a function that compares two types.
29  *
30  *   @param tp1  The first type to compare.
31  *   @param tp2  The second type to compare.
32  */
33 typedef int (*compare_types_func_tp) (const void *tp1, const void *tp2);
34
35 /** Compares two types by their name.
36  *
37  * Compares the opcode and the name of the types. If these are
38  * equal returns 0, else non-zero.
39  */
40 int compare_names (const void *tp1, const void *tp2);
41
42 /** Compares two types strict.
43  *
44  * returns 0 if tp1 == tp2, else non-zero
45  */
46 int compare_strict (const void *tp1, const void *tp2);
47
48 /** A variable that holds a compare function for types.
49  *
50  *  The compare function is used to identify equal types.  The
51  *  variable is initialized with the function compare_strict().
52  *
53  *  The variable must be set before calling init_firm()! Later changes
54  *  have no effect.
55  */
56 extern compare_types_func_tp compare_types_func;
57
58
59 /* ------------------------------------------------------------------------ */
60
61 /**  Type for a function that computes a hash value for a type.
62  *
63  *   @param tp The type to compute a hash for.
64  */
65 typedef int (*hash_types_func_tp)(type *tp);
66
67 /** Computes a hash value by the type name.
68  *
69  * Uses the name of the type and the type opcode to compute the hash.
70  */
71 int hash_name (type *tp);
72
73 /** A variable that holds a hash function for a type.
74  *
75  *  The hash function is used to identify equal types.  The
76  *  variable is initialized with the function hash_name().
77  *
78  *  The variable must be set before calling init_firm()! Later changes
79  *  have no effect.
80  */
81 extern hash_types_func_tp hash_types_func;
82
83
84 /* ------------------------------------------------------------------------ */
85
86 /** Finalize type construction.
87  *
88  * Indicate that a type is so far completed that it can be
89  * distinguished from other types.  Mature_type hashes the type into a
90  * table.  It uses the function in compare_types_func to compare the
91  * types.
92  *
93  * If it finds a type identical to tp it returns this type.  It turns
94  * tp into the Id type.  All places formerly pointing to tp will now
95  * point to the found type.  All entities of tp now refer to the found
96  * type as their owner, but they are not a member of this type.  This
97  * is invalid firm -- the entities must be replaced by entities of the
98  * found type.  The Id type will be removed from the representation
99  * automatically, but within an unknown time span.  It occupies memory
100  * for this time.
101  *
102  * @param tp     The type to mature.
103  */
104 type *       mature_type(type *tp);
105
106 /** Finalize type construction.
107  *
108  * Indicate that a type is so far completed that it can be
109  * distinguished from other types.  Mature_type hashes the type into a
110  * table.  It uses the function in compare_types_func to compare the
111  * types.
112  *
113  * If it finds a type identical to tp it returns this type.  It frees
114  * type tp and all its entities.
115  *
116  * @param tp     The type to mature.
117  */
118 type *       mature_type_free(type *tp);
119
120 /** Finalize type construction.
121  *
122  * Indicate that a type is so far completed that it can be
123  * distinguished from other types.  Mature_type hashes the type into a
124  * table.  It uses the function in compare_types_func to compare the
125  * types.
126  *
127  * If it find a type identical to tp it returns this type.  It frees
128  * the entities and turns the type into an Id type.  All places
129  * formerly pointing to tp will now point to the found type.  The Id
130  * type will be removed from the representation automatically, but
131  * within an unknown time span.  It occupies memory for this time.
132  *
133  * @param tp     The type to mature.
134  */
135 type *       mature_type_free_entities(type *tp);
136
137 /**
138  * initialise the type identifier module.
139  */
140 void init_type_identify(void);
141
142 # endif /* _TYPE_IDENTIFY_H_ */