[pypy-svn] r17851 - pypy/dist/pypy/translator/goal
pedronis at codespeak.net
pedronis at codespeak.net
Sun Sep 25 15:13:58 CEST 2005
Author: pedronis
Date: Sun Sep 25 15:13:57 2005
New Revision: 17851
Modified:
pypy/dist/pypy/translator/goal/query.py
Log:
query to find backedgges in the callgraph
Modified: pypy/dist/pypy/translator/goal/query.py
==============================================================================
--- pypy/dist/pypy/translator/goal/query.py (original)
+++ pypy/dist/pypy/translator/goal/query.py Sun Sep 25 15:13:57 2005
@@ -513,3 +513,27 @@
l.sort()
for name, c in l:
print name, c
+
+def backcalls(t):
+ g = {}
+ for caller, callee in t.callgraph.itervalues():
+ g.setdefault(caller,[]).append(callee)
+
+ back = []
+ color = {}
+ WHITE, GRAY, BLACK = 0,1,2
+
+ def visit(fcur,witness=[]):
+ color[fcur] = GRAY
+ for f in dict.fromkeys(g.get(fcur, [])):
+ fcolor = color.get(f, WHITE)
+ if fcolor == WHITE:
+ visit(f,witness+[f])
+ elif fcolor == GRAY:
+ print "*", witness, f
+ back.append((fcur, f))
+ color[fcur] = BLACK
+
+ visit(t.entrypoint, [t.entrypoint])
+
+ return back
More information about the Pypy-commit
mailing list