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 = getenv("TMP");
68 as_file = g_strdup_printf ("%s/test.s", tmp);
70 if (!(ofd = fopen (as_file, "w")))
71 g_assert_not_reached ();
73 for (i = 0; id [i]; ++i) {
74 if (!isalnum (id [i]))
77 fprintf (ofd, "%c", id [i]);
81 for (i = 0; i < size; ++i)
82 fprintf (ofd, ".byte %d\n", (unsigned int) code [i]);
86 #define DIS_CMD "otool -V -v -t"
88 #define DIS_CMD "objdump -d"
90 o_file = g_strdup_printf ("%s/test.o", tmp);
91 cmd = g_strdup_printf ("as %s -o %s", as_file, o_file);
94 cmd = g_strdup_printf (DIS_CMD " %s", o_file);