From 6638be02a7a97559707fe3c70c1759eb030b74f6 Mon Sep 17 00:00:00 2001 From: Manuel Mohr Date: Thu, 22 Sep 2011 16:34:55 +0200 Subject: [PATCH] Added callback mechanism to determine compilerlib function names. --- include/libfirm/iroptimize.h | 23 ++++++++++++++ ir/ir/ircomplib.c | 59 ++++++++++++++++++++++++++++++++++++ ir/lower/lower_copyb.c | 4 +-- 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 ir/ir/ircomplib.c diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h index 7f4a76288..eb088ca22 100644 --- a/include/libfirm/iroptimize.h +++ b/include/libfirm/iroptimize.h @@ -1082,6 +1082,29 @@ FIRM_API ir_value_classify_sign classify_value_sign(ir_node *n); FIRM_API ir_tarval *computed_value_Cmp_Confirm( const ir_node *cmp, ir_node *left, ir_node *right, ir_relation relation); +typedef ir_entity *(*compilerlib_entity_creator_t)(ident *id, ir_type *mt); +/** + * Set the compilerlib entity creation callback that is used to create + * compilerlib function entities. + * + * @param cb the new compilerlib entity creation callback + */ +FIRM_API void set_compilerlib_entity_creator(compilerlib_entity_creator_t c); + +/** + * Get the compilerlib entity creation callback. + */ +FIRM_API compilerlib_entity_creator_t get_compilerlib_entity_creator(); + +/** + * Construct the entity for a given function using the current compilerlib + * entity creation callback. + * + * @param id the identifier of the compilerlib function + * @param mt the method type of the compilerlib function + */ +FIRM_API ir_entity *create_compilerlib_entity(ident *id, ir_type *mt); + #include "end.h" #endif diff --git a/ir/ir/ircomplib.c b/ir/ir/ircomplib.c new file mode 100644 index 000000000..da069d264 --- /dev/null +++ b/ir/ir/ircomplib.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. + * + * 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 + * @brief Compilerlib entity creation related functions. + * @date 2011-09-22 + * @author Manuel Mohr + * @version $Id$ + */ +#include "config.h" + +#include "irprog.h" +#include "iroptimize.h" +#include "typerep.h" + +#include +#include + +/* The default implementation does not set a different ld name. */ +static ir_entity *compilerlib_entity_def_creator(ident *id, ir_type *mt) +{ + return new_entity(get_glob_type(), id, mt); +} + +static compilerlib_entity_creator_t creator = compilerlib_entity_def_creator; + +void set_compilerlib_entity_creator(compilerlib_entity_creator_t c) +{ + assert(c != NULL); + + creator = c; +} + +compilerlib_entity_creator_t get_compilerlib_entity_creator() +{ + return creator; +} + +ir_entity *create_compilerlib_entity(ident *id, ir_type *mt) +{ + return creator(id, mt); +} diff --git a/ir/lower/lower_copyb.c b/ir/lower/lower_copyb.c index 6bf7b7b7e..b4b114cad 100644 --- a/ir/lower/lower_copyb.c +++ b/ir/lower/lower_copyb.c @@ -187,12 +187,10 @@ static ir_node *get_memcpy_symconst(ir_graph *irg) { ident *id = new_id_from_str("memcpy"); ir_type *mt = get_memcpy_methodtype(); - ir_entity *ent = new_entity(get_glob_type(), id, mt); + ir_entity *ent = create_compilerlib_entity(id, mt); symconst_symbol sym; - set_entity_ld_ident(ent, get_entity_ident(ent)); sym.entity_p = ent; - return new_r_SymConst(irg, mode_P_code, sym, symconst_addr_ent); } -- 2.20.1