[pypy-commit] pypy framestate: Decode the bytecode up-front
rlamy
noreply at buildbot.pypy.org
Mon Nov 24 17:29:43 CET 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: framestate
Changeset: r74674:272d69dae528
Date: 2014-05-05 01:33 +0100
http://bitbucket.org/pypy/pypy/changeset/272d69dae528/
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
@@ -56,6 +56,7 @@
self.co_firstlineno = firstlineno
self.co_lnotab = lnotab
self.signature = cpython_code_signature(self)
+ self.build_flow()
def disassemble(self):
contents = []
@@ -73,6 +74,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,6 +104,12 @@
return bool(self.co_flags & CO_GENERATOR)
def read(self, offset):
+ i = self.pos_index[offset]
+ op = self.contents[i][1]
+ next_offset = self.contents[i+1][0]
+ return next_offset, op
+
+ def decode(self, offset):
return bc_reader.read(self, offset)
class BytecodeReader(object):
More information about the pypy-commit
mailing list