From 7481253cfeee6d29f432efcdfab42e4278b1154f Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 19 Oct 2005 16:52:34 +0000 Subject: [PATCH] add win32 C function mangling [r6759] --- ir/tr/mangle.c | 43 ++++++++++++++++++++++++++++++++++++++++++- ir/tr/mangle.h | 15 +++++++++------ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/ir/tr/mangle.c b/ir/tr/mangle.c index 07a10fc78..9cd6ad7a3 100644 --- a/ir/tr/mangle.c +++ b/ir/tr/mangle.c @@ -53,7 +53,7 @@ mangle_entity (entity *ent) /* Returns a new ident that represents 'firstscnd'. */ -ident *mangle (ident *first, ident* scnd) { +ident *mangle (ident *first, ident *scnd) { char *cp; int len; ident *res; @@ -67,6 +67,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; @@ -83,6 +99,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_entity_calling_convention(ent); + 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 & irg_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) diff --git a/ir/tr/mangle.h b/ir/tr/mangle.h index d8e2b427a..099f62c4c 100644 --- a/ir/tr/mangle.h +++ b/ir/tr/mangle.h @@ -11,12 +11,12 @@ */ /** -* @file mangle.h -* -* FIRM name mangling -- methods to manipulate names. -* -* @author Martin Trapp, Christian Schaefer -*/ + * @file mangle.h + * + * FIRM name mangling -- methods to manipulate names. + * + * @author Martin Trapp, Christian Schaefer + */ #ifndef _MANGLE_H_ #define _MANGLE_H_ @@ -38,4 +38,7 @@ ident *mangle_u (ident *first, ident* scnd); /** mangle: Returns a new ident that represents firstscnd. */ ident *mangle (ident *first, ident* scnd); +/** returns a mangled name for a Win32 function using it's calling convention */ +ident *decorate_win32_c_fkt(entity *ent); + #endif /* _MANGLE_H_ */ -- 2.20.1