[pypy-commit] pypy x86-dump-labels: add a handy method dump() to looptoken, which prints a disassembled version of the compiled loop on stdout

antocuni noreply at buildbot.pypy.org
Wed May 11 14:32:02 CEST 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: x86-dump-labels
Changeset: r44070:15611cc6a84c
Date: 2011-05-10 16:07 +0200
http://bitbucket.org/pypy/pypy/changeset/15611cc6a84c/

Log:	add a handy method dump() to looptoken, which prints a disassembled
	version of the compiled loop on stdout

diff --git a/pypy/jit/backend/model.py b/pypy/jit/backend/model.py
--- a/pypy/jit/backend/model.py
+++ b/pypy/jit/backend/model.py
@@ -53,7 +53,6 @@
         """Called once by the front-end when the program stops."""
         pass
 
-
     def compile_loop(self, inputargs, operations, looptoken, log=True):
         """Assemble the given loop.
         Should create and attach a fresh CompiledLoopToken to
@@ -69,6 +68,10 @@
         """
         raise NotImplementedError    
 
+    def dump_loop_token(self, looptoken):
+        """Print a disassembled version of looptoken to stdout"""
+        raise NotImplementedError
+
     def execute_token(self, looptoken):
         """Execute the generated code referenced by the looptoken.
         Returns the descr of the last executed operation: either the one
diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -361,6 +361,11 @@
                                 frame_depth + param_depth)
         self.patch_pending_failure_recoveries(rawstart)
         #
+        if not we_are_translated():
+            # only for tests
+            looptoken._x86_rawstart = rawstart
+            looptoken._x86_fullsize = fullsize
+
         looptoken._x86_bootstrap_code = rawstart + bootstrappos
         looptoken._x86_loop_code = rawstart + self.looppos
         looptoken._x86_direct_bootstrap_code = rawstart + directbootstrappos
diff --git a/pypy/jit/backend/x86/runner.py b/pypy/jit/backend/x86/runner.py
--- a/pypy/jit/backend/x86/runner.py
+++ b/pypy/jit/backend/x86/runner.py
@@ -60,6 +60,17 @@
         self.assembler.finish_once()
         self.profile_agent.shutdown()
 
+    def dump_loop_token(self, looptoken):
+        from pypy.jit.backend.x86.tool.viewcode import machine_code_dump
+        data = []
+        addr = looptoken._x86_rawstart
+        src = rffi.cast(rffi.CCHARP, addr)
+        for p in range(looptoken._x86_fullsize):
+            data.append(src[p])
+        data = ''.join(data)
+        lines = machine_code_dump(data, addr, self.backend_name)
+        print ''.join(lines)
+
     def compile_loop(self, inputargs, operations, looptoken, log=True):
         self.assembler.assemble_loop(inputargs, operations, looptoken,
                                      log=log)
@@ -164,7 +175,9 @@
         # positions invalidated
         looptoken.compiled_loop_token.invalidate_positions = []
 
+
 class CPU386(AbstractX86CPU):
+    backend_name = 'x86'
     WORD = 4
     NUM_REGS = 8
     CALLEE_SAVE_REGISTERS = [regloc.ebx, regloc.esi, regloc.edi]
@@ -180,6 +193,7 @@
     supports_longlong = False
 
 class CPU_X86_64(AbstractX86CPU):
+    backend_name = 'x86_64'
     WORD = 8
     NUM_REGS = 16
     CALLEE_SAVE_REGISTERS = [regloc.ebx, regloc.r12, regloc.r13, regloc.r14, regloc.r15]
diff --git a/pypy/jit/backend/x86/tool/__init__.py b/pypy/jit/backend/x86/tool/__init__.py
new file mode 100644
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -785,6 +785,8 @@
     def repr_of_descr(self):
         return '<Loop%d>' % self.number
 
+    def dump(self):
+        self.compiled_loop_token.cpu.dump_loop_token(self)
 
 class TreeLoop(object):
     inputargs = None


More information about the pypy-commit mailing list