[pypy-svn] r65026 - in pypy/branch/pyjitpl5/pypy: jit/backend/cli translator/cli/src

antocuni at codespeak.net antocuni at codespeak.net
Mon May 4 17:47:18 CEST 2009


Author: antocuni
Date: Mon May  4 17:47:18 2009
New Revision: 65026

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py
   pypy/branch/pyjitpl5/pypy/jit/backend/cli/runner.py
   pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs
Log:
- implement int_add_ovf

- implement guard_no_exception

- add a general way to add "branches" of the main method

- correctly return the last operation that failed

- this is enough to make the first bit of test_ovf_operations passing.  The
  test as a whole still fails, because the other ops are still unimplemented



Modified: pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/cli/method.py	Mon May  4 17:47:18 2009
@@ -83,18 +83,23 @@
         self.name = name
         self.loop = loop
         self.boxes = {} # box --> local var
+        self.failing_ops = {} # index --> op
+        self.branches = [] # (Label, operations)
         self.meth_wrapper = self._get_meth_wrapper()
         self.il = self.meth_wrapper.get_il_generator()
         self.av_consts = MethodArgument(0, System.Type.GetType("System.Object[]"))
-        self.av_inputargs = MethodArgument(1, dotnet.typeof(InputArgs))
+        t_InputArgs = dotnet.typeof(InputArgs)
+        self.av_inputargs = MethodArgument(1,t_InputArgs )
+        self.exc_value_field = t_InputArgs.GetField('exc_value')
+        # ----
         self.emit_load_inputargs()
-        self.emit_operations()
+        self.emit_operations(loop.operations)
+        self.emit_branches()
         self.emit_end()
         delegatetype = dotnet.typeof(LoopDelegate)
         consts = dotnet.new_array(System.Object, 0)
         self.func = self.meth_wrapper.create_delegate(delegatetype, consts)
 
-
     def _get_meth_wrapper(self):
         restype = dotnet.class2type(cVoid)
         args = self._get_args_array([dotnet.typeof(InputArgs)])
@@ -115,6 +120,22 @@
             self.boxes[box] = v
             return v
 
+    def get_index_for_failing_op(self, op):
+        try:
+            return self.failing_ops[op]
+        except KeyError:
+            i = len(self.failing_ops)
+            self.failing_ops[i] = op
+            return i
+
+    def newbranch(self, op):
+        # sanity check, maybe we can remove it later
+        for _, myop in self.branches:
+            assert myop is not op
+        il_label = self.il.DefineLabel()
+        self.branches.append((il_label, op))
+        return il_label
+
     def get_inputarg_field(self, type):
         t = dotnet.typeof(InputArgs)
         if type == history.INT:
@@ -147,13 +168,22 @@
             box.store(self)
             i+=1
 
-    def emit_operations(self):
-        for op in self.loop.operations:
+    def emit_operations(self, operations):
+        for op in operations:
             func = self.operations[op.opnum]
             assert func is not None
             func(self, op)
 
+    def emit_branches(self):
+        while self.branches:
+            branches = self.branches
+            self.branches = []
+            for il_label, op in branches:
+                self.il.MarkLabel(il_label)
+                self.emit_operations(op.suboperations)
+
     def emit_end(self):
+        assert self.branches == []
         self.il.Emit(OpCodes.Ret)
 
     # -----------------------------
@@ -166,15 +196,45 @@
         op.result.store(self)
 
     def emit_op_fail(self, op):
+        index_op = self.get_index_for_failing_op(op)
+        self.av_inputargs.load(self)
+        self.il.Emit(OpCodes.Ldc_I4, index_op)
+        field = dotnet.typeof(InputArgs).GetField('failed_op')
+        self.il.Emit(OpCodes.Stfld, field)
+
         i = 0
         for box in op.args:
             self.store_inputarg(i, box.type, box.getCliType(), box)
             i+=1
         self.il.Emit(OpCodes.Ret)
 
+    def emit_op_guard_no_exception(self, op):
+        assert op.suboperations
+        il_label = self.newbranch(op)
+        self.av_inputargs.load(self)
+        self.il.Emit(OpCodes.Ldfld, self.exc_value_field)
+        self.il.Emit(OpCodes.Brtrue, il_label)
+
+    def emit_op_int_add_ovf(self, op):
+        exctype = dotnet.typeof(System.OverflowException)
+        v = self.il.DeclareLocal(exctype)
+        lbl = self.il.BeginExceptionBlock()
+        # XXX: clear_exception
+        self.push_all_args(op)
+        self.il.Emit(OpCodes.Add_Ovf)
+        self.store_result(op)
+        self.il.Emit(OpCodes.Leave, lbl)
+        self.il.BeginCatchBlock(exctype)
+        self.il.Emit(OpCodes.Stloc, v)
+        self.av_inputargs.load(self)
+        self.il.Emit(OpCodes.Ldloc, v)
+        self.il.Emit(OpCodes.Stfld, self.exc_value_field)
+        self.il.EndExceptionBlock()
+
     def not_implemented(self, op):
         raise NotImplementedError
 
+    emit_op_guard_exception = not_implemented
     emit_op_guard_value = not_implemented
     emit_op_cast_int_to_ptr = not_implemented
     emit_op_guard_nonvirtualized = not_implemented
@@ -184,7 +244,6 @@
     emit_op_jump = not_implemented
     emit_op_setfield_raw = not_implemented
     emit_op_cast_ptr_to_int = not_implemented
-    emit_op_guard_no_exception = not_implemented
     emit_op_newunicode = not_implemented
     emit_op_new_array = not_implemented
     emit_op_unicodegetitem = not_implemented
@@ -205,7 +264,6 @@
     emit_op_call_pure = not_implemented
     emit_op_strlen = not_implemented
     emit_op_newstr = not_implemented
-    emit_op_guard_exception = not_implemented
     emit_op_call = not_implemented
     emit_op_strsetitem = not_implemented
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/cli/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/cli/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/cli/runner.py	Mon May  4 17:47:18 2009
@@ -33,11 +33,13 @@
     # ----------------------
 
     def compile_operations(self, loop):
-        meth = Method(self, 'loop', loop)
+        meth = Method(self, loop.name, loop)
         loop._cli_meth = meth
 
     def execute_operations(self, loop):
-        loop._cli_meth.func(self.inputargs)
+        meth = loop._cli_meth
+        meth.func(self.inputargs)
+        return meth.failing_ops[self.inputargs.failed_op]
 
     def set_future_value_int(self, index, intvalue):
         self.inputargs.ints[index] = intvalue

Modified: pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs	Mon May  4 17:47:18 2009
@@ -115,6 +115,8 @@
       public int[] ints = new int[32];
       public float[] floats = new float[32];
       public object[] objs = new object[32];
+      public Exception exc_value = null;
+      public int failed_op = -1;
 
       public void ensure_ints(int n)
       {



More information about the Pypy-commit mailing list