[pypy-commit] pypy framestate: Create HostCode.disassemble()

rlamy noreply at buildbot.pypy.org
Mon Nov 24 17:29:42 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: framestate
Changeset: r74673:f3685601c1d7
Date: 2013-05-02 23:24 +0100
http://bitbucket.org/pypy/pypy/changeset/f3685601c1d7/

Log:	Create HostCode.disassemble()

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -57,6 +57,23 @@
         self.co_lnotab = lnotab
         self.signature = cpython_code_signature(self)
 
+    def disassemble(self):
+        contents = []
+        offsets = []
+        jumps = {}
+        pos = 0
+        i = 0
+        while pos < len(self.co_code):
+            offsets.append(pos)
+            next_pos, op = self.decode(pos)
+            contents.append(op)
+            if op.has_jump():
+                jumps[pos] = op.arg
+            pos = next_pos
+            i += 1
+        return contents, offsets, jumps
+
+
     @classmethod
     def _from_code(cls, code):
         """Initialize the code object from a real (CPython) one.
@@ -153,6 +170,9 @@
     def eval(self, ctx):
         pass
 
+    def has_jump(self):
+        return self.num in opcode.hasjrel or self.num in opcode.hasjabs
+
     def __repr__(self):
         return "%s(%s)" % (self.name, self.arg)
 


More information about the pypy-commit mailing list