X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftype_identify.c;h=bdd11278f7a33ff6deb570968b2b3185c8eaddf6;hb=98ca7e71bc79bb2a3b2ccb039df78000fc48e70a;hp=1905f6c332b7c631f0b07ef18e9ccdce2ed25b9e;hpb=2a2ba142b11466a039c95046ab26f003bc757a9e;p=libfirm diff --git a/ir/tr/type_identify.c b/ir/tr/type_identify.c index 1905f6c33..bdd11278f 100644 --- a/ir/tr/type_identify.c +++ b/ir/tr/type_identify.c @@ -11,35 +11,38 @@ */ /** - * - * file type.c - implementation of the datastructure to hold - * type information. + * file type.c - implementation of the datastructure to hold + * type information. * (C) 2004 by Universitaet Karlsruhe * Goetz Lindenmaier * */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif -#include "type_identify.h" - -# include -# include -# include -# include "type_t.h" -# include "tpop_t.h" -# include "irprog_t.h" -# include "typegmod.h" -# include "array.h" -# include "irprog.h" -# include "mangle.h" +#include "type_identify_t.h" + +#include +#include +#include + +#include "type_t.h" +#include "tpop_t.h" +#include "irprog_t.h" +#include "typegmod.h" +#include "array.h" +#include "irprog_t.h" +#include "mangle.h" #include "pset.h" /* The hash set for types. */ static pset *type_table = NULL; +/* hash and compare types */ +static hash_types_func_t *hash_types_func; +static compare_types_func_t *compare_types_func; int compare_names (const void *tp1, const void *tp2) { type *t1 = (type *) tp1; @@ -50,27 +53,20 @@ int compare_names (const void *tp1, const void *tp2) { t1->name != t2->name ) ); } - /* stuff for comparing two types. */ -//static int compare_strict (type *tp1, type *tp2) { -static int compare_strict (const void *tp1, const void *tp2) { +int compare_strict (const void *tp1, const void *tp2) { type *t1 = (type *) tp1; type *t2 = (type *) tp2; return t1 != t2; } -compare_types_func_tp compare_types_func = compare_strict; - /* stuff to compute a hash value for a type. */ -int hash_name (type *tp) { +int firm_hash_name (type *tp) { unsigned h = (unsigned)tp->type_op; h = 9*h + (unsigned)tp->name; return h; } -hash_types_func_tp hash_types_func = hash_name; - - /* The function that hashes a type. */ type *mature_type(type *tp) { type *o; @@ -82,13 +78,47 @@ type *mature_type(type *tp) { if (!o || o == tp) return tp; exchange_types(tp, o); - return o ; + + return o; } -void init_type_identify(void) { - //type_table = new_pset ((int (const void *, const void *))compare_types_func, 8); +/* The function that hashes a type. */ +type *mature_type_free(type *tp) { + type *o; + + assert(type_table); + + o = pset_insert (type_table, tp, hash_types_func(tp) ); + + if (!o || o == tp) return tp; + + free_type_entities(tp); + free_type(tp); + + return o; +} + +/* The function that hashes a type. */ +type *mature_type_free_entities(type *tp) { + type *o; + + assert(type_table); + + o = pset_insert (type_table, tp, hash_types_func(tp) ); + + if (!o || o == tp) return tp; + + free_type_entities(tp); + exchange_types(tp, o); + + return o; +} + +/* initialize this module */ +void init_type_identify(type_identify_if_t *ti_if) { + compare_types_func = ti_if && ti_if->cmp ? ti_if->cmp : compare_strict; + hash_types_func = ti_if && ti_if->hash ? ti_if->hash : firm_hash_name; type_table = new_pset (compare_types_func, 8); - //type_table = new_pset (compare_names, 8); }