fbb5eea2121a8b6f7f733789f4674bc842491553
[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) (type *tp1, type *tp2);
34 typedef int (*compare_types_func_tp) (const void *tp1, const void *tp2);
35
36 /** Compares two types by their name.
37  *
38  * Compares the opcode and the name of the types. If these are
39  * equal returns true, else false.
40  */
41 int compare_names (const void *tp1, const void *tp2);
42
43 /** Compares two types strict.
44  *
45  * returns true if tp1 == tp2
46  */
47 int compare_strict (const void *tp1, const void *tp2);
48
49 /** A variable that holds a compare function for types.
50  *
51  *  The compare function is used to identify equal types.  The
52  *  variable is initialized with the function compare_strict().
53  *
54  *  The variable must be set before calling init_firm()! Later changes
55  *  have no effect.
56  */
57 extern compare_types_func_tp compare_types_func;
58
59
60 /* ------------------------------------------------------------------------ */
61
62 /**  Type for a function that computes a hash value for a type.
63  *
64  *   @param tp The type to compute a hash for.
65  */
66 typedef int (*hash_types_func_tp)(type *tp);
67
68 /** Computes a hash value by the type name.
69  *
70  * Uses the name of the type and the type opcode to compute the hash.
71  */
72 int hash_name (type *tp);
73
74 /** A variable that holds a hash function for a type.
75  *
76  *  The hash function is used to identify equal types.  The
77  *  variable is initialized with the function hash_name().
78  *
79  *  The variable must be set before calling init_firm()! Later changes
80  *  have no effect.
81  */
82 extern hash_types_func_tp hash_types_func;
83
84
85 /* ------------------------------------------------------------------------ */
86
87 /** Finalize type construction.
88  *
89  * Indicate that a type is so far completed that it can be
90  * distinguished from other types.  Mature_type hashes the type into a
91  * table.  It uses the function in compare_types_func to compare the
92  * types.  If it find a type identical to tp it returns this type.  In
93  * this case it also turns tp into the Id type.  The caller should free
94  * tp if he knows that there are no other references to tp.  The memory
95  * of tp is not lost, but will remain alive for an unknown time.
96  *
97  * @param tp The type to mature.
98  */
99 type *       mature_type(type *tp);
100
101 # endif /* _TYPE_IDENTIFY_H_ */