PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/rpython/jit/backend/x86/codebuf.py

https://bitbucket.org/pypy/pypy/
Python | 55 lines | 40 code | 6 blank | 9 comment | 6 complexity | b1606e55f2013bdc4fadf13951c3797b MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. from rpython.rtyper.lltypesystem import lltype, rffi
  2. from rpython.rlib.rarithmetic import intmask
  3. from rpython.rlib.debug import debug_start, debug_print, debug_stop
  4. from rpython.rlib.debug import have_debug_prints
  5. from rpython.jit.backend.llsupport.asmmemmgr import BlockBuilderMixin
  6. from rpython.jit.backend.x86.rx86 import X86_32_CodeBuilder, X86_64_CodeBuilder
  7. from rpython.jit.backend.x86.regloc import LocationCodeBuilder
  8. from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64, WORD
  9. from rpython.jit.backend.x86 import valgrind
  10. # XXX: Seems nasty to change the superclass of MachineCodeBlockWrapper
  11. # like this
  12. if IS_X86_32:
  13. codebuilder_cls = X86_32_CodeBuilder
  14. backend_name = 'x86'
  15. elif IS_X86_64:
  16. codebuilder_cls = X86_64_CodeBuilder
  17. backend_name = 'x86_64'
  18. class MachineCodeBlockWrapper(BlockBuilderMixin,
  19. LocationCodeBuilder,
  20. codebuilder_cls):
  21. def __init__(self):
  22. self.init_block_builder()
  23. codebuilder_cls.__init__(self)
  24. # a list of relative positions; for each position p, the bytes
  25. # at [p-4:p] encode an absolute address that will need to be
  26. # made relative. Only works on 32-bit!
  27. if WORD == 4:
  28. self.relocations = []
  29. else:
  30. self.relocations = None
  31. #
  32. # ResOperation --> offset in the assembly.
  33. # ops_offset[None] represents the beginning of the code after the last op
  34. # (i.e., the tail of the loop)
  35. self.ops_offset = {}
  36. def add_pending_relocation(self):
  37. self.relocations.append(self.get_relative_pos())
  38. def mark_op(self, op):
  39. pos = self.get_relative_pos()
  40. self.ops_offset[op] = pos
  41. def copy_to_raw_memory(self, addr):
  42. self._copy_to_raw_memory(addr)
  43. if self.relocations is not None:
  44. for reloc in self.relocations: # for 32-bit only
  45. p = addr + reloc
  46. adr = rffi.cast(rffi.INTP, p - 4)
  47. adr[0] = rffi.cast(rffi.INT, intmask(adr[0]) - p)
  48. valgrind.discard_translations(addr, self.get_relative_pos())
  49. self._dump(addr, "jit-backend-dump", backend_name)