[pypy-svn] r46580 - in pypy/dist/pypy/translator: cli/test jvm jvm/test oosupport/test_template

antocuni at codespeak.net antocuni at codespeak.net
Fri Sep 14 14:45:13 CEST 2007


Author: antocuni
Date: Fri Sep 14 14:45:10 2007
New Revision: 46580

Added:
   pypy/dist/pypy/translator/jvm/test/test_backendopt.py   (contents, props changed)
   pypy/dist/pypy/translator/oosupport/test_template/backendopt.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/cli/test/test_backendopt.py
   pypy/dist/pypy/translator/jvm/generator.py
   pypy/dist/pypy/translator/jvm/genjvm.py
   pypy/dist/pypy/translator/jvm/test/runtest.py
Log:
move test_backendopt to oosupport, and port it to genvjm



Modified: pypy/dist/pypy/translator/cli/test/test_backendopt.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_backendopt.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_backendopt.py	Fri Sep 14 14:45:10 2007
@@ -1,27 +1,7 @@
 import py
 from pypy.translator.cli.test.runtest import compile_function
-from pypy.translator.c.test.test_backendoptimized import \
-     TestTypedOptimizedSwitchTestCase as c_TestTypedOptimizedSwitchTestCase
-
-class CTestCompat:
-    def CodeGenerator(self):
-        return self
+from pypy.translator.oosupport.test_template.backendopt import BaseTestOptimizedSwitch
 
+class TestOptimizedSwitch(BaseTestOptimizedSwitch):
     def getcompiled(self, fn, annotation):
         return compile_function(fn, annotation, backendopt=True)
-
-class TestOptimizedSwitchTestCase(CTestCompat, c_TestTypedOptimizedSwitchTestCase):
-
-    def test_switch_naive(self):
-        def fn(x):
-            if x == -1:
-                return 3
-            elif x == 3:
-                return 9
-            elif x == 9:
-                return -1
-            return 42
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(fn, [int])
-        for x in (-5,-1,0,3,9,27,48):
-            assert fn(x) == fn(x)

Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py	(original)
+++ pypy/dist/pypy/translator/jvm/generator.py	Fri Sep 14 14:45:10 2007
@@ -1378,3 +1378,8 @@
                        
     def get_instruction_count(self):
         return self.curfunc.instr_counter
+
+    def emit_tableswitch(self, low, lbls, default):
+        pass
+
+        

Modified: pypy/dist/pypy/translator/jvm/genjvm.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/genjvm.py	(original)
+++ pypy/dist/pypy/translator/jvm/genjvm.py	Fri Sep 14 14:45:10 2007
@@ -9,6 +9,8 @@
 from pypy.tool.udir import udir
 from pypy.translator.translator import TranslationContext
 from pypy.translator.oosupport.genoo import GenOO
+from pypy.translator.backendopt.all import backend_optimizations
+from pypy.translator.backendopt.checkvirtual import check_virtual_methods
 
 from pypy.translator.jvm.generator import JasminGenerator
 from pypy.translator.jvm.option import getoption
@@ -202,7 +204,7 @@
         sys.stderr.write(stderr)
         return stdout
         
-def generate_source_for_function(func, annotation):
+def generate_source_for_function(func, annotation, backendopt=False):
     
     """
     Given a Python function and some hints about its argument types,
@@ -216,6 +218,9 @@
     ann = t.buildannotator()
     ann.build_types(func, annotation)
     t.buildrtyper(type_system="ootype").specialize()
+    if backendopt:
+        check_virtual_methods(ootype.ROOT)
+        backend_optimizations(t)
     main_graph = t.graphs[0]
     if getoption('view'): t.view()
     if getoption('wd'): tmpdir = py.path.local('.')

Modified: pypy/dist/pypy/translator/jvm/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/jvm/test/runtest.py	Fri Sep 14 14:45:10 2007
@@ -84,7 +84,7 @@
         self._ann = None
         self._jvm_src = None
 
-    def _compile(self, fn, args, ann=None):
+    def _compile(self, fn, args, ann=None, backendopt=False):
         if ann is None:
             ann = [lltype_to_annotation(typeOf(x)) for x in args]
         if self._func is fn and self._ann == ann:
@@ -93,7 +93,7 @@
             self._func = fn
             self._ann = ann
             olddefs = patch_os()
-            self._jvm_src = generate_source_for_function(fn, ann)
+            self._jvm_src = generate_source_for_function(fn, ann, backendopt)
             unpatch_os(olddefs)
             if not getoption('noasm'):
                 self._jvm_src.compile()

Added: pypy/dist/pypy/translator/jvm/test/test_backendopt.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/jvm/test/test_backendopt.py	Fri Sep 14 14:45:10 2007
@@ -0,0 +1,8 @@
+import py
+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.translator.oosupport.test_template.backendopt import BaseTestOptimizedSwitch
+
+class TestOptimizedSwitch(BaseTestOptimizedSwitch):
+    def getcompiled(self, fn, annotation):
+        t = JvmTest()
+        return t._compile(fn, None, annotation, backendopt=True)

Added: pypy/dist/pypy/translator/oosupport/test_template/backendopt.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/oosupport/test_template/backendopt.py	Fri Sep 14 14:45:10 2007
@@ -0,0 +1,25 @@
+import py
+from pypy.translator.c.test.test_backendoptimized import \
+     TestTypedOptimizedSwitchTestCase as c_TestTypedOptimizedSwitchTestCase
+
+class BaseTestOptimizedSwitch(c_TestTypedOptimizedSwitchTestCase):
+
+    def CodeGenerator(self):
+        return self
+
+    def getcompiled(self, fn, annotation):
+        return compile_function(fn, annotation, backendopt=True)
+
+    def test_switch_naive(self):
+        def fn(x):
+            if x == -1:
+                return 3
+            elif x == 3:
+                return 9
+            elif x == 9:
+                return -1
+            return 42
+        codegenerator = self.CodeGenerator()
+        fn = codegenerator.getcompiled(fn, [int])
+        for x in (-5,-1,0,3,9,27,48):
+            assert fn(x) == fn(x)



More information about the Pypy-commit mailing list