[pypy-svn] r64768 - in pypy/branch/pyjitpl5/pypy/jit/backend: minimal minimal/test test x86 x86/test

antocuni at codespeak.net antocuni at codespeak.net
Tue Apr 28 14:51:58 CEST 2009


Author: antocuni
Date: Tue Apr 28 14:51:58 2009
New Revision: 64768

Added:
   pypy/branch/pyjitpl5/pypy/jit/backend/test/support.py   (contents, props changed)
Removed:
   pypy/branch/pyjitpl5/pypy/jit/backend/minimal/support.py
Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_zrpy_exception.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_slist.py
Log:
merge the two almost identical c_meta_interp functions found in x86/support.py
and minimal/support.py into a nice subclassable class, reusable by all
backends (even ootype ones, in the future)



Modified: pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_zrpy_exception.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_zrpy_exception.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_zrpy_exception.py	Tue Apr 28 14:51:58 2009
@@ -1,29 +1,18 @@
 import py
 from pypy.jit.backend.minimal.runner import LLtypeCPU, OOtypeCPU
-from pypy.jit.backend.minimal.support import c_meta_interp
-from pypy.jit.metainterp.test import test_basic, test_zrpy_exception
+from pypy.jit.backend.test.support import CCompiledMixin
+from pypy.jit.metainterp.test import test_zrpy_exception
 
-
-class TranslatedJitMixin(test_basic.LLJitMixin):
+class LLTranslatedJitMixin(CCompiledMixin):
     CPUClass = LLtypeCPU
 
     def meta_interp(self, *args, **kwds):
-        return c_meta_interp(*args, **kwds)
-
-    def check_loops(self, *args, **kwds):
-        pass
-    def check_tree_loop_count(self, *args, **kwds):
-        pass
-    def check_enter_count(self, *args, **kwds):
-        pass
-    def check_enter_count_at_most(self, *args, **kwds):
-        pass
-
-    def interp_operations(self, *args, **kwds):
-        py.test.skip("interp_operations test skipped")
+        from pypy.jit.metainterp.simple_optimize import Optimizer
+        kwds['optimizer'] = Optimizer
+        return CCompiledMixin.meta_interp(self, *args, **kwds)
 
 
-class TestException(TranslatedJitMixin, test_zrpy_exception.TestLLExceptions):
+class TestLLtype(LLTranslatedJitMixin, test_zrpy_exception.TestLLExceptions):
     # for the individual tests see
     # ====> ../../../metainterp/test/test_exception.py
     pass

Added: pypy/branch/pyjitpl5/pypy/jit/backend/test/support.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/support.py	Tue Apr 28 14:51:58 2009
@@ -0,0 +1,92 @@
+import py
+from pypy.jit.metainterp.history import log
+from pypy.translator.translator import TranslationContext
+
+class BaseCompiledMixin(object):
+
+    type_system = None
+    CPUClass = None
+
+    def _get_TranslationContext(self):
+        return TranslationContext()
+
+    def _compile_and_run(self, t, entry_point, entry_point_graph, args):
+        raise NotImplementedError
+
+    def meta_interp(self, function, args, repeat=1, **kwds): # XXX ignored
+        from pypy.jit.metainterp.warmspot import WarmRunnerDesc
+        from pypy.annotation.listdef import s_list_of_strings
+        from pypy.annotation import model as annmodel
+
+        for arg in args:
+            assert isinstance(arg, int)
+
+        t = self._get_TranslationContext()
+        if repeat != 1:
+            src = py.code.Source("""
+            def entry_point(argv):
+                args = (%s,)
+                res = function(*args)
+                for k in range(%d - 1):
+                    res = function(*args)
+                print res
+                return 0
+            """ % (", ".join(['int(argv[%d])' % (i + 1) for i in range(len(args))]), repeat))
+        else:
+            src = py.code.Source("""
+            def entry_point(argv):
+                args = (%s,)
+                res = function(*args)
+                print res
+                return 0
+            """ % (", ".join(['int(argv[%d])' % (i + 1) for i in range(len(args))]),))
+        exec src.compile() in locals()
+
+        t.buildannotator().build_types(function, [int] * len(args))
+        t.buildrtyper(type_system=self.type_system).specialize()
+        warmrunnerdesc = WarmRunnerDesc(t, translate_support_code=True,
+                                        CPUClass=self.CPUClass,
+                                        **kwds)
+        warmrunnerdesc.state.set_param_threshold(3)          # for tests
+        warmrunnerdesc.state.set_param_trace_eagerness(2)    # for tests
+        mixlevelann = warmrunnerdesc.annhelper
+        entry_point_graph = mixlevelann.getgraph(entry_point, [s_list_of_strings],
+                                                 annmodel.SomeInteger())
+        warmrunnerdesc.finish()
+        return self._compile_and_run(t, entry_point, entry_point_graph, args)
+
+    def check_loops(self, *args, **kwds):
+        pass
+
+    def check_tree_loop_count(self, *args, **kwds):
+        pass
+
+    def check_enter_count(self, *args, **kwds):
+        pass
+
+    def check_enter_count_at_most(self, *args, **kwds):
+        pass
+
+    def interp_operations(self, *args, **kwds):
+        py.test.skip("interp_operations test skipped")
+
+
+class CCompiledMixin(BaseCompiledMixin):
+    type_system = 'lltype'
+
+    def _get_TranslationContext(self):
+        t = TranslationContext()
+        t.config.translation.gc = 'boehm'
+        return t
+
+    def _compile_and_run(self, t, entry_point, entry_point_graph, args):
+        from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
+        # XXX patch exceptions
+        cbuilder = CBuilder(t, entry_point, config=t.config)
+        cbuilder.generate_source()
+        exe_name = cbuilder.compile()
+        log('---------- Test starting ----------')
+        stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
+        res = int(stdout)
+        log('---------- Test done (%d) ----------' % (res,))
+        return res

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/support.py	Tue Apr 28 14:51:58 2009
@@ -31,57 +31,3 @@
         else:
             GC_malloc = boehmlib.GC_malloc
             return cast(GC_malloc, c_void_p).value
-
-def c_meta_interp(function, args, repeat=1, **kwds):
-    from pypy.translator.translator import TranslationContext
-    from pypy.jit.metainterp.warmspot import WarmRunnerDesc
-    from pypy.jit.backend.x86.runner import CPU386
-    from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
-    from pypy.annotation.listdef import s_list_of_strings
-    from pypy.annotation import model as annmodel
-    
-    for arg in args:
-        assert isinstance(arg, int)
-
-    t = TranslationContext()
-    t.config.translation.gc = 'boehm'
-    if repeat != 1:
-        src = py.code.Source("""
-        def entry_point(argv):
-            args = (%s,)
-            res = function(*args)
-            for k in range(%d - 1):
-                res = function(*args)
-            print res
-            return 0
-        """ % (", ".join(['int(argv[%d])' % (i + 1) for i in range(len(args))]), repeat))
-    else:
-        src = py.code.Source("""
-        def entry_point(argv):
-            args = (%s,)
-            res = function(*args)
-            print res
-            return 0
-        """ % (", ".join(['int(argv[%d])' % (i + 1) for i in range(len(args))]),))
-    exec src.compile() in locals()
-
-    t.buildannotator().build_types(function, [int] * len(args))
-    t.buildrtyper().specialize()
-    warmrunnerdesc = WarmRunnerDesc(t, translate_support_code=True,
-                                    CPUClass=CPU386,
-                                    **kwds)
-    warmrunnerdesc.state.set_param_threshold(3)          # for tests
-    warmrunnerdesc.state.set_param_trace_eagerness(2)    # for tests
-    mixlevelann = warmrunnerdesc.annhelper
-    entry_point_graph = mixlevelann.getgraph(entry_point, [s_list_of_strings],
-                                             annmodel.SomeInteger())
-    warmrunnerdesc.finish()
-    # XXX patch exceptions
-    cbuilder = CBuilder(t, entry_point, config=t.config)
-    cbuilder.generate_source()
-    exe_name = cbuilder.compile()
-    log('---------- Test starting ----------')
-    stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
-    res = int(stdout)
-    log('---------- Test done (%d) ----------' % (res,))
-    return res

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_slist.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_slist.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_slist.py	Tue Apr 28 14:51:58 2009
@@ -1,27 +1,11 @@
 
 import py
 from pypy.jit.metainterp.test.test_slist import ListTests
-from pypy.jit.backend.x86.support import c_meta_interp
+from pypy.jit.backend.x86.runner import CPU386
+from pypy.jit.backend.test.support import CCompiledMixin
 
-class Jit386Mixin(object):
-    @staticmethod
-    def meta_interp(fn, args, **kwds):
-        return c_meta_interp(fn, args, **kwds)
-
-    def check_loops(self, *args, **kwds):
-        pass
-
-    def check_tree_loop_count(self, *args, **kwds):
-        pass
-
-    def check_enter_count(self, *args, **kwds):
-        pass
-
-    def check_enter_count_at_most(self, *args, **kwds):
-        pass
-
-    def interp_operations(self, *args, **kwds):
-        py.test.skip("using interp_operations")
+class Jit386Mixin(CCompiledMixin):
+    CPUClass = CPU386
 
 class TestSList(Jit386Mixin, ListTests):
     # for the individual tests see



More information about the Pypy-commit mailing list