X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftype_identify.c;h=f026b13508fb93ad1e2c0e1a8583a27d6550475f;hb=dd4cd761ab637d4488c7e29f49843b1b02366acf;hp=1905f6c332b7c631f0b07ef18e9ccdce2ed25b9e;hpb=2a2ba142b11466a039c95046ab26f003bc757a9e;p=libfirm diff --git a/ir/tr/type_identify.c b/ir/tr/type_identify.c index 1905f6c33..f026b1350 100644 --- a/ir/tr/type_identify.c +++ b/ir/tr/type_identify.c @@ -1,94 +1,124 @@ /* - * Project: libFIRM - * File name: ir/tr/type.c - * Purpose: Representation of types. - * Author: Goetz Lindenmaier - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2003 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. - */ - -/** + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * - * file type.c - implementation of the datastructure to hold - * type information. - * (C) 2004 by Universitaet Karlsruhe - * Goetz Lindenmaier + * This file is part of libFirm. * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ +/** + * @file type_identify.c + * @brief Representation of types. + * @author Goetz Lindenmaier + * @version $Id$ + */ #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 "typerep.h" + +#include +#include +#include + +#include "type_t.h" +#include "tpop_t.h" +#include "irprog_t.h" +#include "array.h" +#include "irprog_t.h" #include "pset.h" +#include "irtools.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; - type *t2 = (type *) tp2; + ir_type *t1 = (ir_type *) tp1; + ir_type *t2 = (ir_type *) tp2; - return (t1 != t2 && - (t1->type_op != t2->type_op || - t1->name != t2->name ) ); + return (t1 != t2 && + (t1->type_op != t2->type_op || + 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) { - type *t1 = (type *) tp1; - type *t2 = (type *) tp2; - return t1 != t2; +int compare_strict(const void *tp1, const void *tp2) { + const ir_type *t1 = tp1; + const ir_type *t2 = 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) { - unsigned h = (unsigned)tp->type_op; - h = 9*h + (unsigned)tp->name; - return h; +int firm_hash_name(ir_type *tp) { + unsigned h = (unsigned)PTR_TO_INT(tp->type_op); + h = 9*h + (unsigned)PTR_TO_INT(tp->name); + return h; } -hash_types_func_tp hash_types_func = hash_name; +/* The function that hashes a type. */ +ir_type *mature_type(ir_type *tp) { + ir_type *o; + + assert(type_table); + + o = pset_insert (type_table, tp, hash_types_func(tp) ); + if (!o || o == tp) return tp; + exchange_types(tp, o); + + return o; +} /* The function that hashes a type. */ -type *mature_type(type *tp) { - type *o; +ir_type *mature_type_free(ir_type *tp) { + ir_type *o; - assert(type_table); + assert(type_table); - o = pset_insert (type_table, tp, hash_types_func(tp) ); + o = pset_insert (type_table, tp, hash_types_func(tp) ); + if (!o || o == tp) return tp; - if (!o || o == tp) return tp; + free_type_entities(tp); + free_type(tp); - exchange_types(tp, o); - return o ; + return o; } +/* The function that hashes a type. */ +ir_type *mature_type_free_entities(ir_type *tp) { + ir_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; +} -void init_type_identify(void) { - //type_table = new_pset ((int (const void *, const void *))compare_types_func, 8); +/* 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); + type_table = new_pset (compare_types_func, 8); }