Commit af027d18 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

ident: Replace id_mangle*() by new_id_fmt().

parent 1c9b1e14
......@@ -44,6 +44,13 @@ FIRM_API ident *new_id_from_str(const char *str);
*/
FIRM_API ident *new_id_from_chars(const char *str, size_t len);
/**
* Create an ident from a format string.
*
* @return a handle for the generated ident
*/
FIRM_API ident *new_id_fmt(char const *fmt, ...);
/**
* Returns a string represented by an ident.
*
......@@ -61,13 +68,6 @@ FIRM_API const char *get_id_str(ident *id);
*/
FIRM_API ident *id_unique(const char *tag);
/** mangle dot: Returns a new ident that represents first.scnd. */
FIRM_API ident *id_mangle_dot(ident *first, ident* scnd);
/** Returns a new ident that represents 'prefixscndsuffix'. */
FIRM_API ident *id_mangle3(const char *prefix, ident *middle,
const char *suffix);
/** @} */
#include "end.h"
......
......@@ -2812,7 +2812,7 @@ static void amd64_create_stacklayout(ir_graph *irg, const x86_cconv_t *cconv)
be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
/* construct argument type */
ident *const arg_id = id_mangle3("", get_entity_ident(entity), "_arg_type");
ident *const arg_id = new_id_fmt("%s_arg_type", get_entity_ident(entity));
ir_type *const arg_type = new_type_struct(arg_id);
size_t const n_params = get_method_n_params(function_type);
for (size_t p = 0; p < n_params; ++p) {
......
......@@ -1713,7 +1713,7 @@ static void create_stacklayout(ir_graph *irg)
assert(cconv != NULL);
/* construct argument type */
ident *const arg_type_id = id_mangle3("", get_entity_ident(entity), "_arg_type");
ident *const arg_type_id = new_id_fmt("%s_arg_type", get_entity_ident(entity));
ir_type *const arg_type = new_type_struct(arg_type_id);
for (unsigned p = 0, n_params = get_method_n_params(function_type);
p < n_params; ++p) {
......
......@@ -28,7 +28,7 @@ static ir_entity *create_trampoline(be_main_env_t *be, ir_entity *method)
{
ir_type *type = get_entity_type(method);
ident *old_id = get_entity_ld_ident(method);
ident *id = id_mangle3("", old_id, "$stub");
ident *id = new_id_fmt("%s$stub", old_id);
ir_type *parent = be->pic_trampolines_type;
ir_entity *ent = new_entity(parent, old_id, type);
set_entity_ld_ident(ent, id);
......@@ -54,7 +54,7 @@ static ir_entity *get_trampoline(be_main_env_t *env, ir_entity *method)
static ir_entity *create_pic_symbol(be_main_env_t *be, ir_entity *entity)
{
ident *old_id = get_entity_ld_ident(entity);
ident *id = id_mangle3("", old_id, "$non_lazy_ptr");
ident *id = new_id_fmt("%s$non_lazy_ptr", old_id);
ir_type *e_type = get_entity_type(entity);
ir_type *type = new_type_pointer(e_type);
ir_type *parent = be->pic_symbols_type;
......
......@@ -5906,7 +5906,7 @@ static void ia32_create_stacklayout(ir_graph *irg, const x86_cconv_t *cconv)
be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
/* construct argument type */
ident *arg_id = id_mangle3("", get_entity_ident(entity), "_arg_type");
ident *arg_id = new_id_fmt("%s_arg_type", get_entity_ident(entity));
ir_type *arg_type = new_type_struct(arg_id);
ir_type *frame_type = get_irg_frame_type(irg);
ir_entity *va_start_entity = NULL;
......
......@@ -220,7 +220,7 @@ static ir_type *compute_arg_type(ir_graph *irg, calling_convention_t *cconv,
ir_type *frame_type = get_irg_frame_type(irg);
size_t n_frame_members = get_compound_n_members(frame_type);
ir_type *const res = new_type_struct(id_mangle3("", get_entity_ident(entity), "_arg_type"));
ir_type *const res = new_type_struct(new_id_fmt("%s_arg_type", get_entity_ident(entity)));
/* search for existing value_param entities */
for (size_t f = n_frame_members; f-- > 0; ) {
......
......@@ -64,7 +64,6 @@ void ir_init(void)
init_mode();
init_tarval_2();
firm_init_op();
firm_init_mangle();
firm_init_reassociation();
firm_init_funccalls();
firm_init_inline();
......@@ -98,7 +97,6 @@ void ir_finish(void)
finish_tarval();
finish_mode();
finish_tpop();
firm_finish_mangle();
finish_ident();
}
......
......@@ -13,14 +13,19 @@
#include "hashptr.h"
#include "ident_t.h"
#include "obst.h"
#include "set.h"
static set *id_set;
/** An obstack used for temporary space */
static struct obstack id_obst;
void init_ident(void)
{
/* it's ok to use memcmp here, we check only strings */
id_set = new_set(memcmp, 128);
obstack_init(&id_obst);
}
ident *new_id_from_chars(const char *str, size_t len)
......@@ -35,6 +40,24 @@ ident *new_id_from_str(const char *str)
return new_id_from_chars(str, strlen(str));
}
static ident *new_ident_from_obst(struct obstack *const obst)
{
size_t const len = obstack_object_size(obst);
char *const string = (char*)obstack_finish(obst);
ident *const res = new_id_from_chars(string, len);
obstack_free(obst, string);
return res;
}
ident *new_id_fmt(char const *const fmt, ...)
{
va_list ap;
va_start(ap, fmt);
obstack_vprintf(&id_obst, fmt, ap);
va_end(ap);
return new_ident_from_obst(&id_obst);
}
const char *(get_id_str)(ident *id)
{
return get_id_str_(id);
......@@ -42,6 +65,7 @@ const char *(get_id_str)(ident *id)
void finish_ident(void)
{
obstack_free(&id_obst, NULL);
del_set(id_set);
id_set = NULL;
}
......
......@@ -30,11 +30,6 @@ void init_ident(void);
*/
void finish_ident(void);
/** initializes the name mangling code */
void firm_init_mangle(void);
void firm_finish_mangle(void);
#define NEW_IDENT(x) new_id_from_chars((x), sizeof(x) - 1)
#endif
/*
* This file is part of libFirm.
* Copyright (C) 2012 University of Karlsruhe.
*/
/**
* @file
* @brief Methods to manipulate names.
* @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
*/
#include "ident_t.h"
#include "obst.h"
/** An obstack used for temporary space */
static struct obstack mangle_obst;
static ident *new_ident_from_obst(struct obstack *obst)
{
size_t len = obstack_object_size(obst);
char *string = (char*)obstack_finish(obst);
ident *res = new_id_from_chars(string, len);
obstack_free(obst, string);
return res;
}
static void grow_string(char const *const s)
{
obstack_grow(&mangle_obst, s, strlen(s));
}
/** Returns a new ident that represents 'prefixscndsuffix'. */
ident *id_mangle3(char const *const prefix, ident *const middle, char const *const suffix)
{
grow_string(prefix);
grow_string(get_id_str(middle));
grow_string(suffix);
return new_ident_from_obst(&mangle_obst);
}
/** Returns a new ident that represents first<c>scnd. */
static ident *id_mangle_3(ident *first, char c, ident *scnd)
{
grow_string(first);
obstack_1grow(&mangle_obst, c);
grow_string(scnd);
return new_ident_from_obst(&mangle_obst);
}
/* Returns a new ident that represents first.scnd. */
ident *id_mangle_dot(ident *first, ident *scnd)
{
return id_mangle_3(first, '.', scnd);
}
void firm_init_mangle(void)
{
obstack_init(&mangle_obst);
}
void firm_finish_mangle(void)
{
obstack_free(&mangle_obst, NULL);
}
......@@ -280,7 +280,7 @@ static void copy_parameter_entities(ir_node *call, ir_graph *called_graph)
ir_type *old_type = get_entity_type(old_entity);
dbg_info *entity_dbgi = get_entity_dbg_info(old_entity);
ident *old_name = get_entity_ident(old_entity);
ident *name = id_mangle3("", old_name, "$inlined");
ident *name = new_id_fmt("%s$inlined", old_name);
ir_entity *new_ent = new_entity(frame_type, name, old_type);
set_entity_dbg_info(new_ent, entity_dbgi);
set_entity_link(old_entity, new_ent);
......
......@@ -245,9 +245,7 @@ static void collect_irg_calls(ir_node *call, void *env)
*/
static ident *get_clone_ident(ident *id, size_t pos, size_t nr)
{
char clone_postfix[32];
ir_snprintf(clone_postfix, sizeof(clone_postfix), "_cl_%zu_%zu", pos, nr);
return id_mangle3("", id, clone_postfix);
return new_id_fmt("%s_cl_%zu_%zu", id, pos, nr);
}
static inline ir_node *get_irn_copy(ir_node *const irn)
......
Supports Markdown
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