Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r b9bbd6c09333 pypy/interpreter/astcompiler/assemble.py
- --- a/pypy/interpreter/astcompiler/assemble.py Wed Sep 05 21:20:38 2018 +0200
- +++ b/pypy/interpreter/astcompiler/assemble.py Sun Sep 09 11:03:28 2018 +0000
- @@ -329,36 +329,48 @@
- for block in blocks:
- offset = block.offset
- for instr in block.instructions:
- - offset += instr.size()
- if instr.has_jump:
- + print repr(instr), '->',
- target, absolute = instr.jump
- - op = instr.opcode
- - # Optimize an unconditional jump going to another
- - # unconditional jump.
- - if op == ops.JUMP_ABSOLUTE or op == ops.JUMP_FORWARD:
- - if target.instructions:
- - target_op = target.instructions[0].opcode
- - if target_op == ops.JUMP_ABSOLUTE:
- - target = target.instructions[0].jump[0]
- + while target.instructions and target.instructions[0].opcode in (
- + ops.JUMP_ABSOLUTE,
- + ops.JUMP_FORWARD,
- + ):
- + # Replace jump to unconditional jump into
- + # a jump to that jump's target.
- + new_target, new_absolute = target.instructions[0].jump
- + if not absolute and (new_absolute or new_target.offset <= offset):
- + # But stop when encountering an absolute jump
- + # on an original relative-only jump.
- + if instr.opcode != ops.JUMP_FORWARD:
- + break
- + absolute = True
- + target = new_target
- + if target.instructions and target.instructions[0].opcode == ops.RETURN_VALUE and instr.opcode in (
- + ops.JUMP_ABSOLUTE,
- + ops.JUMP_FORWARD,
- + ):
- + # Replace unconditional jump to a RETURN into
- + # just a RETURN
- + instr.opcode = ops.RETURN_VALUE
- + instr.arg = 0
- + instr.has_jump = False
- + # The size of the code changed,
- + # we have to trigger another pass
- + force_redo = True
- + else:
- + if absolute:
- + if instr.opcode == ops.JUMP_FORWARD:
- instr.opcode = ops.JUMP_ABSOLUTE
- - absolute = True
- - elif target_op == ops.RETURN_VALUE:
- - # Replace JUMP_* to a RETURN into
- - # just a RETURN
- - instr.opcode = ops.RETURN_VALUE
- - instr.arg = 0
- - instr.has_jump = False
- - # The size of the code changed,
- - # we have to trigger another pass
- - force_redo = True
- - continue
- - if absolute:
- - jump_arg = target.offset
- - else:
- - jump_arg = target.offset - offset
- - instr.arg = jump_arg
- - if jump_arg > 0xFFFF:
- - extended_arg_count += 1
- + jump_arg = target.offset
- + else:
- + jump_arg = target.offset - offset - instr.size()
- + instr.arg = jump_arg
- + instr.jump_to(target, absolute)
- + if jump_arg > 0xFFFF:
- + extended_arg_count += 1
- + print repr(instr)
- + offset += instr.size()
- if (extended_arg_count == last_extended_arg_count and
- not force_redo):
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement