Author: Ronan Lamy <[email protected]>
Branch: Opcode-class
Changeset: r63837:62e72859ced3
Date: 2013-05-02 23:24 +0100
http://bitbucket.org/pypy/pypy/changeset/62e72859ced3/
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
@@ -53,6 +53,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.
@@ -142,6 +159,9 @@
except ValueError:
return -1
+ def has_jump(self):
+ return self.num in opcode.hasjrel or self.num in opcode.hasjabs
+
def __repr__(self):
return "%s(%d)" % (self.name, self.arg)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit