[pypy-commit] pypy Opcode-class: Decode the bytecode up-front

rlamy noreply at buildbot.pypy.org
Sat May 4 02:05:48 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: Opcode-class
Changeset: r63838:b0a33987a874
Date: 2013-04-28 15:02 +0100
http://bitbucket.org/pypy/pypy/changeset/b0a33987a874/

Log:	Decode the bytecode up-front

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -52,6 +52,7 @@
         self.co_firstlineno = firstlineno
         self.co_lnotab = lnotab
         self.signature = cpython_code_signature(self)
+        self.build_flow()
 
     def disassemble(self):
         contents = []
@@ -69,6 +70,14 @@
             i += 1
         return contents, offsets, jumps
 
+    def build_flow(self):
+        next_pos = pos = 0
+        contents, offsets, jumps = self.disassemble()
+        self.contents = zip(offsets, contents)
+        self.pos_index = dict((offset, i) for i, offset in enumerate(offsets))
+        # add end marker
+        self.contents.append((len(self.co_code), None))
+
 
     @classmethod
     def _from_code(cls, code):
@@ -95,10 +104,17 @@
         return self.signature.scope_length()
 
     def read(self, pos):
+        i = self.pos_index[pos]
+        op = self.contents[i][1]
+        next_pos = self.contents[i+1][0]
+        return next_pos, op
+
+
+    def decode(self, pos):
         """
         Decode the instruction starting at position ``next_instr``.
 
-        Returns (next_instr, opname, oparg).
+        Returns (next_instr, op).
         """
         co_code = self.co_code
         opnum = ord(co_code[pos])


More information about the pypy-commit mailing list