[pypy-commit] pypy less-stringly-ops: Add SpaceOperation.replace()

rlamy noreply at buildbot.pypy.org
Wed Sep 25 16:17:42 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r67092:aacb3f409865
Date: 2013-09-25 05:31 +0100
http://bitbucket.org/pypy/pypy/changeset/aacb3f409865/

Log:	Add SpaceOperation.replace()

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -417,6 +417,11 @@
         return "%r = %s(%s)" % (self.result, self.opname,
                                 ", ".join(map(repr, self.args)))
 
+    def replace(self, mapping):
+        newargs = [mapping.get(arg, arg) for arg in self.args]
+        newresult = mapping.get(self.result, self.result)
+        return type(self)(self.opname, newargs, newresult, self.offset)
+
 class Atom(object):
     def __init__(self, name):
         self.__name__ = name # make save_global happy
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -59,6 +59,14 @@
         self.result = Variable()
         self.offset = -1
 
+    def replace(self, mapping):
+        newargs = [mapping.get(arg, arg) for arg in self.args]
+        newresult = mapping.get(self.result, self.result)
+        newop = type(self)(*newargs)
+        newop.result = newresult
+        newop.offset = self.offset
+        return newop
+
     @classmethod
     def make_sc(cls):
         def sc_operator(space, *args_w):
diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py
--- a/rpython/translator/simplify.py
+++ b/rpython/translator/simplify.py
@@ -265,8 +265,7 @@
             def rename(v):
                 return renaming.get(v, v)
             def rename_op(op):
-                args = [rename(a) for a in op.args]
-                op = SpaceOperation(op.opname, args, rename(op.result), op.offset)
+                op = op.replace(renaming)
                 # special case...
                 if op.opname == 'indirect_call':
                     if isinstance(op.args[0], Constant):


More information about the pypy-commit mailing list