add win32 C function mangling
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 19 Oct 2005 16:52:34 +0000 (16:52 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 19 Oct 2005 16:52:34 +0000 (16:52 +0000)
[r6759]

ir/tr/mangle.c
ir/tr/mangle.h

index 07a10fc..9cd6ad7 100644 (file)
@@ -53,7 +53,7 @@ mangle_entity (entity *ent)
 
 
 /* Returns a new ident that represents 'firstscnd'. */
-ident *mangle (ident *first, identscnd) {
+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)
index d8e2b42..099f62c 100644 (file)
  */
 
 /**
-* @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_ */