2 * helpers.c: Assorted routines
4 * (C) 2003 Ximian, Inc.
8 #include <mono/metadata/opcodes.h>
13 #define MINI_OP(a,b) b,
14 /* keep in sync with the enum in mini.h */
22 mono_inst_name (int op) {
23 if (op >= OP_LOAD && op <= OP_LAST)
24 return opnames [op - OP_LOAD];
26 return mono_opcode_names [op];
27 g_error ("unknown opcode name for %d", op);
32 mono_blockset_print (MonoCompile *cfg, MonoBitSet *set, const char *name, guint idom)
37 g_print ("%s:", name);
39 mono_bitset_foreach_bit (set, i, cfg->num_bblocks) {
41 g_print (" [BB%d]", cfg->bblocks [i]->block_num);
43 g_print (" BB%d", cfg->bblocks [i]->block_num);
50 * mono_disassemble_code:
51 * @code: a pointer to the code
52 * @size: the code size in bytes
54 * Disassemble to code to stdout.
57 mono_disassemble_code (guint8 *code, int size, char *id)
61 const char *tmp = g_get_tmp_dir ();
62 const char *objdump_args = g_getenv ("MONO_OBJDUMP_ARGS");
67 as_file = g_strdup_printf ("%s/test.s", tmp);
69 if (!(ofd = fopen (as_file, "w")))
70 g_assert_not_reached ();
72 for (i = 0; id [i]; ++i) {
73 if (!isalnum (id [i]))
76 fprintf (ofd, "%c", id [i]);
80 for (i = 0; i < size; ++i)
81 fprintf (ofd, ".byte %d\n", (unsigned int) code [i]);
85 #define DIS_CMD "otool -V -v -t"
87 #if defined(sparc) && !defined(__GNUC__)
90 #define DIS_CMD "objdump -d"
93 o_file = g_strdup_printf ("%s/test.o", tmp);
94 cmd = g_strdup_printf ("as %s -o %s", as_file, o_file);
100 cmd = g_strdup_printf (DIS_CMD " %s %s", objdump_args, o_file);