summaryrefslogtreecommitdiffhomepage
path: root/src/codedump.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-05-24 15:19:06 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-07-30 22:57:54 +0900
commit891839b976c75c77f238931123ac472e3284e95d (patch)
treebbecccdb4cea0f3272a966e39cdfebfda7eb5295 /src/codedump.c
parentb09d2eb90074c50ed83d4d10d3fe0393bc9e43da (diff)
downloadmruby-891839b976c75c77f238931123ac472e3284e95d.tar.gz
mruby-891839b976c75c77f238931123ac472e3284e95d.zip
New bytecode implementation of mruby VM.
Diffstat (limited to 'src/codedump.c')
-rw-r--r--src/codedump.c772
1 files changed, 412 insertions, 360 deletions
diff --git a/src/codedump.c b/src/codedump.c
index d79a65a70..22cbc59eb 100644
--- a/src/codedump.c
+++ b/src/codedump.c
@@ -6,451 +6,503 @@
#include <mruby/proc.h>
#ifndef MRB_DISABLE_STDIO
-static int
-print_r(mrb_state *mrb, mrb_irep *irep, size_t n, int pre)
+static void
+print_r(mrb_state *mrb, mrb_irep *irep, size_t n)
{
size_t i;
- if (n == 0) return 0;
+ if (n == 0) return;
for (i=0; i+1<irep->nlocals; i++) {
if (irep->lv[i].r == n) {
mrb_sym sym = irep->lv[i].name;
- if (pre) printf(" ");
- printf("R%d:%s", (int)n, mrb_sym2name(mrb, sym));
- return 1;
+ printf(" R%d:%s", (int)n, mrb_sym2name(mrb, sym));
}
}
- return 0;
}
-#define RA 1
-#define RB 2
-#define RAB 3
-
static void
-print_lv(mrb_state *mrb, mrb_irep *irep, mrb_code c, int r)
+print_lv_a(mrb_state *mrb, mrb_irep *irep, uint16_t a)
{
- int pre = 0;
-
- if (!irep->lv
- || ((!(r & RA) || GETARG_A(c) >= irep->nlocals)
- && (!(r & RB) || GETARG_B(c) >= irep->nlocals))) {
+ if (!irep->lv || a >= irep->nlocals || a == 0) {
printf("\n");
return;
}
- printf("\t; ");
- if (r & RA) {
- pre = print_r(mrb, irep, GETARG_A(c), 0);
- }
- if (r & RB) {
- print_r(mrb, irep, GETARG_B(c), pre);
+ printf("\t;");
+ print_r(mrb, irep, a);
+ printf("\n");
+}
+
+static void
+print_lv_ab(mrb_state *mrb, mrb_irep *irep, uint16_t a, uint16_t b)
+{
+ if (!irep->lv || (a >= irep->nlocals && b >= irep->nlocals) || a+b == 0) {
+ printf("\n");
+ return;
}
+ printf("\t;");
+ if (a > 0) print_r(mrb, irep, a);
+ if (b > 0) print_r(mrb, irep, b);
printf("\n");
}
#endif
static void
+print_header(mrb_irep *irep, int i)
+{
+ int32_t line;
+
+ line = mrb_debug_get_line(irep, i);
+ if (line < 0) {
+ printf(" ");
+ }
+ else {
+ printf("%5d ", line);
+ }
+
+ printf("%03d ", i);
+}
+
+#define CASE(insn,ops) case insn: FETCH_ ## ops (); L_ ## insn
+
+static void
codedump(mrb_state *mrb, mrb_irep *irep)
{
#ifndef MRB_DISABLE_STDIO
- int i;
int ai;
- mrb_code c;
+ mrb_code *pc, *pcend;
+ mrb_code ins;
const char *file = NULL, *next_file;
- int32_t line;
if (!irep) return;
printf("irep %p nregs=%d nlocals=%d pools=%d syms=%d reps=%d\n", (void*)irep,
irep->nregs, irep->nlocals, (int)irep->plen, (int)irep->slen, (int)irep->rlen);
- for (i = 0; i < (int)irep->ilen; i++) {
+ pc = irep->iseq;
+ pcend = pc + irep->ilen;
+ while (pc < pcend) {
+ int i;
+ uint32_t a;
+ uint16_t b;
+ uint8_t c;
+
ai = mrb_gc_arena_save(mrb);
+ i = pc - irep->iseq;
next_file = mrb_debug_get_filename(irep, i);
if (next_file && file != next_file) {
printf("file: %s\n", next_file);
file = next_file;
}
- line = mrb_debug_get_line(irep, i);
- if (line < 0) {
- printf(" ");
- }
- else {
- printf("%5d ", line);
- }
-
- printf("%03d ", i);
- c = irep->iseq[i];
- switch (GET_OPCODE(c)) {
- case OP_NOP:
+ print_header(irep, i);
+ ins = READ_B();
+ switch (ins) {
+ CASE(OP_NOP, Z):
printf("OP_NOP\n");
break;
- case OP_MOVE:
- printf("OP_MOVE\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_MOVE, BB):
+ printf("OP_MOVE\tR%d\tR%d\t", a, b);
+ print_lv_ab(mrb, irep, a, b);
break;
- case OP_LOADL:
+ CASE(OP_LOADL, BB):
{
- mrb_value v = irep->pool[GETARG_Bx(c)];
+ mrb_value v = irep->pool[b];
mrb_value s = mrb_inspect(mrb, v);
- printf("OP_LOADL\tR%d\tL(%d)\t; %s", GETARG_A(c), GETARG_Bx(c), RSTRING_PTR(s));
+ printf("OP_LOADL\tR%d\tL(%d)\t; %s", a, b, RSTRING_PTR(s));
}
- print_lv(mrb, irep, c, RA);
- break;
- case OP_LOADI:
- printf("OP_LOADI\tR%d\t%d\t", GETARG_A(c), GETARG_sBx(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_LOADSYM:
- printf("OP_LOADSYM\tR%d\t:%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_LOADNIL:
- printf("OP_LOADNIL\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_LOADSELF:
- printf("OP_LOADSELF\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_LOADT:
- printf("OP_LOADT\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_LOADF:
- printf("OP_LOADF\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_GETGLOBAL:
- printf("OP_GETGLOBAL\tR%d\t:%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_SETGLOBAL:
- printf("OP_SETGLOBAL\t:%s\tR%d\t",
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
- GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_GETCONST:
- printf("OP_GETCONST\tR%d\t:%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_SETCONST:
- printf("OP_SETCONST\t:%s\tR%d\t",
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
- GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_GETMCNST:
- printf("OP_GETMCNST\tR%d\tR%d::%s", GETARG_A(c), GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
- print_lv(mrb, irep, c, RAB);
- break;
- case OP_SETMCNST:
- printf("OP_SETMCNST\tR%d::%s\tR%d", GETARG_A(c)+1,
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
- GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_GETIV:
- printf("OP_GETIV\tR%d\t%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_SETIV:
- printf("OP_SETIV\t%s\tR%d",
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
- GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_GETUPVAR:
- printf("OP_GETUPVAR\tR%d\t%d\t%d",
- GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_SETUPVAR:
- printf("OP_SETUPVAR\tR%d\t%d\t%d",
- GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_GETCV:
- printf("OP_GETCV\tR%d\t%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_SETCV:
- printf("OP_SETCV\t%s\tR%d",
- mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
- GETARG_A(c));
- print_lv(mrb, irep, c, RA);
- break;
- case OP_JMP:
- printf("OP_JMP\t%03d (%d)\n", i+GETARG_sBx(c), GETARG_sBx(c));
- break;
- case OP_JMPIF:
- printf("OP_JMPIF\tR%d\t%03d (%d)\n", GETARG_A(c), i+GETARG_sBx(c), GETARG_sBx(c));
- break;
- case OP_JMPNOT:
- printf("OP_JMPNOT\tR%d\t%03d (%d)\n", GETARG_A(c), i+GETARG_sBx(c), GETARG_sBx(c));
- break;
- case OP_SEND:
- printf("OP_SEND\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_SENDB:
- printf("OP_SENDB\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_CALL:
- printf("OP_CALL\tR%d\n", GETARG_A(c));
- break;
- case OP_TAILCALL:
- printf("OP_TAILCALL\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_SUPER:
- printf("OP_SUPER\tR%d\t%d\n", GETARG_A(c),
- GETARG_C(c));
- break;
- case OP_ARGARY:
- printf("OP_ARGARY\tR%d\t%d:%d:%d:%d", GETARG_A(c),
- (GETARG_Bx(c)>>10)&0x3f,
- (GETARG_Bx(c)>>9)&0x1,
- (GETARG_Bx(c)>>4)&0x1f,
- (GETARG_Bx(c)>>0)&0xf);
- print_lv(mrb, irep, c, RA);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADI, BB):
+ printf("OP_LOADI\tR%d\t%d\t", a, b);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADINEG, BB):
+ printf("OP_LOADI\tR%d\t-%d\t", a, b);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADI__1, B):
+ printf("OP_LOADI__1\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADI_0, B): goto L_LOADI;
+ CASE(OP_LOADI_1, B): goto L_LOADI;
+ CASE(OP_LOADI_2, B): goto L_LOADI;
+ CASE(OP_LOADI_3, B): goto L_LOADI;
+ CASE(OP_LOADI_4, B): goto L_LOADI;
+ CASE(OP_LOADI_5, B): goto L_LOADI;
+ CASE(OP_LOADI_6, B): goto L_LOADI;
+ CASE(OP_LOADI_7, B):
+ L_LOADI:
+ printf("OP_LOADI_%d\tR%d\t\t", ins-(int)OP_LOADI_0, a);
+ print_lv_a(mrb, irep, a);
break;
-
- case OP_ENTER:
+ CASE(OP_LOADSYM, BB):
+ printf("OP_LOADSYM\tR%d\t:%s\t", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADNIL, B):
+ printf("OP_LOADNIL\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADSELF, B):
+ printf("OP_LOADSELF\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADT, B):
+ printf("OP_LOADT\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LOADF, B):
+ printf("OP_LOADF\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETGV, BB):
+ printf("OP_GETGV\tR%d\t:%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETGV, BB):
+ printf("OP_SETGV\t:%s\tR%d", mrb_sym2name(mrb, irep->syms[b]), a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETSV, BB):
+ printf("OP_GETSV\tR%d\t:%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETSV, BB):
+ printf("OP_SETSV\t:%s\tR%d", mrb_sym2name(mrb, irep->syms[b]), a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETCONST, BB):
+ printf("OP_GETCONST\tR%d\t:%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETCONST, BB):
+ printf("OP_SETCONST\t:%s\tR%d", mrb_sym2name(mrb, irep->syms[b]), a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETMCNST, BB):
+ printf("OP_GETMCNST\tR%d\tR%d::%s", a, a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETMCNST, BB):
+ printf("OP_SETMCNST\tR%d::%s\tR%d", a+1, mrb_sym2name(mrb, irep->syms[b]), a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETIV, BB):
+ printf("OP_GETIV\tR%d\t%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETIV, BB):
+ printf("OP_SETIV\t%s\tR%d", mrb_sym2name(mrb, irep->syms[b]), a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETUPVAR, BBB):
+ printf("OP_GETUPVAR\tR%d\t%d\t%d", a, b, c);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETUPVAR, BBB):
+ printf("OP_SETUPVAR\tR%d\t%d\t%d", a, b, c);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_GETCV, BB):
+ printf("OP_GETCV\tR%d\t%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SETCV, BB):
+ printf("OP_SETCV\t%s\tR%d", mrb_sym2name(mrb, irep->syms[b]), a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_JMP, S):
+ printf("OP_JMP\t\t%03d\n", a);
+ break;
+ CASE(OP_JMPIF, BS):
+ printf("OP_JMPIF\tR%d\t%03d\t", a, b);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_JMPNOT, BS):
+ printf("OP_JMPNOT\tR%d\t%03d\t", a, b);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_JMPNIL, BS):
+ printf("OP_JMPNIL\tR%d\t%03d\t", a, b);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_SENDV, BB):
+ printf("OP_SENDV\tR%d\t:%s\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_SENDVB, BB):
+ printf("OP_SENDVB\tR%d\t:%s\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_SEND, BBB):
+ printf("OP_SEND\tR%d\t:%s\t%d\n", a, mrb_sym2name(mrb, irep->syms[b]), c);
+ break;
+ CASE(OP_SENDB, BBB):
+ printf("OP_SENDB\tR%d\t:%s\t%d\n", a, mrb_sym2name(mrb, irep->syms[b]), c);
+ break;
+ CASE(OP_CALL, Z):
+ printf("OP_CALL\n");
+ break;
+ CASE(OP_SUPER, BB):
+ printf("OP_SUPER\tR%d\t%d\n", a, b);
+ break;
+ CASE(OP_ARGARY, BS):
+ printf("OP_ARGARY\tR%d\t%d:%d:%d:%d", a,
+ (b>>10)&0x3f,
+ (b>>9)&0x1,
+ (b>>4)&0x1f,
+ (b>>0)&0xf);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_ENTER, W):
printf("OP_ENTER\t%d:%d:%d:%d:%d:%d:%d\n",
- (GETARG_Ax(c)>>18)&0x1f,
- (GETARG_Ax(c)>>13)&0x1f,
- (GETARG_Ax(c)>>12)&0x1,
- (GETARG_Ax(c)>>7)&0x1f,
- (GETARG_Ax(c)>>2)&0x1f,
- (GETARG_Ax(c)>>1)&0x1,
- GETARG_Ax(c) & 0x1);
- break;
- case OP_RETURN:
- printf("OP_RETURN\tR%d", GETARG_A(c));
- switch (GETARG_B(c)) {
- case OP_R_NORMAL:
- printf("\tnormal\t"); break;
- case OP_R_RETURN:
- printf("\treturn\t"); break;
- case OP_R_BREAK:
- printf("\tbreak\t"); break;
- default:
- printf("\tbroken\t"); break;
- }
- print_lv(mrb, irep, c, RA);
+ (a>>18)&0x1f,
+ (a>>13)&0x1f,
+ (a>>12)&0x1,
+ (a>>7)&0x1f,
+ (a>>2)&0x1f,
+ (a>>1)&0x1,
+ a & 0x1);
break;
- case OP_BLKPUSH:
- printf("OP_BLKPUSH\tR%d\t%d:%d:%d:%d", GETARG_A(c),
- (GETARG_Bx(c)>>10)&0x3f,
- (GETARG_Bx(c)>>9)&0x1,
- (GETARG_Bx(c)>>4)&0x1f,
- (GETARG_Bx(c)>>0)&0xf);
- print_lv(mrb, irep, c, RA);
+ CASE(OP_KARG, BB):
+ printf("OP_KARG\tR(%d)\tK(%d)\n", a, b);
break;
-
- case OP_LAMBDA:
- printf("OP_LAMBDA\tR%d\tI(%+d)\t", GETARG_A(c), GETARG_b(c)+1);
- switch (GETARG_c(c)) {
- case OP_L_METHOD:
- printf("method"); break;
- case OP_L_BLOCK:
- printf("block"); break;
- case OP_L_LAMBDA:
- printf("lambda"); break;
- }
- print_lv(mrb, irep, c, RA);
+ CASE(OP_KARG2, BB):
+ printf("OP_KARG2\tR(%d)\tK(%d)\n", a, b);
break;
- case OP_RANGE:
- printf("OP_RANGE\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_KDICT, B):
+ printf("OP_KDICt\tR(%d)\n", a);
break;
- case OP_METHOD:
- printf("OP_METHOD\tR%d\t:%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_RETURN, B):
+ printf("OP_RETURN\tR%d", a);
+ print_lv_a(mrb, irep, a);
break;
-
- case OP_ADD:
- printf("OP_ADD\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_ADDI:
- printf("OP_ADDI\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_SUB:
- printf("OP_SUB\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_SUBI:
- printf("OP_SUBI\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_MUL:
- printf("OP_MUL\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_DIV:
- printf("OP_DIV\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_LT:
- printf("OP_LT\t\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_LE:
- printf("OP_LE\t\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_GT:
- printf("OP_GT\t\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_GE:
- printf("OP_GE\t\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
- break;
- case OP_EQ:
- printf("OP_EQ\t\tR%d\t:%s\t%d\n", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
- GETARG_C(c));
+ CASE(OP_RETURN_BLK, B):
+ printf("OP_RETURN_BLK\tR%d", a);
+ print_lv_a(mrb, irep, a);
break;
-
- case OP_STOP:
- printf("OP_STOP\n");
+ CASE(OP_BREAK, B):
+ printf("OP_BREAK\tR%d", a);
+ print_lv_a(mrb, irep, a);
break;
-
- case OP_ARRAY:
- printf("OP_ARRAY\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_BLKPUSH, BS):
+ printf("OP_BLKPUSH\tR%d\t%d:%d:%d:%d", a,
+ (b>>10)&0x3f,
+ (b>>9)&0x1,
+ (b>>4)&0x1f,
+ (b>>0)&0xf);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_LAMBDA, BB):
+ printf("OP_LAMBDA\tR%d\tI(%d:%p)\n", a, b, irep->reps[b]);
+ break;
+ CASE(OP_BLOCK, BB):
+ printf("OP_BLOCK\tR%d\tI(%d:%p)\n", a, b, irep->reps[b]);
+ break;
+ CASE(OP_METHOD, BB):
+ printf("OP_METHOD\tR%d\tI(%d:%p)\n", a, b, irep->reps[b]);
+ break;
+ CASE(OP_RANGE_INC, B):
+ printf("OP_RANGE_INC\tR%d\n", a);
+ break;
+ CASE(OP_RANGE_EXC, B):
+ printf("OP_RANGE_EXC\tR%d\n", a);
+ break;
+ CASE(OP_DEF, BB):
+ printf("OP_DEF\tR%d\t:%s\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_UNDEF, B):
+ printf("OP_UNDEF\t:%s\n", mrb_sym2name(mrb, irep->syms[a]));
+ break;
+ CASE(OP_ALIAS, BB):
+ printf("OP_ALIAS\t:%s\t%s\n", mrb_sym2name(mrb, irep->syms[a]), mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_ADD, BB):
+ printf("OP_ADD\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_ADDI, BBB):
+ printf("OP_ADDI\tR%d\t:%s\t%d\n", a, mrb_sym2name(mrb, irep->syms[b]), c);
+ break;
+ CASE(OP_SUB, BB):
+ printf("OP_SUB\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_SUBI, BBB):
+ printf("OP_SUBI\tR%d\t:%s\t%d\n", a, mrb_sym2name(mrb, irep->syms[b]), c);
+ break;
+ CASE(OP_MUL, BB):
+ printf("OP_MUL\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_DIV, BB):
+ printf("OP_DIV\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_LT, BB):
+ printf("OP_LT\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_LE, BB):
+ printf("OP_LE\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_GT, BB):
+ printf("OP_GT\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_GE, BB):
+ printf("OP_GE\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
+ break;
+ CASE(OP_EQ, BB):
+ printf("OP_EQ\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b]));
break;
- case OP_ARYCAT:
- printf("OP_ARYCAT\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_ARRAY, BB):
+ printf("OP_ARRAY\tR%d\t%d\t", a, b);
+ print_lv_a(mrb, irep, a);
break;
- case OP_ARYPUSH:
- printf("OP_ARYPUSH\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_ARRAY2, BBB):
+ printf("OP_ARRAY\tR%d\tR%d\t%d\t", a, b, c);
+ print_lv_ab(mrb, irep, a, b);
break;
- case OP_AREF:
- printf("OP_AREF\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_ARYCAT, B):
+ printf("OP_ARYCAT\tR%d\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_APOST:
- printf("OP_APOST\tR%d\t%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_ARYPUSH, B):
+ printf("OP_ARYPUSH\tR%d\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_STRING:
+ CASE(OP_ARYDUP, B):
+ printf("OP_ARYDUP\tR%d\t", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_AREF, BBB):
+ printf("OP_AREF\tR%d\tR%d\t%d", a, b, c);
+ print_lv_ab(mrb, irep, a, b);
+ break;
+ CASE(OP_ASET, BBB):
+ printf("OP_ASET\tR%d\tR%d\t%d", a, b, c);
+ print_lv_ab(mrb, irep, a, b);
+ break;
+ CASE(OP_APOST, BBB):
+ printf("OP_APOST\tR%d\t%d\t%d", a, b, c);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_INTERN, B):
+ printf("OP_INTERN\tR%d", a);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_STRING, BB):
{
- mrb_value v = irep->pool[GETARG_Bx(c)];
+ mrb_value v = irep->pool[b];
mrb_value s = mrb_str_dump(mrb, mrb_str_new(mrb, RSTRING_PTR(v), RSTRING_LEN(v)));
- printf("OP_STRING\tR%d\tL(%d)\t; %s", GETARG_A(c), GETARG_Bx(c), RSTRING_PTR(s));
+ printf("OP_STRING\tR%d\tL(%d)\t; %s", a, b, RSTRING_PTR(s));
}
- print_lv(mrb, irep, c, RA);
+ print_lv_a(mrb, irep, a);
+ break;
+ CASE(OP_STRCAT, B):
+ printf("OP_STRCAT\tR%d\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_STRCAT:
- printf("OP_STRCAT\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_HASH, BB):
+ printf("OP_HASH\tR%d\t%d\t", a, b);
+ print_lv_a(mrb, irep, a);
break;
- case OP_HASH:
- printf("OP_HASH\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_HASHADD, BB):
+ printf("OP_HASHADD\tR%d\t%d", a, b);
+ print_lv_a(mrb, irep, a);
break;
- case OP_OCLASS:
- printf("OP_OCLASS\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_OCLASS, B):
+ printf("OP_OCLASS\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_CLASS:
- printf("OP_CLASS\tR%d\t:%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_CLASS, BB):
+ printf("OP_CLASS\tR%d\t:%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
break;
- case OP_MODULE:
- printf("OP_MODULE\tR%d\t:%s", GETARG_A(c),
- mrb_sym2name(mrb, irep->syms[GETARG_B(c)]));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_MODULE, BB):
+ printf("OP_MODULE\tR%d\t:%s", a, mrb_sym2name(mrb, irep->syms[b]));
+ print_lv_a(mrb, irep, a);
break;
- case OP_EXEC:
- printf("OP_EXEC\tR%d\tI(%+d)", GETARG_A(c), GETARG_Bx(c)+1);
- print_lv(mrb, irep, c, RA);
+ CASE(OP_EXEC, BB):
+ printf("OP_EXEC\tR%d\tI(%d:%p)", a, b, irep->reps[b]);
+ print_lv_a(mrb, irep, a);
break;
- case OP_SCLASS:
- printf("OP_SCLASS\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
- print_lv(mrb, irep, c, RAB);
+ CASE(OP_SCLASS, B):
+ printf("OP_SCLASS\tR%d\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_TCLASS:
- printf("OP_TCLASS\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_TCLASS, B):
+ printf("OP_TCLASS\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_ERR:
+ CASE(OP_ERR, B):
{
- mrb_value v = irep->pool[GETARG_Bx(c)];
+ mrb_value v = irep->pool[a];
mrb_value s = mrb_str_dump(mrb, mrb_str_new(mrb, RSTRING_PTR(v), RSTRING_LEN(v)));
printf("OP_ERR\t%s\n", RSTRING_PTR(s));
}
break;
- case OP_EPUSH:
- printf("OP_EPUSH\t:I(%+d)\n", GETARG_Bx(c)+1);
+ CASE(OP_EPUSH, B):
+ printf("OP_EPUSH\t\t:I(%d:%p)\n", a, irep->reps[a]);
break;
- case OP_ONERR:
- printf("OP_ONERR\t%03d\n", i+GETARG_sBx(c));
+ CASE(OP_ONERR, S):
+ printf("OP_ONERR\t%03d\n", a);
break;
- case OP_RESCUE:
- {
- int a = GETARG_A(c);
- int b = GETARG_B(c);
- int cnt = GETARG_C(c);
-
- if (b == 0) {
- printf("OP_RESCUE\tR%d\t\t%s", a, cnt ? "cont" : "");
- print_lv(mrb, irep, c, RA);
- break;
- }
- else {
- printf("OP_RESCUE\tR%d\tR%d\t%s", a, b, cnt ? "cont" : "");
- print_lv(mrb, irep, c, RAB);
- break;
- }
- }
+ CASE(OP_EXCEPT, B):
+ printf("OP_EXCEPT\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_RAISE:
- printf("OP_RAISE\tR%d\t\t", GETARG_A(c));
- print_lv(mrb, irep, c, RA);
+ CASE(OP_RESCUE, BB):
+ printf("OP_RESCUE\tR%d\tR%d", a, b);
+ print_lv_ab(mrb, irep, a, b);
break;
- case OP_POPERR:
- printf("OP_POPERR\t%d\t\t\n", GETARG_A(c));
+ CASE(OP_RAISE, B):
+ printf("OP_RAISE\tR%d\t\t", a);
+ print_lv_a(mrb, irep, a);
break;
- case OP_EPOP:
- printf("OP_EPOP\t%d\n", GETARG_A(c));
+ CASE(OP_POPERR, B):
+ printf("OP_POPERR\t%d\t\t\n", a);
+ break;
+ CASE(OP_EPOP, B):
+ printf("OP_EPOP\t%d\n", a);
break;
+ CASE(OP_DEBUG, BBB):
+ printf("OP_DEBUG\t%d\t%d\t%d\n", a, b, c);
+ break;
+
+ CASE(OP_STOP, Z):
+ printf("OP_STOP\n");
+ break;
+
+ CASE(OP_EXT1, Z):
+ ins = READ_B();
+ printf("OP_EXT1\n");
+ print_header(irep, pc-irep->iseq-2);
+ switch (ins) {
+#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); goto L_OP_ ## i;
+#include "mruby/ops.h"
+#undef OPCODE
+ }
+ break;
+ CASE(OP_EXT2, Z):
+ ins = READ_B();
+ printf("OP_EXT2\n");
+ print_header(irep, pc-irep->iseq-2);
+ switch (ins) {
+#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); goto L_OP_ ## i;
+#include "mruby/ops.h"
+#undef OPCODE
+ }
+ break;
+ CASE(OP_EXT3, Z):
+ ins = READ_B();
+ printf("OP_EXT3\n");
+ print_header(irep, pc-irep->iseq-2);
+ switch (ins) {
+#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); goto L_OP_ ## i;
+#include "mruby/ops.h"
+#undef OPCODE
+ }
+ break;
+
default:
- printf("OP_unknown %d\t%d\t%d\t%d\n", GET_OPCODE(c),
- GETARG_A(c), GETARG_B(c), GETARG_C(c));
+ printf("OP_unknown (0x%x)\n", ins);
break;
}
mrb_gc_arena_restore(mrb, ai);