X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Fmangle.c;h=8f283600f6623f598e1b895ab5db7e0e675a21ec;hb=28e1715f2331a319bc8451941e043ac0534af7ac;hp=d842a69bf82aa11836b3dcc60688a7f37782ebc6;hpb=a53d7f8f2e862aeb0f316091558a8eab3e5b1e35;p=libfirm diff --git a/ir/tr/mangle.c b/ir/tr/mangle.c index d842a69bf..8f283600f 100644 --- a/ir/tr/mangle.c +++ b/ir/tr/mangle.c @@ -9,23 +9,26 @@ * Copyright: (c) 1998-2003 Universität Karlsruhe * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. */ - - - #ifdef HAVE_CONFIG_H -# include +# include "config.h" +#endif + +#ifdef HAVE_STDIO_H +# include #endif -# include "mangle.h" -# include "obst.h" +#include "mangle.h" +#include "obst.h" /* Make types visible to allow most efficient access */ -# include "entity_t.h" -# include "type_t.h" -# include "tpop_t.h" +#include "entity_t.h" +#include "type_t.h" +#include "tpop_t.h" +/** a obstack used for temporary space */ static struct obstack mangle_obst; +/** returned a mangled type name, currently no mangling */ static INLINE ident * mangle_type (type *tp) { @@ -41,7 +44,7 @@ mangle_entity (entity *ent) int len; ident *res; - type_id = mangle_type ((type *) ent->owner); + type_id = mangle_type(ent->owner); obstack_grow(&mangle_obst, get_id_str(type_id), get_id_strlen(type_id)); obstack_1grow(&mangle_obst,'_'); obstack_grow(&mangle_obst,get_id_str(ent->name),get_id_strlen(ent->name)); @@ -53,8 +56,8 @@ mangle_entity (entity *ent) } -/* Returns a new ident that represents firstscnd. */ -ident *mangle (ident *first, ident* scnd) { +/* Returns a new ident that represents 'firstscnd'. */ +ident *mangle (ident *first, ident *scnd) { char *cp; int len; ident *res; @@ -68,6 +71,22 @@ ident *mangle (ident *first, ident* scnd) { return res; } +/* Returns a new ident that represents 'prefixscndsuffix'. */ +static ident *mangle3(const char *prefix, ident *scnd, const char *suffix) { + char *cp; + int len; + ident *res; + + obstack_grow(&mangle_obst, prefix, strlen(prefix)); + obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd)); + obstack_grow(&mangle_obst, suffix, strlen(suffix)); + len = obstack_object_size (&mangle_obst); + cp = obstack_finish (&mangle_obst); + res = new_id_from_chars (cp, len); + obstack_free (&mangle_obst, cp); + return res; +} + /* Returns a new ident that represents first_scnd. */ ident *mangle_u (ident *first, ident* scnd) { char *cp; @@ -84,6 +103,31 @@ ident *mangle_u (ident *first, ident* scnd) { return res; } +/* returns a mangled name for a Win32 function using it's calling convention */ +ident *decorate_win32_c_fkt(entity *ent) { + type *tp = get_entity_type(ent); + unsigned cc_mask = get_method_calling_convention(tp); + char buf[16]; + int size, i; + + if (IS_CDECL(cc_mask)) + return mangle3("_", get_entity_ident(ent), ""); + else if (IS_STDCALL(cc_mask)) { + + size = 0; + for (i = get_method_n_params(tp) - 1; i >= 0; --i) { + size += get_type_size_bytes(get_method_param_type(tp, i)); + } + + snprintf(buf, sizeof(buf), "@%d", size); + + if (cc_mask & cc_reg_param) + return mangle3("@", get_entity_ident(ent), buf); + else + return mangle3("_", get_entity_ident(ent), buf); + } + return get_entity_ident(ent); +} void firm_init_mangle (void)