[pypy-svn] r52683 - in pypy/dist/pypy: jit/codegen/cli jit/codegen/cli/test jit/codegen/i386/test jit/codegen/test jit/timeshifter jit/timeshifter/test rpython/ootypesystem translator/cli

antocuni at codespeak.net antocuni at codespeak.net
Tue Mar 18 13:53:27 CET 2008


Author: antocuni
Date: Tue Mar 18 13:53:27 2008
New Revision: 52683

Added:
   pypy/dist/pypy/jit/codegen/cli/test/test_gencli_ts.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/codegen/cli/operation.py
   pypy/dist/pypy/jit/codegen/cli/rgenop.py
   pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py
   pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
   pypy/dist/pypy/jit/timeshifter/exception.py
   pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
   pypy/dist/pypy/rpython/ootypesystem/rootype.py
   pypy/dist/pypy/translator/cli/constant.py
Log:
whack here and there until we can run the first timeshifted tests with
gencli



Modified: pypy/dist/pypy/jit/codegen/cli/operation.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/cli/operation.py	(original)
+++ pypy/dist/pypy/jit/codegen/cli/operation.py	Tue Mar 18 13:53:27 2008
@@ -154,7 +154,14 @@
         self.builder.il.EmitCall(OpCodes.Callvirt, meth_invoke, None)
         self.storeResult()
 
-        
+
+class GetField(Operation):
+
+    def __init__(self, builder, gv_obj, fieldname):
+        self.builder = builder
+        self.gv_obj = gv_obj
+        self.fieldname = fieldname
+
 
 def opcode2attrname(opcode):
     if opcode == 'ldc.r8 0':

Modified: pypy/dist/pypy/jit/codegen/cli/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/cli/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/cli/rgenop.py	Tue Mar 18 13:53:27 2008
@@ -1,11 +1,13 @@
 from pypy.tool.pairtype import extendabletype
 from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rlib.objectmodel import specialize
 from pypy.jit.codegen.model import AbstractRGenOp, GenBuilder, GenLabel
 from pypy.jit.codegen.model import GenVarOrConst, GenVar, GenConst, CodeGenSwitch
 from pypy.jit.codegen.cli import operation as ops
 from pypy.jit.codegen.cli.dumpgenerator import DumpGenerator
 from pypy.translator.cli.dotnet import CLR, typeof, new_array, box, unbox, clidowncast, classof
+from pypy.translator.cli.dotnet import cast_record_to_object, cast_object_to_record
 System = CLR.System
 Utils = CLR.pypy.runtime.Utils
 DelegateHolder = CLR.pypy.runtime.DelegateHolder
@@ -133,15 +135,24 @@
 
     def load(self, builder):
         index = self._get_index(builder)
-        t = self.obj.GetType()
+        if self.obj is None:
+            t = typeof(System.Object)
+        else:
+            t = self.obj.GetType()
         self._load_from_array(builder, index, t)
 
     @specialize.arg(1)
     def revealconst(self, T):
-        assert isinstance(T, ootype.OOType)
-        return unbox(self.obj, T)
+        if T is llmemory.Address:
+            return unbox(self.obj, ootype.ROOT) # XXX
+        elif isinstance(T, ootype.Record):
+            return cast_object_to_record(T, self.obj)
+        else:
+            assert isinstance(T, ootype.OOType)
+            return unbox(self.obj, T)
 
 
+OBJECT = System.Object._INSTANCE
 class FunctionConst(BaseConst):
 
     def __init__(self, delegatetype):
@@ -149,7 +160,8 @@
         self.delegatetype = delegatetype
 
     def getobj(self):
-        return self.holder
+        # XXX: should the conversion be done automatically?
+        return ootype.ooupcast(OBJECT, self.holder)
 
     def load(self, builder):
         holdertype = box(self.holder).GetType()
@@ -185,8 +197,15 @@
             return IntConst(llvalue)
         elif T is ootype.Bool:
             return IntConst(int(llvalue))
+        elif T is llmemory.Address:
+            assert llvalue is llmemory.NULL
+            return zero_const
+        elif isinstance(T, ootype.Record):
+            obj = cast_record_to_object(llvalue)
+            return ObjectConst(obj)
         elif isinstance(T, ootype.OOType):
-            return ObjectConst(box(llvalue))
+            obj = box(llvalue)
+            return ObjectConst(obj)
         else:
             assert False, "XXX not implemented"
 
@@ -220,6 +239,15 @@
         else:
             assert False
 
+    @staticmethod
+    @specialize.memo()
+    def fieldToken(T, name):
+        _, FIELD = T._lookup_field(name)
+        return name #, RCliGenOp.kindToken(FIELD)
+
+    def check_no_open_mc(self):
+        pass
+
     def newgraph(self, sigtoken, name):
         argsclass = sigtoken.args
         args = new_array(System.Type, len(argsclass)+1)
@@ -295,7 +323,13 @@
         op = ops.SameAs(self, gv_x)
         self.emit(op)
         return op.gv_res()
-        
+
+    def genop_getfield(self, fieldtoken, gv_ptr):
+        pass
+
+    def genop_setfield(self, fieldtoken, gv_ptr, gv_value):
+        pass
+
     def emit(self, op):
         op.emit()
 
@@ -406,4 +440,5 @@
 
 global_rgenop = RCliGenOp()
 RCliGenOp.constPrebuiltGlobal = global_rgenop.genconst
-zero_const = ObjectConst(ootype.null(ootype.ROOT))
+NULL = ootype.null(System.Object._INSTANCE)
+zero_const = ObjectConst(NULL)

Added: pypy/dist/pypy/jit/codegen/cli/test/test_gencli_ts.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/cli/test/test_gencli_ts.py	Tue Mar 18 13:53:27 2008
@@ -0,0 +1,52 @@
+import py
+from pypy.tool.udir import udir
+from pypy.translator.cli.entrypoint import StandaloneEntryPoint
+from pypy.translator.cli.gencli import GenCli
+from pypy.translator.cli.sdk import SDK
+from pypy.jit.codegen.i386.test.test_genc_ts import I386TimeshiftingTestMixin
+from pypy.jit.timeshifter.test import test_timeshift
+from pypy.jit.codegen.cli.rgenop import RCliGenOp
+
+class CliTimeshiftingTestMixin(I386TimeshiftingTestMixin):
+    RGenOp = RCliGenOp
+
+    def getgraph(self, fn):
+        bk = self.rtyper.annotator.bookkeeper
+        return bk.getdesc(fn).getuniquegraph()
+
+    def compile(self, ll_main):
+        graph = self.getgraph(ll_main)
+        entrypoint = StandaloneEntryPoint(graph)
+        gen = GenCli(udir, self.rtyper.annotator.translator, entrypoint)
+        gen.generate_source()
+        self.executable_name = gen.build_exe()
+
+    def cmdexec(self, args=''):
+        assert self.executable_name
+        mono = ''.join(SDK.runtime())
+        return py.process.cmdexec('%s "%s" %s' % (mono, self.executable_name, args))
+
+
+class TestTimeshiftCli(CliTimeshiftingTestMixin,
+                       test_timeshift.TestOOType):
+
+    passing_ootype_tests = set([
+        'test_very_simple',
+        'test_convert_const_to_redbox',
+        'test_simple_opt_const_propagation1',
+        'test_simple_opt_const_propagation2',
+        'test_loop_folding',
+#        'test_loop_merging',
+#        'test_two_loops_merging',
+        'test_convert_greenvar_to_redvar',
+#        'test_green_across_split',
+#        'test_merge_const_before_return',
+#        'test_merge_3_redconsts_before_return',
+        'test_merge_const_at_return',
+#        'test_arith_plus_minus',
+        ])
+
+    # for the individual tests see
+    # ====> ../../../timeshifter/test/test_timeshift.py
+
+    pass

Modified: pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py	Tue Mar 18 13:53:27 2008
@@ -13,7 +13,7 @@
     RGenOp = RI386GenOp
 
     SEPLINE = 'running residual graph...\n'
-    
+
     def annotate_interface_functions(self):
         annhelper = self.hrtyper.annhelper
         RGenOp = self.RGenOp
@@ -95,12 +95,18 @@
         annhelper.getgraph(ll_main, [s_list_of_strings],
                            annmodel.SomeInteger())
         annhelper.finish()
+        self.compile(ll_main)
+        
+    def compile(self, ll_main):
         t = self.rtyper.annotator.translator
         t.config.translation.gc = 'boehm'
         cbuilder = CStandaloneBuilder(t, ll_main, config=t.config)
         cbuilder.generate_source()
         cbuilder.compile()
         self.main_cbuilder= cbuilder
+
+    def cmdexec(self, args):
+        return self.main_cbuilder.cmdexec(args)
         
     def timeshift(self, ll_function, values, opt_consts=[], *args, **kwds):
         self.ll_function = ll_function
@@ -119,7 +125,7 @@
 
         mainargs = ' '.join([str(arg) for arg in mainargs])
 
-        output = self.main_cbuilder.cmdexec(mainargs)
+        output = self.cmdexec(mainargs)
         lines = output.splitlines()
         assert lines[0] == self.SEPLINE[:-1]
         if (lines[1].startswith('{') and

Modified: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	(original)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	Tue Mar 18 13:53:27 2008
@@ -1979,9 +1979,12 @@
         RGenOp = self.RGenOp
         gv = RGenOp.genzeroconst(RGenOp.kindToken(lltype.Signed))
         assert gv.revealconst(lltype.Signed) == 0
-        P = self.T.Ptr(lltype.Struct('S'))
+        P = self.T.Ptr(self.T.Struct('S'))
         gv = RGenOp.genzeroconst(RGenOp.kindToken(P))
-        assert gv.revealconst(llmemory.Address) == llmemory.NULL
+        if self.T.__name__ == 'LLType':
+            assert gv.revealconst(llmemory.Address) == llmemory.NULL
+        else:
+            assert gv.revealconst(ootype.ROOT) == ootype.null(ootype.ROOT)
 
     def test_ovfcheck_adder_direct(self):
         rgenop = self.RGenOp()

Modified: pypy/dist/pypy/jit/timeshifter/exception.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/exception.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/exception.py	Tue Mar 18 13:53:27 2008
@@ -33,7 +33,7 @@
             # XXX: think more about exceptions
             self.null_exc_type_box = rvalue.PtrRedBox(self.exc_type_kind,
                                                       RGenOp.constPrebuiltGlobal(llmemory.NULL))
-            self.null_exc_value_box = rvalue.IntRedBox(self.exc_value_kind,
+            self.null_exc_value_box = rvalue.PtrRedBox(self.exc_value_kind,
                                                        RGenOp.constPrebuiltGlobal(llmemory.NULL))
             
         self.lazy_exception_path = lazy_exception_path
@@ -70,6 +70,9 @@
         builder = jitstate.curbuilder
         etypebox = jitstate.exc_type_box
         if etypebox.is_constant():
+            # we should really use LL_EXC_TYPE instead of Address, but at the moment it crashes with ootype
+            #LL_EXC_TYPE = self.etrafo.lltype_of_exception_type
+            #ll_etype = rvalue.ll_getvalue(etypebox, LL_EXC_TYPE)
             ll_etype = rvalue.ll_getvalue(etypebox, llmemory.Address)
             if not ll_etype:
                 return       # we know there is no exception set

Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	Tue Mar 18 13:53:27 2008
@@ -1799,29 +1799,30 @@
 class TestLLType(BaseTestTimeshift):
     type_system = 'lltype'
 
-passing_ootype_tests = set([
-    'test_very_simple',
-    'test_convert_const_to_redbox',
-    'test_simple_opt_const_propagation1',
-    'test_simple_opt_const_propagation2',
-    'test_loop_folding',
-    'test_loop_merging',
-    'test_two_loops_merging',
-    'test_convert_greenvar_to_redvar',
-    'test_green_across_split',
-    'test_merge_const_before_return',
-    'test_merge_3_redconsts_before_return',
-    'test_merge_const_at_return',
-    'test_arith_plus_minus',
-    ])
 class TestOOType(BaseTestTimeshift):
     type_system = 'ootype'
 
+    passing_ootype_tests = set([
+        'test_very_simple',
+        'test_convert_const_to_redbox',
+        'test_simple_opt_const_propagation1',
+        'test_simple_opt_const_propagation2',
+        'test_loop_folding',
+        'test_loop_merging',
+        'test_two_loops_merging',
+        'test_convert_greenvar_to_redvar',
+        'test_green_across_split',
+        'test_merge_const_before_return',
+        'test_merge_3_redconsts_before_return',
+        'test_merge_const_at_return',
+        'test_arith_plus_minus',
+        ])
+
     def Ptr(self, T):
         return T
 
     def __getattribute__(self, name):
-        if name.startswith('test_') and name not in passing_ootype_tests:
+        if name.startswith('test_') and name not in self.passing_ootype_tests:
             def fn():
                 py.test.skip("doesn't work yet")
             return fn

Modified: pypy/dist/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rootype.py	Tue Mar 18 13:53:27 2008
@@ -109,6 +109,7 @@
         vlist = hop.inputargs(*hop.args_r)
         cgraphs = hop.inputconst(ootype.Void, None)
         vlist.append(cgraphs)
+        hop.exception_is_here()
         return hop.genop("indirect_call", vlist, resulttype = hop.r_result.lowleveltype)
 
     def rtype_call_args(self, hop):

Modified: pypy/dist/pypy/translator/cli/constant.py
==============================================================================
--- pypy/dist/pypy/translator/cli/constant.py	(original)
+++ pypy/dist/pypy/translator/cli/constant.py	Tue Mar 18 13:53:27 2008
@@ -96,6 +96,7 @@
             uniq = self.db.unique()
             return CLIFieldInfoConst(self.db, value.llvalue, uniq)
         elif isinstance(value, ootype._view) and isinstance(value._inst, ootype._record):
+            self.db.cts.lltype_to_cts(value._inst._TYPE) # record the type of the record
             return self.record_const(value._inst)
         else:
             return BaseConstantGenerator._create_complex_const(self, value)



More information about the Pypy-commit mailing list