[pypy-svn] r20841 - pypy/dist/pypy/jit/test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Dec 7 16:32:02 CET 2005


Author: cfbolz
Date: Wed Dec  7 16:32:01 2005
New Revision: 20841

Modified:
   pypy/dist/pypy/jit/test/test_llabstractinterp.py
Log:
(arigo, cfbolz):

refactored test to use llinterp to interpret each graph


Modified: pypy/dist/pypy/jit/test/test_llabstractinterp.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_llabstractinterp.py	(original)
+++ pypy/dist/pypy/jit/test/test_llabstractinterp.py	Wed Dec  7 16:32:01 2005
@@ -1,21 +1,55 @@
 from pypy.translator.translator import TranslationContext
 from pypy.rpython.annlowlevel import annotate_lowlevel_helper
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.llinterp import LLInterpreter
+from pypy.rpython import rstr
+from pypy.annotation import model as annmodel
 from pypy.jit.llabstractinterp import LLAbstractInterp
 
-def test_simple():
-    def ll_function(x, y):
-        return x + y
 
+def annotation(a, x):
+    T = lltype.typeOf(x)
+    if T == lltype.Ptr(rstr.STR):
+        t = str
+    else:
+        t = annmodel.lltype_to_annotation(T)
+    return a.typeannotation(t)
+
+def abstrinterp(ll_function, argvalues, arghints):
     t = TranslationContext()
     a = t.buildannotator()
-    argtypes = [a.typeannotation(int), a.typeannotation(int)]
+    argtypes = [annotation(a, value) for value in argvalues]
     graph1 = annotate_lowlevel_helper(a, ll_function, argtypes)
-    t.buildrtyper().specialize()
+    rtyper = t.buildrtyper()
+    rtyper.specialize()
     interp = LLAbstractInterp()
-    # tell 'y=42'
-    hints = {graph1.getargs()[1]: 42}
+    hints = {}
+    argvalues2 = argvalues[:]
+    lst = list(arghints)
+    lst.sort()
+    lst.reverse()
+    for hint in lst:
+        hints[graph1.getargs()[hint]] = argvalues2[hint]
+        del argvalues2[hint]
     graph2 = interp.eval(graph1, hints)
+    # check the result by running it
+    llinterp = LLInterpreter(rtyper)
+    result1 = llinterp.eval_graph(graph1, argvalues)
+    result2 = llinterp.eval_graph(graph2, argvalues2)
+    assert result1 == result2
+    # return a summary of the instructions left in graph2
+    insns = {}
+    for block in graph2.iterblocks():
+        for op in block.operations:
+            insns[op.opname] = insns.get(op.opname, 0) + 1
+    return graph2, insns
+
+
+def test_simple():
+    def ll_function(x, y):
+        return x + y
+
+    graph2, insns = abstrinterp(ll_function, [6, 42], [1])
     # check that the result is "lambda x: x+42"
     assert len(graph2.startblock.operations) == 1
     assert len(graph2.getargs()) == 1



More information about the Pypy-commit mailing list