fixed config.h include
[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  *  file type.c - implementation of the datastructure to hold
15  *  type information.
16  *  (C) 2004 by Universitaet Karlsruhe
17  *  Goetz Lindenmaier
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include "type_identify_t.h"
26
27 #include <stdlib.h>
28 #include <stddef.h>
29 #include <string.h>
30
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_t.h"
37 #include "mangle.h"
38 #include "pset.h"
39
40 /* The hash set for types. */
41 static pset *type_table = NULL;
42
43 /* hash and compare types */
44 static hash_types_func_t    *hash_types_func;
45 static compare_types_func_t *compare_types_func;
46
47 int compare_names (const void *tp1, const void *tp2) {
48   type *t1 = (type *) tp1;
49   type *t2 = (type *) tp2;
50
51   return (t1 != t2 &&
52           (t1->type_op !=  t2->type_op ||
53            t1->name    !=  t2->name      )  );
54 }
55
56 /* stuff for comparing two types. */
57 int compare_strict (const void *tp1, const void *tp2) {
58   type *t1 = (type *) tp1;
59   type *t2 = (type *) tp2;
60   return t1 != t2;
61 }
62
63 /* stuff to compute a hash value for a type. */
64 int hash_name (type *tp) {
65   unsigned h = (unsigned)tp->type_op;
66   h = 9*h + (unsigned)tp->name;
67   return h;
68 }
69
70 /* The function that hashes a type. */
71 type *mature_type(type *tp) {
72   type *o;
73
74   assert(type_table);
75
76   o = pset_insert (type_table, tp, hash_types_func(tp) );
77
78   if (!o || o == tp) return tp;
79
80   exchange_types(tp, o);
81
82   return o;
83 }
84
85
86 /* The function that hashes a type. */
87 type *mature_type_free(type *tp) {
88   type *o;
89
90   assert(type_table);
91
92   o = pset_insert (type_table, tp, hash_types_func(tp) );
93
94   if (!o || o == tp) return tp;
95
96   free_type_entities(tp);
97   free_type(tp);
98
99   return o;
100 }
101
102 /* The function that hashes a type. */
103 type *mature_type_free_entities(type *tp) {
104   type *o;
105
106   assert(type_table);
107
108   o = pset_insert (type_table, tp, hash_types_func(tp) );
109
110   if (!o || o == tp) return tp;
111
112   free_type_entities(tp);
113   exchange_types(tp, o);
114
115   return o;
116 }
117
118 /* initialize this module */
119 void init_type_identify(type_identify_if_t *ti_if) {
120   compare_types_func = ti_if && ti_if->cmp  ? ti_if->cmp  : compare_strict;
121   hash_types_func    = ti_if && ti_if->hash ? ti_if->hash : hash_name;
122
123   type_table = new_pset (compare_types_func, 8);
124 }