3 * File name: ir/tr/type.c
4 * Purpose: Representation of types.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * file type.c - implementation of the datastructure to hold
17 * (C) 2004 by Universitaet Karlsruhe
26 #include "type_identify.h"
33 # include "irprog_t.h"
34 # include "typegmod.h"
40 /* The hash set for types. */
41 static pset *type_table = NULL;
44 int compare_names (const void *tp1, const void *tp2) {
45 type *t1 = (type *) tp1;
46 type *t2 = (type *) tp2;
49 (t1->type_op != t2->type_op ||
50 t1->name != t2->name ) );
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;
62 compare_types_func_tp compare_types_func = compare_strict;
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;
71 hash_types_func_tp hash_types_func = hash_name;
74 /* The function that hashes a type. */
75 type *mature_type(type *tp) {
80 o = pset_insert (type_table, tp, hash_types_func(tp) );
82 if (!o || o == tp) return tp;
84 exchange_types(tp, o);
90 /* The function that hashes a type. */
91 type *mature_type_free(type *tp) {
96 o = pset_insert (type_table, tp, hash_types_func(tp) );
98 if (!o || o == tp) return tp;
100 free_type_entities(tp);
106 /* The function that hashes a type. */
107 type *mature_type_free_entities(type *tp) {
112 o = pset_insert (type_table, tp, hash_types_func(tp) );
114 if (!o || o == tp) return tp;
116 free_type_entities(tp);
117 exchange_types(tp, o);
122 void init_type_identify(void) {
123 //type_table = new_pset ((int (const void *, const void *))compare_types_func, 8);
125 type_table = new_pset (compare_types_func, 8);
126 //type_table = new_pset (compare_names, 8);