Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r74792:af6873879d10
Date: 2014-12-02 19:02 +0000
http://bitbucket.org/pypy/pypy/changeset/af6873879d10/
Log: WIP: storing blockstack status on bc_graph
diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -263,9 +263,11 @@
instr = self.read(offset)
yield instr
+ def all_blocks(self):
+ return set(x[0] for x in self.pos_index.values())
+
def dump(self):
- all_blocks = set(x[0] for x in self.pos_index.values())
- blocks = sorted(all_blocks, key=lambda b: b.startpos)
+ blocks = sorted(self.all_blocks(), key=lambda b: b.startpos)
return [b.operations for b in blocks]
@@ -274,6 +276,7 @@
def __init__(self):
self.parents = set()
self._exits = []
+ self.blockstack = []
def __getitem__(self, i):
return self.operations[i]
@@ -522,6 +525,7 @@
def bc_flow(self, reader):
reader.curr_block.operations.append(self)
self.target = reader.get_block_at(self.arg)
+ reader.curr_block.blockstack.append(self.make_block(-1))
def eval(self, ctx):
block = self.make_block(ctx.stackdepth)
diff --git a/rpython/flowspace/test/test_bytecode.py
b/rpython/flowspace/test/test_bytecode.py
--- a/rpython/flowspace/test/test_bytecode.py
+++ b/rpython/flowspace/test/test_bytecode.py
@@ -2,12 +2,27 @@
from rpython.flowspace.bytecode import bc_reader
+def make_graph(func):
+ return bc_reader.build_flow(bc_reader.build_code(func.__code__))
+
def test_graph_dump():
def f(x):
if x:
return 1
else:
return 0
- bc_graph = bc_reader.build_flow(bc_reader.build_code(f.__code__))
+ bc_graph = make_graph(f)
assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10]
assert bc_graph.dump()[0][0] == bc_reader.new_instr('LOAD_FAST', 0)
+
+def test_blockstack():
+ def f():
+ for x in lst:
+ xxx
+ graph = make_graph(f)
+ for block in graph.all_blocks():
+ if bc_reader.new_instr('LOAD_GLOBAL', 'xxx') in block.operations:
+ break
+ else:
+ assert False
+ assert len(block.blockstack) == 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit