Commit be94dc6f authored by Matthias Braun's avatar Matthias Braun
Browse files

rework compilerlib entity stuff

now the frontend is only responsible to mangle the ld_name, entity
creation is left to libfirm which now also caches the entities.
parent d5e61694
......@@ -912,7 +912,7 @@ FIRM_API ir_tarval *computed_value_Cmp_Confirm(
const ir_node *cmp, ir_node *left, ir_node *right, ir_relation relation);
/** Type of callbacks for creating entities of the compiler library */
typedef ir_entity *(*compilerlib_entity_creator_t)(ident *id, ir_type *mt);
typedef ident *(*compilerlib_name_mangle_t)(ident *id, ir_type *mt);
/**
* Sets the compilerlib entity creation callback that is used to create
......@@ -920,10 +920,10 @@ typedef ir_entity *(*compilerlib_entity_creator_t)(ident *id, ir_type *mt);
*
* @param cb the new compilerlib entity creation callback
*/
FIRM_API void set_compilerlib_entity_creator(compilerlib_entity_creator_t cb);
FIRM_API void set_compilerlib_name_mangle(compilerlib_name_mangle_t cb);
/** Returns the compilerlib entity creation callback. */
FIRM_API compilerlib_entity_creator_t get_compilerlib_entity_creator(void);
FIRM_API compilerlib_name_mangle_t get_compilerlib_name_mangle(void);
/**
* Constructs the entity for a given function using the current compilerlib
......
......@@ -14,30 +14,54 @@
#include "irprog.h"
#include "iroptimize.h"
#include "typerep.h"
#include "irtypes.h"
#include <assert.h>
/* The default implementation does not set a different ld name. */
static ir_entity *compilerlib_entity_def_creator(ident *id, ir_type *mt)
static ident *compilerlib_name_mangle_default(ident *id, ir_type *mt)
{
return new_entity(get_glob_type(), id, mt);
(void)mt;
return id;
}
static compilerlib_entity_creator_t creator = compilerlib_entity_def_creator;
static compilerlib_name_mangle_t compilerlib_mangler
= compilerlib_name_mangle_default;
void set_compilerlib_entity_creator(compilerlib_entity_creator_t c)
void set_compilerlib_name_mangle(compilerlib_name_mangle_t mangler)
{
assert(c != NULL);
creator = c;
assert(mangler != NULL);
compilerlib_mangler = mangler;
}
compilerlib_entity_creator_t get_compilerlib_entity_creator()
compilerlib_name_mangle_t get_compilerlib_name_mangle(void)
{
return creator;
return compilerlib_mangler;
}
ir_entity *create_compilerlib_entity(ident *id, ir_type *mt)
{
return creator(id, mt);
ir_entity *entity = pmap_get(ir_entity, irp->compilerlib_entities, id);
if (entity != NULL)
return entity;
/* let frontend mangle the name */
ident *ld_name = compilerlib_mangler(id, mt);
/* search for an existing entity */
ir_type *glob = get_glob_type();
for (size_t n_members = get_compound_n_members(glob), i = 0;
i < n_members; ++i) {
ir_entity *member = get_compound_member(glob, i);
if (get_entity_ld_ident(member) == ld_name) {
entity = member;
goto found;
}
}
entity = new_entity(glob, id, mt);
set_entity_ld_ident(entity, ld_name);
set_entity_visibility(entity, ir_visibility_external);
found:
pmap_insert(irp->compilerlib_entities, id, entity);
return entity;
}
......@@ -48,6 +48,7 @@ static ir_prog *new_incomplete_ir_prog(void)
#ifndef NDEBUG
res->reserved_resources = IRP_RESOURCE_NONE;
#endif
res->compilerlib_entities = pmap_create();
return res;
}
......@@ -125,6 +126,7 @@ void free_ir_prog(void)
DEL_ARR_F(irp->global_asms);
pmap_destroy(irp->compilerlib_entities);
irp->name = NULL;
irp->const_code_irg = NULL;
irp->kind = k_BAD;
......
......@@ -26,6 +26,7 @@
#include "bitset.h"
#include "pset.h"
#include "pmap.h"
#include "list.h"
#include "obst.h"
#include "vrp.h"
......@@ -634,6 +635,7 @@ struct ir_prog {
size_t max_irg_idx; /**< highest unused irg index */
long max_node_nr; /**< to generate unique numbers for nodes. */
unsigned dump_nr; /**< number of program info dumps */
pmap *compilerlib_entities; /**< maps ident* to ir_entity* of the compilerlib */
#ifndef NDEBUG
irp_resources_t reserved_resources; /**< Bitset for tracking used global resources. */
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment