[pypy-commit] pypy framestate: Add dumb way of dumping BC graphs

rlamy noreply at buildbot.pypy.org
Mon Nov 24 21:35:16 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: framestate
Changeset: r74715:41cb87605dc8
Date: 2014-11-24 20:35 +0000
http://bitbucket.org/pypy/pypy/changeset/41cb87605dc8/

Log:	Add dumb way of dumping BC graphs

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -244,6 +244,11 @@
         else:
             return block.operations[i].offset
 
+    def dump(self):
+        all_blocks = set(x[0] for x in self.pos_index.values())
+        blocks = sorted(all_blocks, key=lambda b: b.startpos)
+        return [b.operations for b in blocks]
+
 
 class BytecodeBlock(object):
     """Base class for opcode blocks"""
diff --git a/rpython/flowspace/test/test_bytecode.py b/rpython/flowspace/test/test_bytecode.py
new file mode 100644
--- /dev/null
+++ b/rpython/flowspace/test/test_bytecode.py
@@ -0,0 +1,13 @@
+"""Unit tests for rpython.flowspace.bytecode"""
+
+from rpython.flowspace.bytecode import bc_reader
+
+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__))
+    print bc_graph.dump()
+    assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10]


More information about the pypy-commit mailing list