3 * File name: ir/tr/type_identify.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.
14 * @file type_identify.c
16 * (C) 2004 by Universitaet Karlsruhe
25 #include "type_identify_t.h"
41 /* The hash set for types. */
42 static pset *type_table = NULL;
44 /* hash and compare types */
45 static hash_types_func_t *hash_types_func;
46 static compare_types_func_t *compare_types_func;
48 int compare_names (const void *tp1, const void *tp2) {
49 ir_type *t1 = (ir_type *) tp1;
50 ir_type *t2 = (ir_type *) tp2;
53 (t1->type_op != t2->type_op ||
54 t1->name != t2->name ) );
57 /* stuff for comparing two types. */
58 int compare_strict (const void *tp1, const void *tp2) {
59 ir_type *t1 = (ir_type *) tp1;
60 ir_type *t2 = (ir_type *) tp2;
64 /* stuff to compute a hash value for a type. */
65 int firm_hash_name (ir_type *tp) {
66 unsigned h = (unsigned)PTR_TO_INT(tp->type_op);
67 h = 9*h + (unsigned)PTR_TO_INT(tp->name);
71 /* The function that hashes a type. */
72 ir_type *mature_type(ir_type *tp) {
77 o = pset_insert (type_table, tp, hash_types_func(tp) );
79 if (!o || o == tp) return tp;
81 exchange_types(tp, o);
87 /* The function that hashes a type. */
88 ir_type *mature_type_free(ir_type *tp) {
93 o = pset_insert (type_table, tp, hash_types_func(tp) );
95 if (!o || o == tp) return tp;
97 free_type_entities(tp);
103 /* The function that hashes a type. */
104 ir_type *mature_type_free_entities(ir_type *tp) {
109 o = pset_insert (type_table, tp, hash_types_func(tp) );
111 if (!o || o == tp) return tp;
113 free_type_entities(tp);
114 exchange_types(tp, o);
119 /* initialize this module */
120 void init_type_identify(type_identify_if_t *ti_if) {
121 compare_types_func = ti_if && ti_if->cmp ? ti_if->cmp : compare_strict;
122 hash_types_func = ti_if && ti_if->hash ? ti_if->hash : firm_hash_name;
124 type_table = new_pset (compare_types_func, 8);