[pypy-svn] rev 1583 - in pypy/trunk/src/pypy/translator: . test

tomek at codespeak.net tomek at codespeak.net
Sat Oct 4 18:27:47 CEST 2003


Author: tomek
Date: Sat Oct  4 18:27:47 2003
New Revision: 1583

Modified:
   pypy/trunk/src/pypy/translator/simplify.py
   pypy/trunk/src/pypy/translator/test/test_pyrextrans.py
Log:
simplify.py has now two new functions: simplify_graph, which applies all existing transformations, 
and body of eliminate_fun_params_renaming, which will eliminate the renaming of function parameters.



Modified: pypy/trunk/src/pypy/translator/simplify.py
==============================================================================
--- pypy/trunk/src/pypy/translator/simplify.py	(original)
+++ pypy/trunk/src/pypy/translator/simplify.py	Sat Oct  4 18:27:47 2003
@@ -9,6 +9,10 @@
 from pypy.translator.genpyrex import GenPyrex
 
 
+def eliminate_fun_params_renaming(graph):
+    """We allways rename the params - at the first branch, which isn't really necessary"""
+    return graph
+
 def eliminate_empty_blocks(graph):
     """simplify_vars()
     Things we know we can remove:
@@ -45,6 +49,8 @@
                         i = node.input_args.index(var)
                         nextbranch.returnvalue = prevbranch.args[i]
                     prevprevnode[0].replace_branch(prevbranch, nextbranch)
+                elif isinstance(nextbranch, ConditionalBranch):
+                    continue
                 else:
                     # renaming ... (figure it out yourself :-)
                     if len(prevbranch.args) > len(nextbranch.args):
@@ -58,3 +64,11 @@
                 break
     return graph
 
+
+
+def simplify_graph(graph):
+    """apply all the existing optimisations to the graph"""
+    graph = eliminate_empty_blocks(graph)
+    graph = eliminate_fun_params_renaming(graph)
+    return graph
+

Modified: pypy/trunk/src/pypy/translator/test/test_pyrextrans.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/test_pyrextrans.py	(original)
+++ pypy/trunk/src/pypy/translator/test/test_pyrextrans.py	Sat Oct  4 18:27:47 2003
@@ -25,8 +25,8 @@
             pass
         name = func.func_name
         funcgraph = self.space.build_flow(func)
-        from pypy.translator.simplify import eliminate_empty_blocks
-        #eliminate_empty_blocks(funcgraph)
+        from pypy.translator.simplify import simplify_graph
+        simplify_graph(funcgraph)
         funcgraph.source = inspect.getsource(func)
         result = GenPyrex(funcgraph).emitcode()
         make_dot(funcgraph, udir, 'ps')
@@ -84,6 +84,31 @@
         poor_man_range = self.make_cfunc(self.poor_man_range)
         self.assertEquals(poor_man_range(10), range(10))
 
+   #____________________________________________________
+
+    def simple_id(x):
+        return x
+
+    def test_simple_id(self):
+        #we just want to see, if renaming of parameter works correctly
+        #if the first branch is the end branch
+        simple_id = self.make_cfunc(self.simple_id)
+        self.assertEquals(simple_id(9), 9)
+
+   #____________________________________________________
+
+    def branch_id(cond, a, b):
+        while 1:
+            if cond:
+                return a
+            else:
+                return b
+
+    def test_branch_id(self):
+        branch_id = self.make_cfunc(self.branch_id)
+        self.assertEquals(branch_id(1, 2, 3), 2)
+        self.assertEquals(branch_id(0, 2, 3), 3)
+
     #____________________________________________________
 
     def attrs():


More information about the Pypy-commit mailing list