inlinening of functions
[libfirm] / ir / tr / type_identify.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/type.c
4  * Purpose:     Representation of types.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  *
15  *   file type.c - implementation of the datastructure to hold
16  *   type information.
17  *  (C) 2004 by Universitaet Karlsruhe
18  *  Goetz Lindenmaier
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include "type_identify.h"
27
28 # include <stdlib.h>
29 # include <stddef.h>
30 # include <string.h>
31 # include "type_t.h"
32 # include "tpop_t.h"
33 # include "irprog_t.h"
34 # include "typegmod.h"
35 # include "array.h"
36 # include "irprog.h"
37 # include "mangle.h"
38 #include "pset.h"
39
40 /* The hash set for types. */
41 static pset *type_table = NULL;
42
43
44 int compare_names (const void *tp1, const void *tp2) {
45   type *t1 = (type *) tp1;
46   type *t2 = (type *) tp2;
47
48   return (t1 != t2 &&
49           (t1->type_op !=  t2->type_op ||
50            t1->name    !=  t2->name      )  );
51 }
52
53
54 /* stuff for comparing two types. */
55 //int compare_strict (type *tp1, type *tp2) {
56 int compare_strict (const void *tp1, const void *tp2) {
57   type *t1 = (type *) tp1;
58   type *t2 = (type *) tp2;
59   return t1 != t2;
60 }
61
62 compare_types_func_tp compare_types_func = compare_strict;
63
64 /* stuff to compute a hash value for a type. */
65 int hash_name (type *tp) {
66   unsigned h = (unsigned)tp->type_op;
67   h = 9*h + (unsigned)tp->name;
68   return h;
69 }
70
71 hash_types_func_tp hash_types_func = hash_name;
72
73
74 /* The function that hashes a type. */
75 type *mature_type(type *tp) {
76   type *o;
77
78   assert(type_table);
79
80   o = pset_insert (type_table, tp, hash_types_func(tp) );
81
82   if (!o || o == tp) return tp;
83
84   exchange_types(tp, o);
85
86   return o;
87 }
88
89
90 /* The function that hashes a type. */
91 type *mature_type_free(type *tp) {
92   type *o;
93
94   assert(type_table);
95
96   o = pset_insert (type_table, tp, hash_types_func(tp) );
97
98   if (!o || o == tp) return tp;
99
100   free_type_entities(tp);
101   free_type(tp);
102
103   return o;
104 }
105
106 /* The function that hashes a type. */
107 type *mature_type_free_entities(type *tp) {
108   type *o;
109
110   assert(type_table);
111
112   o = pset_insert (type_table, tp, hash_types_func(tp) );
113
114   if (!o || o == tp) return tp;
115
116   free_type_entities(tp);
117   exchange_types(tp, o);
118
119   return o;
120 }
121
122 void init_type_identify(void) {
123   //type_table = new_pset ((int (const void *, const void *))compare_types_func, 8);
124
125   type_table = new_pset (compare_types_func, 8);
126   //type_table = new_pset (compare_names, 8);
127 }