Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: less-stringly-ops
Changeset: r67647:e7fe7dd9a842
Date: 2013-10-19 20:20 +0100
http://bitbucket.org/pypy/pypy/changeset/e7fe7dd9a842/

Log:    create OverflowingOp

diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -53,6 +53,7 @@
 class HLOperation(SpaceOperation):
     __metaclass__ = HLOperationMeta
     pure = False
+    can_overflow = False
 
     def __init__(self, *args):
         self.args = list(args)
@@ -116,12 +117,25 @@
                         # store operation with variable result instead
                         pass
 
+class OverflowingOperation(PureOperation):
+    can_overflow = True
+    def ovfchecked(self):
+        ovf = self.ovf_variant(*self.args)
+        ovf.offset = self.offset
+        return ovf
+
 
 def add_operator(name, arity, pyfunc=None, pure=False, ovf=False):
     operator_func = getattr(operator, name, None)
-    base_cls = PureOperation if pure else HLOperation
+    if ovf:
+        assert pure
+        base_cls = OverflowingOperation
+    elif pure:
+        base_cls = PureOperation
+    else:
+        base_cls = HLOperation
     cls = HLOperationMeta(name, (base_cls,), {'opname': name, 'arity': arity,
-                                   'can_overflow': ovf, 'canraise': []})
+                                              'canraise': []})
     if pyfunc is not None:
         func2op[pyfunc] = cls
     if operator_func:
@@ -134,6 +148,7 @@
         from rpython.rlib.rarithmetic import ovfcheck
         ovf_func = lambda *args: ovfcheck(cls.pyfunc(*args))
         add_operator(name + '_ovf', arity, pyfunc=ovf_func)
+        cls.ovf_variant = getattr(op, name + '_ovf')
 
 # ____________________________________________________________
 
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -6,9 +6,9 @@
 """
 import py
 
-from rpython.flowspace import operation
 from rpython.flowspace.model import (SpaceOperation, Variable, Constant,
                                      c_last_exception, checkgraph, mkentrymap)
+from rpython.flowspace.operation import OverflowingOperation
 from rpython.rlib import rarithmetic
 from rpython.translator import unsimplify
 from rpython.translator.backendopt import ssa
@@ -92,13 +92,6 @@
     """
     covf = Constant(rarithmetic.ovfcheck)
 
-    def check_syntax(opname):
-        oper = getattr(operation.op, opname + "_ovf")
-        exlis = oper.canraise
-        if OverflowError not in exlis:
-            raise Exception("ovfcheck in %s: Operation %s has no"
-                            " overflow variant" % (graph.name, opname))
-
     for block in graph.iterblocks():
         for i in range(len(block.operations)-1, -1, -1):
             op = block.operations[i]
@@ -120,11 +113,14 @@
                     join_blocks(graph)         # merge the two blocks together
                     transform_ovfcheck(graph)  # ...and try again
                     return
-                op1 = block.operations[i-1]
-                check_syntax(op1.opname)
-                op1.opname += '_ovf'
+                op1 = block.operations[i - 1]
+                if not isinstance(op1, OverflowingOperation):
+                    raise Exception("ovfcheck in %s: Operation %s has no "
+                                    "overflow variant" % (graph.name, 
op1.opname))
+                op1_ovf = op1.ovfchecked()
+                block.operations[i - 1] = op1_ovf
                 del block.operations[i]
-                block.renamevariables({op.result: op1.result})
+                block.renamevariables({op.result: op1_ovf.result})
 
 def simplify_exceptions(graph):
     """The exception handling caused by non-implicit exceptions
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to