Commits

Ronan Lamy  committed aacb3f4

Add SpaceOperation.replace()

  • Participants
  • Parent commits b927a28
  • Branches less-stringly-ops

Comments (0)

Files changed (3)

File rpython/flowspace/model.py

         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

File rpython/flowspace/operation.py

         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):

File rpython/translator/simplify.py

             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):