Commits

Maciej Fijalkowski committed aea0991

failargs support

  • Participants
  • Parent commits 93c02fe
  • Branches result-in-resops

Comments (0)

Files changed (5)

File pypy/jit/metainterp/optmodel.py

 """ Mutable subclasses for each of ResOperation.
 """
 
+from pypy.tool.sourcetools import func_with_new_name
 from pypy.jit.metainterp.resoperation import opclasses, opclasses_mutable
 
 def create_mutable_subclasses():
+    def addattr(cls, attr, default_value=None):
+        def getter(self):
+            return getattr(self, '_' + attr)
+        def setter(self, value):
+            setattr(self, '_' + attr, value)
+        setattr(cls, '_' + attr, default_value)
+        setattr(cls, 'get_' + attr, func_with_new_name(getter, 'get_' + attr))
+        setattr(cls, 'set_' + attr, func_with_new_name(setter, 'set_' + attr))
+
     for i, cls in enumerate(opclasses):
         if cls is None:
             Mutable = None
         else:
             class Mutable(cls):
                 is_mutable = True
+            if cls.is_guard():
+                addattr(Mutable, 'failargs')
             Mutable.__name__ = cls.__name__ + '_mutable'
         assert len(opclasses_mutable) == i
         opclasses_mutable.append(Mutable)
+    assert len(opclasses) == len(opclasses_mutable)
 
 create_mutable_subclasses()

File pypy/jit/metainterp/resoperation.py

 VOID  = 'v'
 HOLE = '_'
 
-def create_resop_dispatch(opnum, result, args, descr=None):
+def create_resop_dispatch(opnum, result, args, descr=None, mutable=False):
     """ NOT_RPYTHON this is for tests only!
     """
     cls = opclasses[opnum]
     if cls.NUMARGS == 0:
-        return create_resop_0(opnum, result, descr)
+        return create_resop_0(opnum, result, descr, mutable=mutable)
     elif cls.NUMARGS == 1:
-        return create_resop_1(opnum, result, args[0], descr)
+        return create_resop_1(opnum, result, args[0], descr, mutable=mutable)
     elif cls.NUMARGS == 2:
-        return create_resop_2(opnum, result, args[0], args[1], descr)
+        return create_resop_2(opnum, result, args[0], args[1], descr,
+                              mutable=mutable)
     elif cls.NUMARGS == 3:
-        return create_resop_3(opnum, result, args[0], args[1], args[2], descr)
+        return create_resop_3(opnum, result, args[0], args[1], args[2], descr,
+                              mutable=mutable)
     else:
-        return create_resop(opnum, result, args, descr)
+        return create_resop(opnum, result, args, descr, mutable=mutable)
 
 @specialize.memo()
 def _getcls(opnum, mutable):

File pypy/jit/metainterp/test/test_optmodel.py

     assert op2.getarglist() == ['a', 'b', 'c']
     op2 = op.mutable_copy(rop.rop.CALL_i, [FakeBox('a')])
     assert op2.getarglist() == ['a']
+
+def test_failargs():
+    op = rop.create_resop_0(rop.rop.GUARD_NO_OVERFLOW, None)
+    assert not hasattr(op, 'set_failargs')
+    op2 = op.mutable_copy()
+    op2.set_failargs([1, 2, 3])
+    assert op2.get_failargs() == [1, 2, 3]

File pypy/jit/tool/oparser.py

 from pypy.jit.metainterp.resoperation import rop, opclasses, rop_lowercase,\
      ResOpWithDescr, N_aryOp, UnaryOp, PlainResOp, create_resop_dispatch,\
      ResOpNone, create_resop_0, example_for_opnum
+from pypy.jit.metainterp import optmodel
 from pypy.rpython.lltypesystem import lltype, llmemory
 
 class ParseError(Exception):
         if opnum == FORCE_SPILL.OPNUM:
             return FORCE_SPILL(opnum, args, result, descr)
         else:
-            r = create_resop_dispatch(opnum, result, args)
+            r = create_resop_dispatch(opnum, result, args,
+                                      mutable=self.guards_with_failargs)
             if descr is not None:
                 r.setdescr(descr)
             return r
         opres = self.create_op(opnum, result, args, descr)
         self.vars[res] = opres
         if fail_args is not None:
-            explode
+            opres.set_failargs(fail_args)
         return opres
 
     def parse_op_no_result(self, line):
         opnum, args, descr, fail_args = self.parse_op(line)
         res = self.create_op(opnum, None, args, descr)
         if fail_args is not None:
-            explode
+            res.set_failargs(fail_args)
         return res
 
     def parse_next_op(self, line, num):

File pypy/jit/tool/test/test_oparser.py

     """
 
     def test_attach_comment_to_loop(self):
-        py.test.skip("failargs")
         loop = self.parse(self.example_loop_log, guards_with_failargs=True)
         assert loop.comment == '    # bridge out of Guard12, 6 ops'
+        assert loop.operations[-3].get_failargs()
 
     def test_parse_new_with_comma(self):
         # this is generated by PYPYJITLOG, check that we can handle it