Advertisement
Guest User

Untitled

a guest
Sep 9th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.44 KB | None | 0 0
  1. diff -r b9bbd6c09333 pypy/interpreter/astcompiler/assemble.py
  2. --- a/pypy/interpreter/astcompiler/assemble.py  Wed Sep 05 21:20:38 2018 +0200
  3. +++ b/pypy/interpreter/astcompiler/assemble.py  Sun Sep 09 11:03:28 2018 +0000
  4. @@ -329,36 +329,48 @@
  5.              for block in blocks:
  6.                  offset = block.offset
  7.                  for instr in block.instructions:
  8. -                    offset += instr.size()
  9.                      if instr.has_jump:
  10. +                        print repr(instr), '->',
  11.                          target, absolute = instr.jump
  12. -                        op = instr.opcode
  13. -                        # Optimize an unconditional jump going to another
  14. -                        # unconditional jump.
  15. -                        if op == ops.JUMP_ABSOLUTE or op == ops.JUMP_FORWARD:
  16. -                            if target.instructions:
  17. -                                target_op = target.instructions[0].opcode
  18. -                                if target_op == ops.JUMP_ABSOLUTE:
  19. -                                    target = target.instructions[0].jump[0]
  20. +                        while target.instructions and target.instructions[0].opcode in (
  21. +                            ops.JUMP_ABSOLUTE,
  22. +                            ops.JUMP_FORWARD,
  23. +                        ):
  24. +                            # Replace jump to unconditional jump into
  25. +                            # a jump to that jump's target.
  26. +                            new_target, new_absolute = target.instructions[0].jump
  27. +                            if not absolute and (new_absolute or new_target.offset <= offset):
  28. +                                # But stop when encountering an absolute jump
  29. +                                # on an original relative-only jump.
  30. +                                if instr.opcode != ops.JUMP_FORWARD:
  31. +                                    break
  32. +                                absolute = True
  33. +                            target = new_target
  34. +                        if target.instructions and target.instructions[0].opcode == ops.RETURN_VALUE and instr.opcode in (
  35. +                            ops.JUMP_ABSOLUTE,
  36. +                            ops.JUMP_FORWARD,
  37. +                        ):
  38. +                            # Replace unconditional jump to a RETURN into
  39. +                            # just a RETURN
  40. +                            instr.opcode = ops.RETURN_VALUE
  41. +                            instr.arg = 0
  42. +                            instr.has_jump = False
  43. +                            # The size of the code changed,
  44. +                            # we have to trigger another pass
  45. +                            force_redo = True
  46. +                        else:
  47. +                            if absolute:
  48. +                                if instr.opcode == ops.JUMP_FORWARD:
  49.                                      instr.opcode = ops.JUMP_ABSOLUTE
  50. -                                    absolute = True
  51. -                                elif target_op == ops.RETURN_VALUE:
  52. -                                    # Replace JUMP_* to a RETURN into
  53. -                                    # just a RETURN
  54. -                                    instr.opcode = ops.RETURN_VALUE
  55. -                                    instr.arg = 0
  56. -                                    instr.has_jump = False
  57. -                                    # The size of the code changed,
  58. -                                    # we have to trigger another pass
  59. -                                    force_redo = True
  60. -                                    continue
  61. -                        if absolute:
  62. -                            jump_arg = target.offset
  63. -                        else:
  64. -                            jump_arg = target.offset - offset
  65. -                        instr.arg = jump_arg
  66. -                        if jump_arg > 0xFFFF:
  67. -                            extended_arg_count += 1
  68. +                                jump_arg = target.offset
  69. +                            else:
  70. +                                jump_arg = target.offset - offset - instr.size()
  71. +                            instr.arg = jump_arg
  72. +                            instr.jump_to(target, absolute)
  73. +                            if jump_arg > 0xFFFF:
  74. +                                extended_arg_count += 1
  75. +                        print repr(instr)
  76. +                    offset += instr.size()
  77.              if (extended_arg_count == last_extended_arg_count and
  78.                  not force_redo):
  79.                  break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement