本文整理汇总了Python中opcode.hasjrel方法的典型用法代码示例。如果您正苦于以下问题:Python opcode.hasjrel方法的具体用法?Python opcode.hasjrel怎么用?Python opcode.hasjrel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcode
的用法示例。
在下文中一共展示了opcode.hasjrel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_op_oparg
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasjrel [as 别名]
def get_op_oparg(self, op, arg, bc_index=0):
"""
Retrieve the opcode (`op`) and its argument (`oparg`) from the supplied
opcode and argument.
:param op: The current opcode.
:param arg: The current dereferenced argument.
:param bc_index: The current bytecode index.
"""
# Conversion of LOAD_NAME opcode based on injected references (global, vars)
if op == LOAD_NAME:
if arg in self.name_to_fast:
op = LOAD_FAST
elif arg in self.name_to_global:
op = LOAD_GLOBAL
oparg = None
if op >= opcode.HAVE_ARGUMENT:
if op in opcode.hasconst:
oparg = self.add_get_constant(arg)
elif op in opcode.hasname:
oparg = self.add_get_names(arg)
elif op in opcode.haslocal:
oparg = self.add_get_varnames(arg)
elif op in opcode.hascompare:
oparg = opcode.cmp_op.index(arg)
elif op in opcode.hasfree:
oparg = self.add_get_cellvars_freevars(arg)
elif op in opcode.hasjrel or op in opcode.hasjabs:
oparg = arg
else:
oparg = arg
return op, oparg
示例2: show_bytecode
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasjrel [as 别名]
def show_bytecode(bytecode, start=0, end=2**32):
from ..analysis.python.effects import get_stack_effect
if bytecode is None:
return ''
buffer = []
j = start
end = min(end, len(bytecode) - 1)
while j <= end:
index, lineno, op, arg, _, co = bytecode[j]
uid = hex(id(co))[-5:]
pop_push_str = ''
try:
pop, push = get_stack_effect(op, arg)
pop_push_str = ' (-%d +%d) ' % (pop, push)
except ValueError, ex:
pop_push_str = ' '
if op >= opcode.HAVE_ARGUMENT:
rts = repr(arg)
if len(rts) > 40:
rts = rts[:40] + '[...]'
jump_target = ''
if op in opcode.hasjrel or op in opcode.hasjabs:
jump_address = arg if op in opcode.hasjabs else index + arg + 3
jump_target = ' -------------> (%4d)' % jump_address
buffer.append("[%5s]%4d(%4d) %20s(%3d)%s (%s)%s"
% (uid, lineno, index, opcode.opname[op], op, pop_push_str, rts, jump_target))
else:
buffer.append("[%5s]%4d(%4d) %20s(%3d)%s"
% (uid, lineno, index, opcode.opname[op], op, pop_push_str))
j += 1
示例3: find_targets
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasjrel [as 别名]
def find_targets(bytecode):
targets = set()
i, length = 0, len(bytecode)
while i < length:
index, lineno, op, arg, cflow_in, code_object = bytecode[i]
if op in JUMP_OPCODES:
jump_address = arg
if op in opcode.hasjrel:
jump_address = arg + index + 3
targets.add(jump_address)
if op not in NO_FALL_THROUGH:
targets.add(bytecode[i + 1][0])
i += 1
return targets
示例4: decode_codeobj
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasjrel [as 别名]
def decode_codeobj(codeobj):
# adapted from dis.dis
extended_arg = 0
if is_py3k:
codestr = codeobj.co_code
else:
codestr = [ord(ch) for ch in codeobj.co_code]
free = None
i = 0
while i < len(codestr):
op = codestr[i]
opname = opcode.opname[op]
i += 1
argval = None
if op >= opcode.HAVE_ARGUMENT:
oparg = codestr[i] + codestr[i + 1] * 256 + extended_arg
i += 2
extended_arg = 0
if op == opcode.EXTENDED_ARG:
extended_arg = oparg * 65536
continue
if op in opcode.hasconst:
argval = codeobj.co_consts[oparg]
elif op in opcode.hasname:
argval = codeobj.co_names[oparg]
elif op in opcode.hasjrel:
argval = i + oparg
elif op in opcode.haslocal:
argval = codeobj.co_varnames[oparg]
elif op in opcode.hascompare:
argval = opcode.cmp_op[oparg]
elif op in opcode.hasfree:
if free is None:
free = codeobj.co_cellvars + codeobj.co_freevars
argval = free[oparg]
yield (opname, argval)
示例5: disassemble
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasjrel [as 别名]
def disassemble(co):
code = co.co_code
labels = dis.findlabels(code)
linestarts = dict(dis.findlinestarts(co))
n = len(code)
i = 0
extended_arg = 0
free = None
lineno = None
while i < n:
c = code[i]
op = ord(c)
lineno = linestarts.get(i, lineno)
is_label = i in labels
ist = i
i += 1
if op >= opcode.HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg
extended_arg = 0
i += 2
if op == opcode.EXTENDED_ARG:
extended_arg = oparg * 65536L
if op in opcode.hasconst:
arg = co.co_consts[oparg]
elif op in opcode.hasname:
arg = co.co_names[oparg]
elif op in opcode.hasjrel:
arg = i + oparg
elif op in opcode.haslocal:
arg = co.co_varnames[oparg]
elif op in opcode.hascompare:
arg = opcode.cmp_op[oparg]
elif op in opcode.hasfree:
if free is None:
free = co.co_cellvars + co.co_freevars
arg = free[oparg]
else:
arg = NOVAL
else:
arg = NOVAL
yield ist, lineno, is_label, opcode.opname[op], arg