Author: Maciej Fijalkowski <[email protected]>
Branch: fileops2
Changeset: r67213:23f91dbd0100
Date: 2013-10-08 14:56 +0200
http://bitbucket.org/pypy/pypy/changeset/23f91dbd0100/

Log:    Move the getting graph to block itself

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -252,6 +252,23 @@
         from rpython.translator.tool.graphpage import try_show
         try_show(self)
 
+    def get_graph(self):
+        import gc
+        pending = [self]   # pending blocks
+        seen = {self: True, None: True}
+        for x in pending:
+            for y in gc.get_referrers(self):
+                if isinstance(y, FunctionGraph):
+                    return y
+                elif isinstance(y, Link):
+                    block = y.prevblock
+                    if block not in seen:
+                        pending.append(block)
+                        seen[block] = True
+                elif isinstance(y, dict):
+                    pending.append(y)   # go back from the dict to the real obj
+        return pending
+
     view = show
 
 
diff --git a/rpython/translator/tool/graphpage.py 
b/rpython/translator/tool/graphpage.py
--- a/rpython/translator/tool/graphpage.py
+++ b/rpython/translator/tool/graphpage.py
@@ -200,7 +200,7 @@
                 dotgen.emit_edge(nameof(cdef), nameof(prevcdef), color="red")
             prevcdef = cdef
             cdef = cdef.basedef
-        
+
         self.source = dotgen.generate(target=None)
 
     def followlink(self, name):
@@ -224,7 +224,7 @@
         dotgen.emit('mclimit=15.0')
 
         self.do_compute(dotgen, *args, **kwds)
-        
+
         self.source = dotgen.generate(target=None)
 
         # link the function names to the individual flow graphs
@@ -264,7 +264,7 @@
                 data = self.labelof(classdef, classdef.shortname)
                 dotgen.emit_node(nameof(classdef), label=data, shape="box")
                 dotgen.emit_edge(nameof(classdef.basedef), nameof(classdef))
-             
+
     def labelof(self, obj, objname):
         name = objname
         i = 1
@@ -409,22 +409,11 @@
     elif isinstance(obj, Link):
         try_show(obj.prevblock)
     elif isinstance(obj, Block):
-        import gc
-        pending = [obj]   # pending blocks
-        seen = {obj: True, None: True}
-        for x in pending:
-            for y in gc.get_referrers(x):
-                if isinstance(y, FunctionGraph):
-                    y.show()
-                    return
-                elif isinstance(y, Link):
-                    block = y.prevblock
-                    if block not in seen:
-                        pending.append(block)
-                        seen[block] = True
-                elif isinstance(y, dict):
-                    pending.append(y)   # go back from the dict to the real obj
-        graph = IncompleteGraph(pending)
+        graph = obj.get_graph()
+        if isinstance(graph, FunctionGraph):
+            graph.show()
+            return
+        graph = IncompleteGraph(graph)
         SingleGraphPage(graph).display()
     else:
         raise TypeError("try_show(%r object)" % (type(obj).__name__,))
@@ -449,7 +438,7 @@
                         seen[block] = True
         return pending
     else:
-        raise TypeError("try_get_functiongraph(%r object)" % 
(type(obj).__name__,))    
+        raise TypeError("try_get_functiongraph(%r object)" % 
(type(obj).__name__,))
 
 class IncompleteGraph:
     name = '(incomplete graph)'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to