added missing initialization
[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 #ifndef _TYPE_TYPEDEF_
21 #define _TYPE_TYPEDEF_
22 typedef struct type type;
23 #endif
24
25 /* ------------------------------------------------------------------------ */
26
27 /**  Type for a function that compares two types.
28  *
29  *   @param tp1  The first type to compare.
30  *   @param tp2  The second type to compare.
31  */
32 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
33
34 /** Compares two types by their name.
35  *
36  * Compares the opcode and the name of the types. If these are
37  * equal returns 0, else non-zero.
38  */
39 int compare_names (const void *tp1, const void *tp2);
40
41 /** Compares two types strict.
42  *
43  * returns 0 if tp1 == tp2, else non-zero
44  */
45 int compare_strict (const void *tp1, const void *tp2);
46
47 /* ------------------------------------------------------------------------ */
48
49 /**  Type for a function that computes a hash value for a type.
50  *
51  *   @param tp The type to compute a hash for.
52  */
53 typedef int (hash_types_func_t)(type *tp);
54
55 /** Computes a hash value by the type name.
56  *
57  * Uses the name of the type and the type opcode to compute the hash.
58  */
59 int hash_name (type *tp);
60
61 /* ------------------------------------------------------------------------ */
62
63 /** Finalize type construction.
64  *
65  * Indicate that a type is so far completed that it can be
66  * distinguished from other types.  Mature_type hashes the type into a
67  * table.  It uses the function in compare_types_func to compare the
68  * types.
69  *
70  * If it finds a type identical to tp it returns this type.  It turns
71  * tp into the Id type.  All places formerly pointing to tp will now
72  * point to the found type.  All entities of tp now refer to the found
73  * type as their owner, but they are not a member of this type.  This
74  * is invalid firm -- the entities must be replaced by entities of the
75  * found type.  The Id type will be removed from the representation
76  * automatically, but within an unknown time span.  It occupies memory
77  * for this time.
78  *
79  * @param tp     The type to mature.
80  */
81 type *       mature_type(type *tp);
82
83 /** Finalize type construction.
84  *
85  * Indicate that a type is so far completed that it can be
86  * distinguished from other types.  Mature_type hashes the type into a
87  * table.  It uses the function in compare_types_func to compare the
88  * types.
89  *
90  * If it finds a type identical to tp it returns this type.  It frees
91  * type tp and all its entities.
92  *
93  * @param tp     The type to mature.
94  */
95 type *       mature_type_free(type *tp);
96
97 /** Finalize type construction.
98  *
99  * Indicate that a type is so far completed that it can be
100  * distinguished from other types.  Mature_type hashes the type into a
101  * table.  It uses the function in compare_types_func to compare the
102  * types.
103  *
104  * If it find a type identical to tp it returns this type.  It frees
105  * the entities and turns the type into an Id type.  All places
106  * formerly pointing to tp will now point to the found type.  The Id
107  * type will be removed from the representation automatically, but
108  * within an unknown time span.  It occupies memory for this time.
109  *
110  * @param tp     The type to mature.
111  */
112 type *       mature_type_free_entities(type *tp);
113
114 /**
115  * The interface type for the type identify module;
116  */
117 typedef struct _type_identify_if_t {
118   compare_types_func_t *cmp;    /**< The function that should be used to compare two types.
119                                      If NULL, compare_strict() will be used. */
120   hash_types_func_t *hash;      /**< The function that should be used to calculate a hash
121                                      value of a type. If NULL, hash_name() will be used. */
122 } type_identify_if_t;
123
124 /**
125  * Initialise the type identifier module.
126  *
127  * @param ti_if    The interface functions for this module.
128  *
129  * If the parameter ti_if is NULL, the default functions compare_strict() and
130  * hash_name() will be used.
131  */
132 void init_type_identify(type_identify_if_t *ti_if);
133
134 # endif /* _TYPE_IDENTIFY_H_ */