[pypy-svn] r34046 - in pypy/dist/pypy/jit: codegen/i386/test timeshifter/test

ac at codespeak.net ac at codespeak.net
Wed Nov 1 17:40:14 CET 2006


Author: ac
Date: Wed Nov  1 17:40:13 2006
New Revision: 34046

Added:
   pypy/dist/pypy/jit/codegen/i386/test/test_genc_portal.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/timeshifter/test/test_portal.py
Log:
Port the portal tests to codegen/i386.


Added: pypy/dist/pypy/jit/codegen/i386/test/test_genc_portal.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_genc_portal.py	Wed Nov  1 17:40:13 2006
@@ -0,0 +1,76 @@
+import py, os
+from pypy.annotation import model as annmodel
+from pypy.annotation.listdef import s_list_of_strings
+from pypy.rlib.unroll import unrolling_iterable
+from pypy.translator.c.genc import CStandaloneBuilder
+from pypy.jit.timeshifter.test import test_portal
+from pypy.jit.codegen.i386.rgenop import RI386GenOp
+from pypy.rpython.annlowlevel import PseudoHighLevelCallable
+
+class I386PortalTestMixin(object):
+    RGenOp = RI386GenOp
+
+    def postprocess_timeshifting(self):
+        annhelper = self.hrtyper.annhelper
+        convert_result = getattr(self.main, 'convert_result', str)
+        annotator = self.rtyper.annotator
+        args_s = [annotator.binding(v) for v in self.maingraph.getargs()]
+        s_result = self.rtyper.annotator.binding(self.maingraph.getreturnvar())
+        main_fnptr = self.rtyper.type_system.getcallable(self.maingraph)
+        main = PseudoHighLevelCallable(main_fnptr, args_s, s_result)
+        
+        if hasattr(self.main, 'convert_arguments'):
+            decoders = self.main.convert_arguments
+            assert len(decoders) == len(args_s)
+        else:
+            decoders = [int] * len(args_s)
+        decoders = unrolling_iterable(decoders)
+        def ll_main(argv):
+            args = ()
+            i = 1
+            for decoder in decoders:
+                args += (decoder(argv[i]),)
+                i = i + 1
+            try:
+                res = main(*args)
+            except Exception, e:
+                os.write(1, 'EXCEPTION: %s\n' % (e,))
+                return 0
+            os.write(1, convert_result(res) + '\n')
+            return 0
+
+        annhelper.getgraph(ll_main, [s_list_of_strings],
+                           annmodel.SomeInteger())
+        annhelper.finish()
+        t = self.rtyper.annotator.translator
+        t.config.translation.gc = 'boehm'
+        self.cbuilder = CStandaloneBuilder(t, ll_main)
+        self.cbuilder.generate_source()
+        self.cbuilder.compile()
+        
+    def timeshift_from_portal(self, main, portal, main_args,
+                              inline=None, policy=None,
+                              backendoptimize=False):
+        self.main = main
+        self._timeshift_from_portal(main, portal, main_args,
+                                    inline=inline, policy=policy,
+                                    backendoptimize=backendoptimize)
+        cmdargs = ' '.join([str(arg) for arg in main_args])
+        output = self.cbuilder.cmdexec(cmdargs)
+        lines = output.split()
+        lastline = lines[-1]
+        assert not lastline.startswith('EXCEPTION:')
+        if hasattr(main, 'convert_result'):
+            return lastline
+        else:
+            return int(lastline)    # assume an int
+        
+    def check_insns(self, expected=None, **counts):
+        "Cannot check instructions in the generated assembler."
+    
+class TestPromotion(I386PortalTestMixin,
+                test_portal.TestPortal):
+
+    # for the individual tests see
+    # ====> ../../../timeshifter/test/test_promotion.py
+    pass

Modified: pypy/dist/pypy/jit/timeshifter/test/test_portal.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_portal.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_portal.py	Wed Nov  1 17:40:13 2006
@@ -1,6 +1,6 @@
 from pypy import conftest
 from pypy.translator.translator import graphof
-from pypy.jit.timeshifter.test.test_timeshift import hannotate
+from pypy.jit.timeshifter.test.test_timeshift import hannotate, getargtypes
 from pypy.jit.timeshifter.hrtyper import HintRTyper
 from pypy.jit.timeshifter.test.test_timeshift import P_NOVIRTUAL
 from pypy.rpython.llinterp import LLInterpreter
@@ -20,45 +20,66 @@
         del cls._cache
         del cls._cache_order
 
-    def timeshift_from_portal(self, main, portal, main_args,
+    def postprocess_timeshifting(self):
+        self.readportalgraph = self.hrtyper.readportalgraph
+        
+    def _timeshift_from_portal(self, main, portal, main_args,
                               inline=None, policy=None,
                               backendoptimize=False):
-
+        # decode the 'values' if they are specified as strings
+        if hasattr(main, 'convert_arguments'):
+            assert len(main.convert_arguments) == len(values)
+            main_args = [decoder(value) for decoder, value in zip(
+                                        main.convert_arguments,
+                                        main_args)]
         key = main, portal, inline, policy, backendoptimize
         try:
-            maingraph, readportalgraph, rtyper = self._cache[key]
+            cache, argtypes = self._cache[key]
         except KeyError:
-            if len(self._cache_order) >= 3:
-                del self._cache[self._cache_order.pop(0)]
-
-            hs, ha, rtyper = hannotate(main, main_args, portal=portal,
-                                       policy=policy, inline=inline,
-                                       backendoptimize=backendoptimize)
-
-            t = rtyper.annotator.translator
-            maingraph = graphof(t, main)
-            # make the timeshifted graphs
-            hrtyper = HintRTyper(ha, rtyper, self.RGenOp)
-            origportalgraph = graphof(t, portal)
-            hrtyper.specialize(origportalgraph=origportalgraph,
-                               view = conftest.option.view)
-
-            for graph in ha.translator.graphs:
-                checkgraph(graph)
-                t.graphs.append(graph)
-
-            if conftest.option.view:
-                t.view()
-
-            readportalgraph = hrtyper.readportalgraph
-            self._cache[key] = maingraph, readportalgraph, rtyper
-            self._cache_order.append(key)
+            pass
+        else:
+            self.__dict__.update(cache)
+            assert argtypes == getargtypes(self.rtyper.annotator, main_args)
+            return
+
+        hs, ha, self.rtyper = hannotate(main, main_args, portal=portal,
+                                   policy=policy, inline=inline,
+                                   backendoptimize=backendoptimize)
+
+        t = self.rtyper.annotator.translator
+        self.maingraph = graphof(t, main)
+        # make the timeshifted graphs
+        self.hrtyper = HintRTyper(ha, self.rtyper, self.RGenOp)
+        origportalgraph = graphof(t, portal)
+        self.hrtyper.specialize(origportalgraph=origportalgraph,
+                           view = conftest.option.view)
+
+        for graph in ha.translator.graphs:
+            checkgraph(graph)
+            t.graphs.append(graph)
+
+        if conftest.option.view:
+            t.view()
+        self.postprocess_timeshifting()
+        self.readportalgraph = self.hrtyper.readportalgraph
+
+        # Populate the cache
+        if len(self._cache_order) >= 3:
+            del self._cache[self._cache_order.pop(0)]
+        cache = self.__dict__.copy()
+        self._cache[key] = cache, getargtypes(self.rtyper.annotator, main_args)
+        self._cache_order.append(key)
 
-        self.readportalgraph = readportalgraph
+    
+    def timeshift_from_portal(self, main, portal, main_args,
+                              inline=None, policy=None,
+                              backendoptimize=False):
+        self._timeshift_from_portal(main, portal, main_args,
+                                    inline=inline, policy=policy,
+                                    backendoptimize=backendoptimize)
         self.main_args = main_args
-        self.rtyper = rtyper
-        llinterp = LLInterpreter(rtyper)
-        res = llinterp.eval_graph(maingraph, main_args)
+        llinterp = LLInterpreter(self.rtyper)
+        res = llinterp.eval_graph(self.maingraph, main_args)
         return res
 
     def check_insns(self, expected=None, **counts):


More information about the pypy-svn mailing list