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