class MrbParser::CodeDump
Constants
- MAXARG_Bx
- MAXARG_sBx
- OP_ADD
- OP_ADDI
- OP_APOST
- OP_AREF
- OP_ARGARY
- OP_ARRAY
- OP_ARYCAT
- OP_ARYPUSH
- OP_ASET
- OP_BLKPUSH
- OP_CALL
- OP_CLASS
- OP_DEBUG
- OP_DIV
- OP_ENTER
- OP_EPOP
- OP_EPUSH
- OP_EQ
- OP_ERR
- OP_EXEC
- OP_FSEND
- OP_GE
- OP_GETCONST
- OP_GETCV
- OP_GETGLOBAL
- OP_GETIV
- OP_GETMCNST
- OP_GETSPECIAL
- OP_GETUPVAR
- OP_GT
- OP_HASH
- OP_JMP
- OP_JMPIF
- OP_JMPNOT
- OP_KARG
- OP_KDICT
- OP_LAMBDA
- OP_LE
- OP_LOADF
- OP_LOADI
- OP_LOADL
- OP_LOADNIL
- OP_LOADSELF
- OP_LOADSYM
- OP_LOADT
- OP_LT
- OP_METHOD
- OP_MODULE
- OP_MOVE
- OP_MUL
- OP_NOP
- OP_OCLASS
- OP_ONERR
- OP_POPERR
- OP_RAISE
- OP_RANGE
- OP_RESCUE
- OP_RETURN
- OP_RSVD1
- OP_RSVD2
- OP_RSVD3
- OP_RSVD4
- OP_RSVD5
- OP_R_BREAK
- OP_R_NORMAL
- OP_R_RETURN
- OP_SCLASS
- OP_SEND
- OP_SENDB
- OP_SETCONST
- OP_SETCV
- OP_SETGLOBAL
- OP_SETIV
- OP_SETMCNST
- OP_SETSPECIAL
- OP_SETUPVAR
- OP_STOP
- OP_STRCAT
- OP_STRING
- OP_SUB
- OP_SUBI
- OP_SUPER
- OP_TAILCALL
- OP_TCLASS
Public Class Methods
new(irep)
click to toggle source
instructions: packed 32 bit
A:B:C:OP = 9: 9: 7: 7 A:Bx:OP = 9:16: 7 Ax:OP = 25: 7
A:Bz:Cz:OP = 9:14: 2: 7
# File lib/mrb_parser/code_dump.rb, line 112 def initialize(irep) @irep = irep end
Public Instance Methods
dump(c, i)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 161 def dump(c, i) printf("%03d ", i) op = opcode(c) case op when OP_NOP printf("OP_NOP\n") when OP_MOVE printf("OP_MOVE\tR%d\tR%d\n", getarg_a(c), getarg_b(c)) when OP_LOADL printf("OP_LOADL\tR%d\tL(%d)\n", getarg_a(c), getarg_bx(c)) when OP_LOADI printf("OP_LOADI\tR%d\t%d\n", getarg_a(c), getarg_sbx(c)) when OP_LOADSYM printf("OP_LOADSYM\tR%d\t:%s\n", getarg_a(c), @irep.syms[getarg_bx(c)]) when OP_LOADNIL printf("OP_LOADNIL\tR%d\n", getarg_a(c)) when OP_LOADSELF printf("OP_LOADSELF\tR%d\n", getarg_a(c)) when OP_LOADT printf("OP_LOADT\tR%d\n", getarg_a(c)) when OP_LOADF printf("OP_LOADF\tR%d\n", getarg_a(c)) when OP_GETGLOBAL printf("OP_GETGLOBAL\tR%d\t:%s\n", getarg_a(c), @irep.syms[getarg_bx(c)]) when OP_SETGLOBAL printf("OP_SETGLOBAL\t:%s\tR%d\n", @irep.syms[getarg_bx(c)], getarg_a(c)) when OP_GETCONST printf("OP_GETCONST\tR%d\t:%s\n", getarg_a(c), @irep.syms[getarg_bx(c)]) when OP_SETCONST printf("OP_SETCONST\t:%s\tR%d\n", @irep.syms[getarg_bx(c)], getarg_a(c)) when OP_GETMCNST printf("OP_GETMCNST\tR%d\tR%d::%s\n", getarg_a(c), getarg_a(c), @irep.syms[getarg_bx(c)]) when OP_SETMCNST printf("OP_SETMCNST\tR%d::%s\tR%d\n", getarg_a(c)+1, @irep.syms[getarg_bx(c)], getarg_a(c)) when OP_GETIV printf("OP_GETIV\tR%d\t%s\n", getarg_a(c), @irep.syms[getarg_bx(c)]) when OP_SETIV printf("OP_SETIV\t%s\tR%d\n", @irep.syms[getarg_bx(c)], getarg_a(c)) when OP_GETUPVAR printf("OP_GETUPVAR\tR%d\t%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_SETUPVAR printf("OP_SETUPVAR\tR%d\t%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_GETCV printf("OP_GETCV\tR%d\t%s\n", getarg_a(c), @irep.syms[getarg_bx(c)]) when OP_SETCV printf("OP_SETCV\t%s\tR%d\n", @irep.syms[getarg_bx(c)], getarg_a(c)) when OP_JMP printf("OP_JMP\t\t%03d\n", i+getarg_sbx(c)) when OP_JMPIF printf("OP_JMPIF\tR%d\t%03d\n", getarg_a(c), i+getarg_sbx(c)) when OP_JMPNOT printf("OP_JMPNOT\tR%d\t%03d\n", getarg_a(c), i+getarg_sbx(c)); when OP_SEND printf("OP_SEND\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_SENDB printf("OP_SENDB\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_TAILCALL printf("OP_TAILCALL\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_SUPER printf("OP_SUPER\tR%d\t%d\n", getarg_a(c), getarg_c(c)) when OP_ARGARY printf("OP_ARGARY\tR%d\t%d:%d:%d:%d\n", getarg_a(c), (getarg_bx(c)>>10)&0x3f, (getarg_bx(c)>>9)&0x1, (getarg_bx(c)>>4)&0x1f, (getarg_bx(c)>>0)&0xf) when OP_ENTER 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) when OP_RETURN printf("OP_RETURN\tR%d", getarg_a(c)) case getarg_b(c) when OP_R_NORMAL printf("\n") when OP_R_RETURN printf("\treturn\n") when OP_R_BREAK printf("\tbreak\n") else printf("\tbroken\n") end when OP_BLKPUSH printf("OP_BLKPUSH\tR%d\t%d:%d:%d:%d\n", getarg_a(c), (getarg_bx(c)>>10)&0x3f, (getarg_bx(c)>>9)&0x1, (getarg_bx(c)>>4)&0x1f, (getarg_bx(c)>>0)&0xf) when OP_LAMBDA printf("OP_LAMBDA\tR%d\tI(%+d)\t%d\n", getarg_a(c), getarg_b2(c), getarg_c2(c)) when OP_RANGE printf("OP_RANGE\tR%d\tR%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_METHOD printf("OP_METHOD\tR%d\t:%s\n", getarg_a(c), @irep.syms[getarg_b(c)]) when OP_ADD printf("OP_ADD\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_ADDI printf("OP_ADDI\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_SUB printf("OP_SUB\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_SUBI printf("OP_SUBI\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_MUL printf("OP_MUL\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_DIV printf("OP_DIV\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_LT printf("OP_LT\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_LE printf("OP_LE\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_GT printf("OP_GT\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_GE printf("OP_GE\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_EQ printf("OP_EQ\tR%d\t:%s\t%d\n", getarg_a(c), @irep.syms[getarg_b(c)], getarg_c(c)) when OP_STOP printf("OP_STOP\n") when OP_ARRAY printf("OP_ARRAY\tR%d\tR%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_ARYCAT printf("OP_ARYCAT\tR%d\tR%d\n", getarg_a(c), getarg_b(c)) when OP_ARYPUSH printf("OP_ARYPUSH\tR%d\tR%d\n", getarg_a(c), getarg_b(c)) when OP_AREF printf("OP_AREF\tR%d\tR%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_APOST printf("OP_APOST\tR%d\t%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_STRING s = @irep.pool[getarg_bx(c)] printf("OP_STRING\tR%d\t%s\n", getarg_a(c), s) when OP_STRCAT printf("OP_STRCAT\tR%d\tR%d\n", getarg_a(c), getarg_b(c)) when OP_HASH printf("OP_HASH\tR%d\tR%d\t%d\n", getarg_a(c), getarg_b(c), getarg_c(c)) when OP_OCLASS printf("OP_OCLASS\tR%d\n", getarg_a(c)) when OP_CLASS printf("OP_cLASS\tR%d\t:%s\n", getarg_a(c), @irep.syms[getarg_b(c)]) when OP_MODULE printf("OP_MODULE\tR%d\t:%s\n", getarg_a(c), @irep.syms[getarg_b(c)]) when OP_EXEC printf("OP_EXEC\tR%d\tI(%+d)\n", getarg_a(c), getarg_bx(c)) when OP_SCLASS printf("OP_SCLASS\tR%d\tR%d\n", getarg_a(c), getarg_b(c)) when OP_TCLASS printf("OP_TCLASS\tR%d\n", getarg_a(c)) when OP_ERR printf("OP_ERR\tL(%d)\n", getarg_bx(c)) when OP_EPUSH printf("OP_EPUSH\t:I(%+d)\n", getarg_bx(c)) when OP_ONERR printf("OP_ONERR\t%03d\n", i+getarg_sbx(c)) when OP_RESCUE printf("OP_RESCUE\tR%d\n", getarg_a(c)) when OP_RAISE printf("OP_RAISE\tR%d\n", getarg_a(c)) when OP_POPERR printf("OP_POPERR\t%d\n", getarg_a(c)) when OP_EPOP printf("OP_EPOP\t%d\n", getarg_a(c)) else printf("OP_unknown %d\t%d\t%d\t%d\n", opcode(c), getarg_a(c), getarg_b(c), getarg_c(c)) end end
getarg_a(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 120 def getarg_a(code) (code >> 23) & 0x1ff end
getarg_ax(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 140 def getarg_ax(code) (code >> 7) & 0x1ffffff end
getarg_b(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 124 def getarg_b(code) (code >> 14) & 0x1ff end
getarg_b2(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 152 def getarg_b2(code) getarg_unpack_b(code, 14, 2) end
getarg_bx(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 132 def getarg_bx(code) (code >> 7) & 0xffff end
getarg_c(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 128 def getarg_c(code) (code >> 7) & 0x7f end
getarg_c2(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 156 def getarg_c2(code) getarg_unpack_c(code, 14, 2) end
getarg_sbx(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 136 def getarg_sbx(code) getarg_bx(code) - MAXARG_sBx end
getarg_unpack_b(code, n1, n2)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 144 def getarg_unpack_b(code, n1, n2) (code >> (7 + n2)) & ((1 << n1)-1) end
getarg_unpack_c(code, n1, n2)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 148 def getarg_unpack_c(code, n1, n2) (code >> 7) & ((1 << n2)-1) end
opcode(code)
click to toggle source
# File lib/mrb_parser/code_dump.rb, line 116 def opcode(code) code & 0x7F end