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)
62 if (!(ofd = fopen ("/tmp/test.s", "w")))
63 g_assert_not_reached ();
65 for (i = 0; id [i]; ++i) {
66 if (!isalnum (id [i]))
69 fprintf (ofd, "%c", id [i]);
73 for (i = 0; i < size; ++i)
74 fprintf (ofd, ".byte %d\n", (unsigned int) code [i]);
78 #define DIS_CMD "otool -V -v -t"
80 #define DIS_CMD "objdump -d"
82 system ("as /tmp/test.s -o /tmp/test.o;" DIS_CMD " /tmp/test.o");