[pypy-svn] r20271 - in pypy/branch/somepbc-refactoring/pypy/translator: . tool

arigo at codespeak.net arigo at codespeak.net
Sat Nov 26 12:19:03 CET 2005


Author: arigo
Date: Sat Nov 26 12:19:01 2005
New Revision: 20271

Modified:
   pypy/branch/somepbc-refactoring/pypy/translator/tool/graphpage.py
   pypy/branch/somepbc-refactoring/pypy/translator/translator.py
Log:
Started fixing the pygame viewer.  To be able to view graphs before they are
annotated (so before the FunctionDesc asks for graphs), there is a hack in
TranslationContext where we can compute the graph of a function "in advance"
and make sure it will be returned to the FunctionDesc the first time it asks.



Modified: pypy/branch/somepbc-refactoring/pypy/translator/tool/graphpage.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/tool/graphpage.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/tool/graphpage.py	Sat Nov 26 12:19:01 2005
@@ -97,10 +97,19 @@
         self.translator = translator
         self.annotator = translator.annotator
         self.func_names = func_names or {}
-        functions = functions or translator.functions
-        graphs = [translator.getflowgraph(func) for func in functions]
+        if functions:
+            graphs = []
+            for func in functions:
+                graphs += self.graphsof(func)
+        else:
+            graphs = self.translator.graphs
+        if not graphs:
+            if hasattr(translator, 'entrypoint'):
+                graphs = self.graphsof(translator.entrypoint)
+            else:
+                raise Exception("no graph to show")
         gs = [(graph.name, graph) for graph in graphs]
-        if self.annotator and self.annotator.blocked_functions:
+        if self.annotator and self.annotator.blocked_graphs:
             for block, was_annotated in self.annotator.annotated.items():
                 if not was_annotated:
                     block.fillcolor = "red"
@@ -137,6 +146,21 @@
         for graph in graphs:
             traverse(visit, graph)
 
+    def graphsof(self, func):
+        graphs = []
+        if self.annotator:
+            funcdesc = self.annotator.bookkeeper.getdesc(func)
+            graphs = funcdesc._cache.values()
+        if not graphs:
+            # build a new graph, mark it as "to be returned to the annotator the
+            # next time it asks for a graph for the same function"
+            # (note that this buildflowgraph() call will return the same graph
+            # if called again, from the _prebuilt_graphs cache)
+            graph = self.translator.buildflowgraph(func)
+            self.translator._prebuilt_graphs[func] = graph
+            graphs = [graph]
+        return graphs
+
     def followlink(self, varname):
         # clicking on a variable name shows its binding history
         cur_value = self.current_value[varname]

Modified: pypy/branch/somepbc-refactoring/pypy/translator/translator.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/translator.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/translator.py	Sat Nov 26 12:19:01 2005
@@ -32,6 +32,7 @@
         self.rtyper = None
         self.graphs = []      # [graph]
         self.callgraph = {}   # {opaque_tag: (caller-graph, callee-graph)}
+        self._prebuilt_graphs = {}   # only used by the pygame viewer
         # the following is an index into self.functions from where to check
         #self._callgraph_complete = 0
 
@@ -40,16 +41,19 @@
         if not isinstance(func, types.FunctionType):
             raise TypeError("buildflowgraph() expects a function, "
                             "got %r" % (func,))
-        if self.flags.get('verbose'):
-            log.start(nice_repr_for_func(func))
-        space = FlowObjSpace()
-        space.__dict__.update(self.flags)   # xxx push flags there
-        graph = space.build_flow(func)
-        if self.flags.get('simplifying'):
-            simplify_graph(graph)
-        if self.flags.get('verbose'):
-            log.done(func.__name__)
-        self.graphs.append(graph)   # store the graph in our list
+        if func in self._prebuilt_graphs:
+            graph = self._prebuilt_graphs.pop(func)
+        else:
+            if self.flags.get('verbose'):
+                log.start(nice_repr_for_func(func))
+            space = FlowObjSpace()
+            space.__dict__.update(self.flags)   # xxx push flags there
+            graph = space.build_flow(func)
+            if self.flags.get('simplifying'):
+                simplify_graph(graph)
+            if self.flags.get('verbose'):
+                log.done(func.__name__)
+            self.graphs.append(graph)   # store the graph in our list
         if called_by_graph:
             # update the call graph
             key = called_by_graph, graph, call_tag



More information about the Pypy-commit mailing list