Ejemplo n.º 1
0
def get_location(pc, w_func):
    from tvm.rt.code import codenames, Op, argwidth
    savedpc = pc
    op, pc = nextbyte(pc, w_func)
    width = argwidth(op)
    if width == 2:
        oparg, pc = nextshort(pc, w_func)
    elif width == 1:
        oparg, pc = nextbyte(pc, w_func)
    else:
        oparg = 0
    #
    head = '%d:%s' % (savedpc, codenames[op])
    if savedpc == 0:
        head = ('Enter Function %s. ' % w_func.name) + head
    #
    if op in [Op.LOAD, Op.STORE, Op.LOADUPVAL, Op.STOREUPVAL, Op.BUILDUPVAL]:
        tail = '(%d) ;; well, some local var...' % oparg
    elif op in [Op.LOADGLOBAL, Op.STOREGLOBAL]:
        tail = '(%d) ;; %s' % (oparg, w_func.names_w[oparg].to_string())
    elif op == Op.LOADCONST:
        tail = '(%d) ;; %s' % (oparg, w_func.consts_w[oparg].to_string())
    elif op == Op.BUILDCLOSURE:
        tail = '(%d) ;; %s' % (oparg, w_func.functions_w[oparg].to_string())
    elif op in [Op.CALL, Op.TAILCALL]:
        tail = '() ;; argc = %d' % oparg
    elif op in [Op.RET, Op.POP]:
        tail = '()'
    elif op in [Op.J, Op.JIF, Op.JIFNOT]:
        tail = '() ;; to %d' % oparg
    else:
        tail = ';; unknown opcode %d' % op
    return head + ' ' + tail
Ejemplo n.º 2
0
def get_location(pc, w_func):
    from tvm.rt.code import codenames, Op, argwidth
    savedpc = pc
    op, pc = nextbyte(pc, w_func)
    width = argwidth(op)
    if width == 2:
        oparg, pc = nextshort(pc, w_func)
    elif width == 1:
        oparg, pc = nextbyte(pc, w_func)
    else:
        oparg = 0
    #
    head = '%d:%s' % (savedpc, codenames[op])
    if savedpc == 0:
        head = ('Enter Function %s. ' % w_func.name) + head
    #
    if op in [Op.LOAD, Op.STORE, Op.LOADUPVAL, Op.STOREUPVAL, Op.BUILDUPVAL]:
        tail = '(%d) ;; well, some local var...' % oparg
    elif op in [Op.LOADGLOBAL, Op.STOREGLOBAL]:
        tail = '(%d) ;; %s' % (oparg, w_func.names_w[oparg].to_string())
    elif op == Op.LOADCONST:
        tail = '(%d) ;; %s' % (oparg, w_func.consts_w[oparg].to_string())
    elif op == Op.BUILDCLOSURE:
        tail = '(%d) ;; %s' % (oparg, w_func.functions_w[oparg].to_string())
    elif op in [Op.CALL, Op.TAILCALL]:
        tail = '() ;; argc = %d' % oparg
    elif op in [Op.RET, Op.POP]:
        tail = '()'
    elif op in [Op.J, Op.JIF, Op.JIFNOT]:
        tail = '() ;; to %d' % oparg
    else:
        tail = ';; unknown opcode %d' % op
    return head + ' ' + tail
Ejemplo n.º 3
0
 def dispatch(self, code):
     # bytecode dispatch is folded into noop.
     opcode = self.nextbyte(code)
     width = argwidth(opcode)
     if width == 2:
         oparg = self.nextshort(code)
     elif width == 1:
         oparg = self.nextbyte(code)
     else:
         oparg = 0
     assert oparg >= 0
     #
     for someop, somedispatcher in unrolled_dispatchers:
         if someop == opcode:
             somedispatcher(self, oparg)
             break
Ejemplo n.º 4
0
 def dispatch(self, code):
     # bytecode dispatch is folded into noop.
     opcode = self.nextbyte(code)
     width = argwidth(opcode)
     if width == 2:
         oparg = self.nextshort(code)
     elif width == 1:
         oparg = self.nextbyte(code)
     else:
         oparg = 0
     assert oparg >= 0
     #
     for someop, somedispatcher in unrolled_dispatchers:
         if someop == opcode:
             somedispatcher(self, oparg)
             break
Ejemplo n.º 5
0
#!/usr/bin/env python
import sys
import path_fix
from datetime import datetime
from tvm.rt.code import codenames, argwidth

w = sys.stdout.write
w(';; dumped by dump-bytecode.py at %s\n' % datetime.now())
w(';; format is (opcode-name opcode-value argument-type)\n')
w('(')

for op, name in enumerate(codenames):
    if op != 0:
        w(' ')
    w('(%s %d %s)' % (name, op, ['void', 'u8', 'u16'][argwidth(op)]))
    if op != len(codenames) - 1:
        w('\n')

w(')\n')
#