X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fhelpers.c;h=2a0b7d9e0e1d826125da9451cad191f441d99ec8;hb=ec3740aa803f594718e5080f733bd2b5988f7d4d;hp=f3c4ae770062a7f62390f4366980654d85914583;hpb=3d693eeb90339833968d66c3dc9fde2fa3ba2cef;p=mono.git diff --git a/mono/mini/helpers.c b/mono/mini/helpers.c index f3c4ae77006..2a0b7d9e0e1 100644 --- a/mono/mini/helpers.c +++ b/mono/mini/helpers.c @@ -7,52 +7,78 @@ #include #include -#ifndef PLATFORM_WIN32 +#ifndef HOST_WIN32 #include #endif +#ifndef DISABLE_LOGGING + #ifdef MINI_OP #undef MINI_OP #endif +#ifdef MINI_OP3 +#undef MINI_OP3 +#endif #ifdef HAVE_ARRAY_ELEM_INIT #define MSGSTRFIELD(line) MSGSTRFIELD1(line) #define MSGSTRFIELD1(line) str##line static const struct msgstr_t { -#define MINI_OP(a,b) char MSGSTRFIELD(__LINE__) [sizeof (b)]; +#define MINI_OP(a,b,dest,src1,src2) char MSGSTRFIELD(__LINE__) [sizeof (b)]; +#define MINI_OP3(a,b,dest,src1,src2,src3) char MSGSTRFIELD(__LINE__) [sizeof (b)]; #include "mini-ops.h" #undef MINI_OP +#undef MINI_OP3 } opstr = { -#define MINI_OP(a,b) b, +#define MINI_OP(a,b,dest,src1,src2) b, +#define MINI_OP3(a,b,dest,src1,src2,src3) b, #include "mini-ops.h" #undef MINI_OP +#undef MINI_OP3 }; static const gint16 opidx [] = { -#define MINI_OP(a,b) [a - OP_LOAD] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)), +#define MINI_OP(a,b,dest,src1,src2) [a - OP_LOAD] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)), +#define MINI_OP3(a,b,dest,src1,src2,src3) [a - OP_LOAD] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)), #include "mini-ops.h" #undef MINI_OP +#undef MINI_OP3 }; #else -#define MINI_OP(a,b) b, +#define MINI_OP(a,b,dest,src1,src2) b, +#define MINI_OP3(a,b,dest,src1,src2,src3) b, /* keep in sync with the enum in mini.h */ static const char* const opnames[] = { #include "mini-ops.h" }; #undef MINI_OP +#undef MINI_OP3 #endif +#endif /* DISABLE_LOGGING */ + #if defined(__i386__) || defined(__x86_64__) #define emit_debug_info TRUE #else #define emit_debug_info FALSE #endif +/*This enables us to use the right tooling when building the cross compiler for iOS.*/ +#if defined (__APPLE__) && defined (TARGET_ARM) && (defined(__i386__) || defined(__x86_64__)) + +#define ARCH_PREFIX "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/" + +#endif + +#define ARCH_PREFIX "" +//#define ARCH_PREFIX "powerpc64-linux-gnu-" + const char* mono_inst_name (int op) { +#ifndef DISABLE_LOGGING if (op >= OP_LOAD && op <= OP_LAST) #ifdef HAVE_ARRAY_ELEM_INIT return (const char*)&opstr + opidx [op - OP_LOAD]; @@ -63,6 +89,9 @@ mono_inst_name (int op) { return mono_opcode_name (op); g_error ("unknown opcode name for %d", op); return NULL; +#else + g_assert_not_reached (); +#endif } void @@ -100,15 +129,16 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id) GHashTable *offset_to_bb_hash = NULL; int i, cindex, bb_num; FILE *ofd; -#ifdef PLATFORM_WIN32 +#ifdef HOST_WIN32 const char *tmp = g_get_tmp_dir (); #endif const char *objdump_args = g_getenv ("MONO_OBJDUMP_ARGS"); char *as_file; char *o_file; char *cmd; + int unused; -#ifdef PLATFORM_WIN32 +#ifdef HOST_WIN32 as_file = g_strdup_printf ("%s/test.s", tmp); if (!(ofd = fopen (as_file, "w"))) @@ -120,14 +150,16 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id) #endif for (i = 0; id [i]; ++i) { - if (!isalnum (id [i])) + if (i == 0 && isdigit (id [i])) + fprintf (ofd, "_"); + else if (!isalnum (id [i])) fprintf (ofd, "_"); else fprintf (ofd, "%c", id [i]); } fprintf (ofd, ":\n"); - if (emit_debug_info) { + if (emit_debug_info && cfg != NULL) { MonoBasicBlock *bb; fprintf (ofd, ".stabs \"\",100,0,0,.Ltext0\n"); @@ -142,7 +174,7 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id) cindex = 0; for (i = 0; i < size; ++i) { - if (emit_debug_info) { + if (emit_debug_info && cfg != NULL) { bb_num = GPOINTER_TO_INT (g_hash_table_lookup (offset_to_bb_hash, GINT_TO_POINTER (i))); if (bb_num) { fprintf (ofd, "\n.stabd 68,0,%d\n", bb_num - 1); @@ -160,8 +192,13 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id) } fprintf (ofd, "\n"); fclose (ofd); + #ifdef __APPLE__ +#ifdef __ppc64__ +#define DIS_CMD "otool64 -v -t" +#else #define DIS_CMD "otool -v -t" +#endif #else #if defined(sparc) && !defined(__GNUC__) #define DIS_CMD "dis" @@ -174,31 +211,67 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id) #if defined(sparc) #define AS_CMD "as -xarch=v9" -#elif defined(__i386__) || defined(__x86_64__) -#define AS_CMD "as -gstabs" -#elif defined(__mips__) +#elif defined (TARGET_X86) +# if defined(__APPLE__) +# define AS_CMD "as -arch i386" +# else +# define AS_CMD "as -gstabs" +# endif +#elif defined (TARGET_AMD64) +# if defined (__APPLE__) +# define AS_CMD "as -arch x86_64" +# else +# define AS_CMD "as -gstabs" +# endif +#elif defined (TARGET_ARM) +# if defined (__APPLE__) +# define AS_CMD "as -arch arm" +# else +# define AS_CMD "as -gstabs" +# endif +#elif defined(__mips__) && (_MIPS_SIM == _ABIO32) #define AS_CMD "as -mips32" +#elif defined(__ppc64__) +#define AS_CMD "as -arch ppc64" +#elif defined(__powerpc64__) +#define AS_CMD "as -mppc64" #else #define AS_CMD "as" #endif -#ifdef PLATFORM_WIN32 +#ifdef HOST_WIN32 o_file = g_strdup_printf ("%s/test.o", tmp); #else i = g_file_open_tmp (NULL, &o_file, NULL); close (i); #endif - cmd = g_strdup_printf (AS_CMD " %s -o %s", as_file, o_file); - system (cmd); + cmd = g_strdup_printf (ARCH_PREFIX AS_CMD " %s -o %s", as_file, o_file); + unused = system (cmd); g_free (cmd); if (!objdump_args) objdump_args = ""; + + fflush (stdout); + +#ifdef __arm__ + /* + * The arm assembler inserts ELF directives instructing objdump to display + * everything as data. + */ + cmd = g_strdup_printf (ARCH_PREFIX "strip -x %s", o_file); + unused = system (cmd); + g_free (cmd); +#endif - cmd = g_strdup_printf (DIS_CMD " %s %s", objdump_args, o_file); - system (cmd); + cmd = g_strdup_printf (ARCH_PREFIX DIS_CMD " %s %s", objdump_args, o_file); + unused = system (cmd); g_free (cmd); +#ifndef HOST_WIN32 + unlink (o_file); + unlink (as_file); +#endif g_free (o_file); g_free (as_file); #endif