[331] | 1 | #include <mruby.h>
|
---|
| 2 | #include <mruby/irep.h>
|
---|
| 3 | #include <mruby/debug.h>
|
---|
| 4 | #include <mruby/opcode.h>
|
---|
| 5 | #include <mruby/string.h>
|
---|
| 6 | #include <mruby/proc.h>
|
---|
[270] | 7 |
|
---|
| 8 | #ifndef MRB_DISABLE_STDIO
|
---|
| 9 | static int
|
---|
| 10 | print_r(mrb_state *mrb, mrb_irep *irep, size_t n, int pre)
|
---|
| 11 | {
|
---|
| 12 | size_t i;
|
---|
| 13 |
|
---|
| 14 | if (n == 0) return 0;
|
---|
| 15 |
|
---|
| 16 | for (i=0; i+1<irep->nlocals; i++) {
|
---|
| 17 | if (irep->lv[i].r == n) {
|
---|
| 18 | mrb_sym sym = irep->lv[i].name;
|
---|
| 19 | if (pre) printf(" ");
|
---|
| 20 | printf("R%d:%s", (int)n, mrb_sym2name(mrb, sym));
|
---|
| 21 | return 1;
|
---|
| 22 | }
|
---|
| 23 | }
|
---|
| 24 | return 0;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | #define RA 1
|
---|
| 28 | #define RB 2
|
---|
| 29 | #define RAB 3
|
---|
| 30 |
|
---|
| 31 | static void
|
---|
| 32 | print_lv(mrb_state *mrb, mrb_irep *irep, mrb_code c, int r)
|
---|
| 33 | {
|
---|
| 34 | int pre = 0;
|
---|
| 35 |
|
---|
| 36 | if (!irep->lv
|
---|
| 37 | || ((!(r & RA) || GETARG_A(c) >= irep->nlocals)
|
---|
| 38 | && (!(r & RB) || GETARG_B(c) >= irep->nlocals))) {
|
---|
| 39 | printf("\n");
|
---|
| 40 | return;
|
---|
| 41 | }
|
---|
| 42 | printf("\t; ");
|
---|
| 43 | if (r & RA) {
|
---|
| 44 | pre = print_r(mrb, irep, GETARG_A(c), 0);
|
---|
| 45 | }
|
---|
| 46 | if (r & RB) {
|
---|
| 47 | print_r(mrb, irep, GETARG_B(c), pre);
|
---|
| 48 | }
|
---|
| 49 | printf("\n");
|
---|
| 50 | }
|
---|
| 51 | #endif
|
---|
| 52 |
|
---|
| 53 | static void
|
---|
| 54 | codedump(mrb_state *mrb, mrb_irep *irep)
|
---|
| 55 | {
|
---|
| 56 | #ifndef MRB_DISABLE_STDIO
|
---|
| 57 | int i;
|
---|
| 58 | int ai;
|
---|
| 59 | mrb_code c;
|
---|
| 60 | const char *file = NULL, *next_file;
|
---|
| 61 | int32_t line;
|
---|
| 62 |
|
---|
| 63 | if (!irep) return;
|
---|
| 64 | printf("irep %p nregs=%d nlocals=%d pools=%d syms=%d reps=%d\n", (void*)irep,
|
---|
| 65 | irep->nregs, irep->nlocals, (int)irep->plen, (int)irep->slen, (int)irep->rlen);
|
---|
| 66 |
|
---|
| 67 | for (i = 0; i < (int)irep->ilen; i++) {
|
---|
| 68 | ai = mrb_gc_arena_save(mrb);
|
---|
| 69 |
|
---|
| 70 | next_file = mrb_debug_get_filename(irep, i);
|
---|
| 71 | if (next_file && file != next_file) {
|
---|
| 72 | printf("file: %s\n", next_file);
|
---|
| 73 | file = next_file;
|
---|
| 74 | }
|
---|
| 75 | line = mrb_debug_get_line(irep, i);
|
---|
| 76 | if (line < 0) {
|
---|
| 77 | printf(" ");
|
---|
| 78 | }
|
---|
| 79 | else {
|
---|
| 80 | printf("%5d ", line);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | printf("%03d ", i);
|
---|
| 84 | c = irep->iseq[i];
|
---|
| 85 | switch (GET_OPCODE(c)) {
|
---|
| 86 | case OP_NOP:
|
---|
| 87 | printf("OP_NOP\n");
|
---|
| 88 | break;
|
---|
| 89 | case OP_MOVE:
|
---|
| 90 | printf("OP_MOVE\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
|
---|
| 91 | print_lv(mrb, irep, c, RAB);
|
---|
| 92 | break;
|
---|
| 93 | case OP_LOADL:
|
---|
| 94 | {
|
---|
| 95 | mrb_value v = irep->pool[GETARG_Bx(c)];
|
---|
| 96 | mrb_value s = mrb_inspect(mrb, v);
|
---|
| 97 | printf("OP_LOADL\tR%d\tL(%d)\t; %s", GETARG_A(c), GETARG_Bx(c), RSTRING_PTR(s));
|
---|
| 98 | }
|
---|
| 99 | print_lv(mrb, irep, c, RA);
|
---|
| 100 | break;
|
---|
| 101 | case OP_LOADI:
|
---|
| 102 | printf("OP_LOADI\tR%d\t%d\t", GETARG_A(c), GETARG_sBx(c));
|
---|
| 103 | print_lv(mrb, irep, c, RA);
|
---|
| 104 | break;
|
---|
| 105 | case OP_LOADSYM:
|
---|
| 106 | printf("OP_LOADSYM\tR%d\t:%s", GETARG_A(c),
|
---|
| 107 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
|
---|
| 108 | print_lv(mrb, irep, c, RA);
|
---|
| 109 | break;
|
---|
| 110 | case OP_LOADNIL:
|
---|
| 111 | printf("OP_LOADNIL\tR%d\t\t", GETARG_A(c));
|
---|
| 112 | print_lv(mrb, irep, c, RA);
|
---|
| 113 | break;
|
---|
| 114 | case OP_LOADSELF:
|
---|
| 115 | printf("OP_LOADSELF\tR%d\t\t", GETARG_A(c));
|
---|
| 116 | print_lv(mrb, irep, c, RA);
|
---|
| 117 | break;
|
---|
| 118 | case OP_LOADT:
|
---|
| 119 | printf("OP_LOADT\tR%d\t\t", GETARG_A(c));
|
---|
| 120 | print_lv(mrb, irep, c, RA);
|
---|
| 121 | break;
|
---|
| 122 | case OP_LOADF:
|
---|
| 123 | printf("OP_LOADF\tR%d\t\t", GETARG_A(c));
|
---|
| 124 | print_lv(mrb, irep, c, RA);
|
---|
| 125 | break;
|
---|
| 126 | case OP_GETGLOBAL:
|
---|
| 127 | printf("OP_GETGLOBAL\tR%d\t:%s", GETARG_A(c),
|
---|
| 128 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
|
---|
| 129 | print_lv(mrb, irep, c, RA);
|
---|
| 130 | break;
|
---|
| 131 | case OP_SETGLOBAL:
|
---|
| 132 | printf("OP_SETGLOBAL\t:%s\tR%d\t",
|
---|
| 133 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
|
---|
| 134 | GETARG_A(c));
|
---|
| 135 | print_lv(mrb, irep, c, RA);
|
---|
| 136 | break;
|
---|
| 137 | case OP_GETCONST:
|
---|
| 138 | printf("OP_GETCONST\tR%d\t:%s", GETARG_A(c),
|
---|
| 139 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
|
---|
| 140 | print_lv(mrb, irep, c, RA);
|
---|
| 141 | break;
|
---|
| 142 | case OP_SETCONST:
|
---|
| 143 | printf("OP_SETCONST\t:%s\tR%d\t",
|
---|
| 144 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
|
---|
| 145 | GETARG_A(c));
|
---|
| 146 | print_lv(mrb, irep, c, RA);
|
---|
| 147 | break;
|
---|
| 148 | case OP_GETMCNST:
|
---|
| 149 | printf("OP_GETMCNST\tR%d\tR%d::%s", GETARG_A(c), GETARG_A(c),
|
---|
| 150 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
|
---|
| 151 | print_lv(mrb, irep, c, RAB);
|
---|
| 152 | break;
|
---|
| 153 | case OP_SETMCNST:
|
---|
| 154 | printf("OP_SETMCNST\tR%d::%s\tR%d", GETARG_A(c)+1,
|
---|
| 155 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
|
---|
| 156 | GETARG_A(c));
|
---|
| 157 | print_lv(mrb, irep, c, RA);
|
---|
| 158 | break;
|
---|
| 159 | case OP_GETIV:
|
---|
| 160 | printf("OP_GETIV\tR%d\t%s", GETARG_A(c),
|
---|
| 161 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
|
---|
| 162 | print_lv(mrb, irep, c, RA);
|
---|
| 163 | break;
|
---|
| 164 | case OP_SETIV:
|
---|
| 165 | printf("OP_SETIV\t%s\tR%d",
|
---|
| 166 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
|
---|
| 167 | GETARG_A(c));
|
---|
| 168 | print_lv(mrb, irep, c, RA);
|
---|
| 169 | break;
|
---|
| 170 | case OP_GETUPVAR:
|
---|
| 171 | printf("OP_GETUPVAR\tR%d\t%d\t%d",
|
---|
| 172 | GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 173 | print_lv(mrb, irep, c, RA);
|
---|
| 174 | break;
|
---|
| 175 | case OP_SETUPVAR:
|
---|
| 176 | printf("OP_SETUPVAR\tR%d\t%d\t%d",
|
---|
| 177 | GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 178 | print_lv(mrb, irep, c, RA);
|
---|
| 179 | break;
|
---|
| 180 | case OP_GETCV:
|
---|
| 181 | printf("OP_GETCV\tR%d\t%s", GETARG_A(c),
|
---|
| 182 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]));
|
---|
| 183 | print_lv(mrb, irep, c, RA);
|
---|
| 184 | break;
|
---|
| 185 | case OP_SETCV:
|
---|
| 186 | printf("OP_SETCV\t%s\tR%d",
|
---|
| 187 | mrb_sym2name(mrb, irep->syms[GETARG_Bx(c)]),
|
---|
| 188 | GETARG_A(c));
|
---|
| 189 | print_lv(mrb, irep, c, RA);
|
---|
| 190 | break;
|
---|
| 191 | case OP_JMP:
|
---|
| 192 | printf("OP_JMP\t%03d\n", i+GETARG_sBx(c));
|
---|
| 193 | break;
|
---|
| 194 | case OP_JMPIF:
|
---|
| 195 | printf("OP_JMPIF\tR%d\t%03d\n", GETARG_A(c), i+GETARG_sBx(c));
|
---|
| 196 | break;
|
---|
| 197 | case OP_JMPNOT:
|
---|
| 198 | printf("OP_JMPNOT\tR%d\t%03d\n", GETARG_A(c), i+GETARG_sBx(c));
|
---|
| 199 | break;
|
---|
| 200 | case OP_SEND:
|
---|
| 201 | printf("OP_SEND\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 202 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 203 | GETARG_C(c));
|
---|
| 204 | break;
|
---|
| 205 | case OP_SENDB:
|
---|
| 206 | printf("OP_SENDB\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 207 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 208 | GETARG_C(c));
|
---|
| 209 | break;
|
---|
| 210 | case OP_TAILCALL:
|
---|
| 211 | printf("OP_TAILCALL\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 212 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 213 | GETARG_C(c));
|
---|
| 214 | break;
|
---|
| 215 | case OP_SUPER:
|
---|
| 216 | printf("OP_SUPER\tR%d\t%d\n", GETARG_A(c),
|
---|
| 217 | GETARG_C(c));
|
---|
| 218 | break;
|
---|
| 219 | case OP_ARGARY:
|
---|
| 220 | printf("OP_ARGARY\tR%d\t%d:%d:%d:%d", GETARG_A(c),
|
---|
| 221 | (GETARG_Bx(c)>>10)&0x3f,
|
---|
| 222 | (GETARG_Bx(c)>>9)&0x1,
|
---|
| 223 | (GETARG_Bx(c)>>4)&0x1f,
|
---|
| 224 | (GETARG_Bx(c)>>0)&0xf);
|
---|
| 225 | print_lv(mrb, irep, c, RA);
|
---|
| 226 | break;
|
---|
| 227 |
|
---|
| 228 | case OP_ENTER:
|
---|
| 229 | printf("OP_ENTER\t%d:%d:%d:%d:%d:%d:%d\n",
|
---|
| 230 | (GETARG_Ax(c)>>18)&0x1f,
|
---|
| 231 | (GETARG_Ax(c)>>13)&0x1f,
|
---|
| 232 | (GETARG_Ax(c)>>12)&0x1,
|
---|
| 233 | (GETARG_Ax(c)>>7)&0x1f,
|
---|
| 234 | (GETARG_Ax(c)>>2)&0x1f,
|
---|
| 235 | (GETARG_Ax(c)>>1)&0x1,
|
---|
| 236 | GETARG_Ax(c) & 0x1);
|
---|
| 237 | break;
|
---|
| 238 | case OP_RETURN:
|
---|
| 239 | printf("OP_RETURN\tR%d", GETARG_A(c));
|
---|
| 240 | switch (GETARG_B(c)) {
|
---|
| 241 | case OP_R_NORMAL:
|
---|
[331] | 242 | printf("\tnormal\t"); break;
|
---|
[270] | 243 | case OP_R_RETURN:
|
---|
| 244 | printf("\treturn\t"); break;
|
---|
| 245 | case OP_R_BREAK:
|
---|
| 246 | printf("\tbreak\t"); break;
|
---|
| 247 | default:
|
---|
| 248 | printf("\tbroken\t"); break;
|
---|
| 249 | }
|
---|
| 250 | print_lv(mrb, irep, c, RA);
|
---|
| 251 | break;
|
---|
| 252 | case OP_BLKPUSH:
|
---|
| 253 | printf("OP_BLKPUSH\tR%d\t%d:%d:%d:%d", GETARG_A(c),
|
---|
| 254 | (GETARG_Bx(c)>>10)&0x3f,
|
---|
| 255 | (GETARG_Bx(c)>>9)&0x1,
|
---|
| 256 | (GETARG_Bx(c)>>4)&0x1f,
|
---|
| 257 | (GETARG_Bx(c)>>0)&0xf);
|
---|
| 258 | print_lv(mrb, irep, c, RA);
|
---|
| 259 | break;
|
---|
| 260 |
|
---|
| 261 | case OP_LAMBDA:
|
---|
[331] | 262 | printf("OP_LAMBDA\tR%d\tI(%+d)\t", GETARG_A(c), GETARG_b(c)+1);
|
---|
| 263 | switch (GETARG_c(c)) {
|
---|
| 264 | case OP_L_METHOD:
|
---|
| 265 | printf("method"); break;
|
---|
| 266 | case OP_L_BLOCK:
|
---|
| 267 | printf("block"); break;
|
---|
| 268 | case OP_L_LAMBDA:
|
---|
| 269 | printf("lambda"); break;
|
---|
| 270 | }
|
---|
[270] | 271 | print_lv(mrb, irep, c, RA);
|
---|
| 272 | break;
|
---|
| 273 | case OP_RANGE:
|
---|
| 274 | printf("OP_RANGE\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 275 | print_lv(mrb, irep, c, RAB);
|
---|
| 276 | break;
|
---|
| 277 | case OP_METHOD:
|
---|
| 278 | printf("OP_METHOD\tR%d\t:%s", GETARG_A(c),
|
---|
| 279 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]));
|
---|
| 280 | print_lv(mrb, irep, c, RA);
|
---|
| 281 | break;
|
---|
| 282 |
|
---|
| 283 | case OP_ADD:
|
---|
| 284 | printf("OP_ADD\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 285 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 286 | GETARG_C(c));
|
---|
| 287 | break;
|
---|
| 288 | case OP_ADDI:
|
---|
| 289 | printf("OP_ADDI\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 290 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 291 | GETARG_C(c));
|
---|
| 292 | break;
|
---|
| 293 | case OP_SUB:
|
---|
| 294 | printf("OP_SUB\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 295 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 296 | GETARG_C(c));
|
---|
| 297 | break;
|
---|
| 298 | case OP_SUBI:
|
---|
| 299 | printf("OP_SUBI\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 300 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 301 | GETARG_C(c));
|
---|
| 302 | break;
|
---|
| 303 | case OP_MUL:
|
---|
| 304 | printf("OP_MUL\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 305 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 306 | GETARG_C(c));
|
---|
| 307 | break;
|
---|
| 308 | case OP_DIV:
|
---|
| 309 | printf("OP_DIV\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 310 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 311 | GETARG_C(c));
|
---|
| 312 | break;
|
---|
| 313 | case OP_LT:
|
---|
| 314 | printf("OP_LT\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 315 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 316 | GETARG_C(c));
|
---|
| 317 | break;
|
---|
| 318 | case OP_LE:
|
---|
| 319 | printf("OP_LE\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 320 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 321 | GETARG_C(c));
|
---|
| 322 | break;
|
---|
| 323 | case OP_GT:
|
---|
| 324 | printf("OP_GT\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 325 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 326 | GETARG_C(c));
|
---|
| 327 | break;
|
---|
| 328 | case OP_GE:
|
---|
| 329 | printf("OP_GE\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
| 330 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 331 | GETARG_C(c));
|
---|
| 332 | break;
|
---|
| 333 | case OP_EQ:
|
---|
[331] | 334 | printf("OP_EQ\t\tR%d\t:%s\t%d\n", GETARG_A(c),
|
---|
[270] | 335 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]),
|
---|
| 336 | GETARG_C(c));
|
---|
| 337 | break;
|
---|
| 338 |
|
---|
| 339 | case OP_STOP:
|
---|
| 340 | printf("OP_STOP\n");
|
---|
| 341 | break;
|
---|
| 342 |
|
---|
| 343 | case OP_ARRAY:
|
---|
| 344 | printf("OP_ARRAY\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 345 | print_lv(mrb, irep, c, RAB);
|
---|
| 346 | break;
|
---|
| 347 | case OP_ARYCAT:
|
---|
| 348 | printf("OP_ARYCAT\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
|
---|
| 349 | print_lv(mrb, irep, c, RAB);
|
---|
| 350 | break;
|
---|
| 351 | case OP_ARYPUSH:
|
---|
| 352 | printf("OP_ARYPUSH\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
|
---|
| 353 | print_lv(mrb, irep, c, RAB);
|
---|
| 354 | break;
|
---|
| 355 | case OP_AREF:
|
---|
| 356 | printf("OP_AREF\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 357 | print_lv(mrb, irep, c, RAB);
|
---|
| 358 | break;
|
---|
| 359 | case OP_APOST:
|
---|
| 360 | printf("OP_APOST\tR%d\t%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 361 | print_lv(mrb, irep, c, RA);
|
---|
| 362 | break;
|
---|
| 363 | case OP_STRING:
|
---|
| 364 | {
|
---|
| 365 | mrb_value v = irep->pool[GETARG_Bx(c)];
|
---|
| 366 | mrb_value s = mrb_str_dump(mrb, mrb_str_new(mrb, RSTRING_PTR(v), RSTRING_LEN(v)));
|
---|
| 367 | printf("OP_STRING\tR%d\tL(%d)\t; %s", GETARG_A(c), GETARG_Bx(c), RSTRING_PTR(s));
|
---|
| 368 | }
|
---|
| 369 | print_lv(mrb, irep, c, RA);
|
---|
| 370 | break;
|
---|
| 371 | case OP_STRCAT:
|
---|
| 372 | printf("OP_STRCAT\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
|
---|
| 373 | print_lv(mrb, irep, c, RAB);
|
---|
| 374 | break;
|
---|
| 375 | case OP_HASH:
|
---|
| 376 | printf("OP_HASH\tR%d\tR%d\t%d", GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 377 | print_lv(mrb, irep, c, RAB);
|
---|
| 378 | break;
|
---|
| 379 |
|
---|
| 380 | case OP_OCLASS:
|
---|
| 381 | printf("OP_OCLASS\tR%d\t\t", GETARG_A(c));
|
---|
| 382 | print_lv(mrb, irep, c, RA);
|
---|
| 383 | break;
|
---|
| 384 | case OP_CLASS:
|
---|
| 385 | printf("OP_CLASS\tR%d\t:%s", GETARG_A(c),
|
---|
| 386 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]));
|
---|
| 387 | print_lv(mrb, irep, c, RA);
|
---|
| 388 | break;
|
---|
| 389 | case OP_MODULE:
|
---|
| 390 | printf("OP_MODULE\tR%d\t:%s", GETARG_A(c),
|
---|
| 391 | mrb_sym2name(mrb, irep->syms[GETARG_B(c)]));
|
---|
| 392 | print_lv(mrb, irep, c, RA);
|
---|
| 393 | break;
|
---|
| 394 | case OP_EXEC:
|
---|
| 395 | printf("OP_EXEC\tR%d\tI(%+d)", GETARG_A(c), GETARG_Bx(c)+1);
|
---|
| 396 | print_lv(mrb, irep, c, RA);
|
---|
| 397 | break;
|
---|
| 398 | case OP_SCLASS:
|
---|
| 399 | printf("OP_SCLASS\tR%d\tR%d\t", GETARG_A(c), GETARG_B(c));
|
---|
| 400 | print_lv(mrb, irep, c, RAB);
|
---|
| 401 | break;
|
---|
| 402 | case OP_TCLASS:
|
---|
| 403 | printf("OP_TCLASS\tR%d\t\t", GETARG_A(c));
|
---|
| 404 | print_lv(mrb, irep, c, RA);
|
---|
| 405 | break;
|
---|
| 406 | case OP_ERR:
|
---|
| 407 | {
|
---|
| 408 | mrb_value v = irep->pool[GETARG_Bx(c)];
|
---|
| 409 | mrb_value s = mrb_str_dump(mrb, mrb_str_new(mrb, RSTRING_PTR(v), RSTRING_LEN(v)));
|
---|
| 410 | printf("OP_ERR\t%s\n", RSTRING_PTR(s));
|
---|
| 411 | }
|
---|
| 412 | break;
|
---|
| 413 | case OP_EPUSH:
|
---|
| 414 | printf("OP_EPUSH\t:I(%+d)\n", GETARG_Bx(c)+1);
|
---|
| 415 | break;
|
---|
| 416 | case OP_ONERR:
|
---|
| 417 | printf("OP_ONERR\t%03d\n", i+GETARG_sBx(c));
|
---|
| 418 | break;
|
---|
| 419 | case OP_RESCUE:
|
---|
[331] | 420 | {
|
---|
| 421 | int a = GETARG_A(c);
|
---|
| 422 | int b = GETARG_B(c);
|
---|
| 423 | int cnt = GETARG_C(c);
|
---|
| 424 |
|
---|
| 425 | if (b == 0) {
|
---|
| 426 | printf("OP_RESCUE\tR%d\t\t%s", a, cnt ? "cont" : "");
|
---|
| 427 | print_lv(mrb, irep, c, RA);
|
---|
| 428 | break;
|
---|
| 429 | }
|
---|
| 430 | else {
|
---|
| 431 | printf("OP_RESCUE\tR%d\tR%d\t%s", a, b, cnt ? "cont" : "");
|
---|
| 432 | print_lv(mrb, irep, c, RAB);
|
---|
| 433 | break;
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
[270] | 436 | break;
|
---|
| 437 | case OP_RAISE:
|
---|
| 438 | printf("OP_RAISE\tR%d\t\t", GETARG_A(c));
|
---|
| 439 | print_lv(mrb, irep, c, RA);
|
---|
| 440 | break;
|
---|
| 441 | case OP_POPERR:
|
---|
[331] | 442 | printf("OP_POPERR\t%d\t\t\n", GETARG_A(c));
|
---|
[270] | 443 | break;
|
---|
| 444 | case OP_EPOP:
|
---|
| 445 | printf("OP_EPOP\t%d\n", GETARG_A(c));
|
---|
| 446 | break;
|
---|
| 447 |
|
---|
| 448 | default:
|
---|
| 449 | printf("OP_unknown %d\t%d\t%d\t%d\n", GET_OPCODE(c),
|
---|
| 450 | GETARG_A(c), GETARG_B(c), GETARG_C(c));
|
---|
| 451 | break;
|
---|
| 452 | }
|
---|
| 453 | mrb_gc_arena_restore(mrb, ai);
|
---|
| 454 | }
|
---|
| 455 | printf("\n");
|
---|
| 456 | #endif
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 | static void
|
---|
| 460 | codedump_recur(mrb_state *mrb, mrb_irep *irep)
|
---|
| 461 | {
|
---|
| 462 | size_t i;
|
---|
| 463 |
|
---|
| 464 | codedump(mrb, irep);
|
---|
| 465 | for (i=0; i<irep->rlen; i++) {
|
---|
| 466 | codedump_recur(mrb, irep->reps[i]);
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | void
|
---|
| 471 | mrb_codedump_all(mrb_state *mrb, struct RProc *proc)
|
---|
| 472 | {
|
---|
| 473 | codedump_recur(mrb, proc->body.irep);
|
---|
| 474 | }
|
---|