def _get_instructions(code_obj):
if hasattr(dis, 'get_instructions'):
return list(dis.get_instructions(code_obj))
instructions = []
instruction = None
for byte in code_obj.co_code:
byte = _six_ord(byte)
if instruction is None:
instruction = [byte]
else:
instruction.append(byte)
if instruction[0] < dis.HAVE_ARGUMENT or len(instruction) == 3:
op_code = instruction[0]
op_name = dis.opname[op_code]
if instruction[0] < dis.HAVE_ARGUMENT:
instructions.append(_Instruction(op_code, op_name, None, None))
else:
arg = instruction[1]
instructions.append(_Instruction(op_code, op_name, arg, arg))
instruction = None
return instructions
评论列表
文章目录