[pypy-svn] r64055 - in pypy/branch/pyjitpl5-simplify/pypy/jit: backend/llgraph backend/minimal backend/minimal/test backend/x86 metainterp

arigo at codespeak.net arigo at codespeak.net
Tue Apr 14 13:50:30 CEST 2009


Author: arigo
Date: Tue Apr 14 13:50:29 2009
New Revision: 64055

Added:
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/support.py   (contents, props changed)
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_zrpy_exception.py
      - copied, changed from r64050, pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/test/test_zrpy_exception.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_zrpy_tl.py   (contents, props changed)
Modified:
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_basic.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py
Log:
In-progress, but many translation tests are passing.


Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py	Tue Apr 14 13:50:29 2009
@@ -63,6 +63,8 @@
 
 
 class BaseCPU(model.AbstractCPU):
+    has_lltype = True
+    has_ootype = True
 
     def __init__(self, rtyper, stats=None, translate_support_code=False,
                  annmixlevel=None):

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py	Tue Apr 14 13:50:29 2009
@@ -7,6 +7,8 @@
 
 
 class CPU(object):
+    has_lltype = True
+    has_ootype = False    # XXX for now
 
     def __init__(self, rtyper, stats, translate_support_code=False,
                  mixlevelann=None):
@@ -79,7 +81,7 @@
                 continue
             if op.opnum == rop.FAIL:
                 break
-            raise 0, "bad opnum"
+            assert 0, "bad opnum"
         #
         for i in range(len(op.args)):
             box = op.args[i]
@@ -102,8 +104,8 @@
                 raise GuardFailed
         elif opnum == rop.GUARD_CLASS:
             value = argboxes[0].getptr(rclass.OBJECTPTR)
-            expected_class = self.cast_int_to_ptr(rclass.CLASSTYPE,
-                                                  argboxes[1].getint())
+            adr = argboxes[1].getaddr(self)
+            expected_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
             if value.typeptr != expected_class:
                 raise GuardFailed
         elif opnum == rop.GUARD_VALUE:
@@ -117,10 +119,11 @@
             if self.current_exc_inst:
                 raise GuardFailed
         elif opnum == rop.GUARD_EXCEPTION:
-            expected_exception = argboxes[0].getptr(rclass.CLASSTYPE)
-            assert expected_exception
+            adr = argboxes[0].getaddr(self)
+            expected_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
+            assert expected_class
             exc = self.current_exc_inst
-            if exc and rclass.ll_isinstance(exc, expected_exception):
+            if exc and rclass.ll_isinstance(exc, expected_class):
                 raise GuardFailed
         else:
             assert 0, "unknown guard op"
@@ -164,6 +167,9 @@
             def new(length):
                 p = malloc(ARRAY, length)
                 return cast_opaque_ptr(GCREF, p)
+            def length(pbox):
+                p = reveal_ptr(PTR, pbox)
+                return len(p)
             def getarrayitem(pbox, index):
                 p = reveal_ptr(PTR, pbox)
                 x = p[index]
@@ -174,6 +180,7 @@
                 p[index] = x
         """ % dict).compile() in dict2
         return ArrayDescr(dict2['new'],
+                          dict2['length'],
                           dict2['getarrayitem'],
                           dict2['setarrayitem'])
 
@@ -207,6 +214,7 @@
 
     def do_new(self, args, sizedescr):
         assert isinstance(sizedescr, SizeDescr)
+        assert sizedescr.alloc is not None
         p = sizedescr.alloc()
         return BoxPtr(p)
 
@@ -214,35 +222,41 @@
 
     def do_getfield_gc(self, args, fielddescr):
         assert isinstance(fielddescr, FieldDescr)
+        assert fielddescr.getfield is not None
         return fielddescr.getfield(args[0])
 
     do_getfield_raw = do_getfield_gc
 
     def do_setfield_gc(self, args, fielddescr):
         assert isinstance(fielddescr, FieldDescr)
+        assert fielddescr.setfield is not None
         fielddescr.setfield(args[0], args[1])
 
     do_setfield_raw = do_setfield_gc
 
     def do_new_array(self, args, arraydescr):
         assert isinstance(arraydescr, ArrayDescr)
+        assert arraydescr.new is not None
         p = arraydescr.new(args[0].getint())
         return BoxPtr(p)
 
     def do_arraylen_gc(self, args, arraydescr):
         assert isinstance(arraydescr, ArrayDescr)
+        assert arraydescr.length is not None
         return BoxInt(arraydescr.length(args[0]))
 
     do_arraylen_raw = do_arraylen_gc
 
     def do_getarrayitem_gc(self, args, arraydescr):
         assert isinstance(arraydescr, ArrayDescr)
+        assert arraydescr.getarrayitem is not None
         index = args[1].getint()
         return arraydescr.getarrayitem(args[0], index)
     do_getarrayitem_raw = do_getarrayitem_gc
 
     def do_setarrayitem_gc(self, args, arraydescr):
         assert isinstance(arraydescr, ArrayDescr)
+        assert arraydescr.setarrayitem is not None
         index = args[1].getint()
         arraydescr.setarrayitem(args[0], index, args[2])
 
@@ -293,6 +307,8 @@
     def do_call(self, args, calldescr):
         if not we_are_translated():
             py.test.skip("call not supported in non-translated version")
+        assert isinstance(calldescr, CallDescr)
+        assert calldescr.call is not None
         self.clear_exception()
         try:
             return calldescr.call(args[0].getaddr(self), args[1:])
@@ -344,10 +360,14 @@
 
 
 class SizeDescr(AbstractDescr):
+    alloc = None
     def __init__(self, alloc):
         self.alloc = alloc
 
 class FieldDescr(AbstractDescr):
+    getfield = None
+    setfield = None
+    _sort_key = 0
     def __init__(self, getfield, setfield, sort_key):
         self.getfield = getfield
         self.setfield = setfield
@@ -356,12 +376,19 @@
         return self._sort_key
 
 class ArrayDescr(AbstractDescr):
-    def __init__(self, new, getarrayitem, setarrayitem):
+    new = None
+    length = None
+    getarrayitem = None
+    setarrayitem = None
+    def __init__(self, new, length, getarrayitem, setarrayitem):
         self.new = new
+        self.length = length
         self.getarrayitem = getarrayitem
         self.setarrayitem = setarrayitem
 
 class CallDescr(AbstractDescr):
+    call = None
+    errbox = None
     def __init__(self, FUNC, call, errbox):
         self.FUNC = FUNC
         self.call = call
@@ -399,6 +426,7 @@
             return i
         i += len(STRUCT._names) + 1
 
+ at specialize.arg(0)
 def reveal_ptr(PTR, box):
     if PTR.TO._gckind == 'gc':
         return box.getptr(PTR)

Added: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/support.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/support.py	Tue Apr 14 13:50:29 2009
@@ -0,0 +1,58 @@
+# XXX copy and paste from backend/x86/support.py
+import py
+from pypy.jit.metainterp.history import log
+
+
+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.minimal.runner import CPU
+    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=CPU,
+                                    **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-simplify/pypy/jit/backend/minimal/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_basic.py	Tue Apr 14 13:50:29 2009
@@ -3,12 +3,8 @@
 from pypy.jit.metainterp.test import test_basic
 
 class JitMixin(test_basic.LLJitMixin):
-    type_system = 'lltype'
     CPUClass = CPU
 
-    def check_jumps(self, maxcount):
-        pass
-
 class TestBasic(JitMixin, test_basic.BasicTests):
     # for the individual tests see
     # ====> ../../../metainterp/test/test_basic.py

Copied: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_zrpy_exception.py (from r64050, pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/test/test_zrpy_exception.py)
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/test/test_zrpy_exception.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_zrpy_exception.py	Tue Apr 14 13:50:29 2009
@@ -1,11 +1,29 @@
-
 import py
-from pypy.jit.metainterp.test import test_zrpy_exception
-from pypy.jit.backend.x86.test.test_zrpy_slist import Jit386Mixin
-from pypy.jit.backend.x86.support import c_meta_interp
+from pypy.jit.backend.minimal.runner import CPU
+from pypy.jit.backend.minimal.support import c_meta_interp
+from pypy.jit.metainterp.test import test_basic, test_zrpy_exception
+
+
+class TranslatedJitMixin(test_basic.LLJitMixin):
+    CPUClass = CPU
+
+    def meta_interp(self, *args, **kwds):
+        return c_meta_interp(*args, **kwds)
 
-class TestException(Jit386Mixin, test_zrpy_exception.TestLLExceptions):
+    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 TestException(TranslatedJitMixin, test_zrpy_exception.TestLLExceptions):
     # for the individual tests see
     # ====> ../../../metainterp/test/test_exception.py
     pass
-

Added: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_zrpy_tl.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/test/test_zrpy_tl.py	Tue Apr 14 13:50:29 2009
@@ -0,0 +1,8 @@
+import py
+from pypy.jit.metainterp.test.test_tl import ToyLanguageTests
+from pypy.jit.backend.minimal.test.test_zrpy_exception import TranslatedJitMixin
+
+class TestTL(TranslatedJitMixin, ToyLanguageTests):
+    # for the individual tests see
+    # ====> ../../../metainterp/test/test_tl.py
+    pass

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py	Tue Apr 14 13:50:29 2009
@@ -62,6 +62,8 @@
 
 class CPU386(object):
     debug = True
+    has_lltype = True
+    has_ootype = False
 
     BOOTSTRAP_TP = lltype.FuncType([lltype.Ptr(rffi.CArray(lltype.Signed))],
                                    lltype.Signed)

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py	Tue Apr 14 13:50:29 2009
@@ -253,6 +253,7 @@
 
 # XXX: these ops should probably be delegated to the backend
 def do_str_stritem_nonneg(cpu, args, descr=None):
+    assert cpu.has_ootype
     obj = args[0].getobj()
     str = ootype.cast_from_object(ootype.String, obj)
     index = args[1].getint()
@@ -260,6 +261,7 @@
     return ConstInt(ord(res))
 
 def do_str_strconcat(cpu, args, descr=None):
+    assert cpu.has_ootype
     obj1 = args[0].getobj()
     obj2 = args[1].getobj()
     str1 = ootype.cast_from_object(ootype.String, obj1)
@@ -269,12 +271,14 @@
     return ConstObj(objres)
 
 def do_str_strlen(cpu, args, descr=None):
+    assert cpu.has_ootype
     obj = args[0].getobj()
     str = ootype.cast_from_object(ootype.String, obj)
     res = str.ll_strlen()
     return ConstInt(res)
 
 def do_oostring(cpu, args, descr=None):
+    assert cpu.has_ootype
     obj = args[0].getint() # XXX what about other types?
     base = args[1].getint()
     res = ootype.cast_to_object(ootype.oostring(obj, base))



More information about the Pypy-commit mailing list