[pypy-svn] r48998 - in pypy/dist/pypy/translator/llvm: . test

xoraxax at codespeak.net xoraxax at codespeak.net
Fri Nov 23 19:19:36 CET 2007


Author: xoraxax
Date: Fri Nov 23 19:19:34 2007
New Revision: 48998

Modified:
   pypy/dist/pypy/translator/llvm/node.py
   pypy/dist/pypy/translator/llvm/test/test_genllvm.py
Log:
(xoraxax, algorithm by fijal): Fixed name mangling of LLVM backend. Before it generated two functions with the same name.



Modified: pypy/dist/pypy/translator/llvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/node.py	(original)
+++ pypy/dist/pypy/translator/llvm/node.py	Fri Nov 23 19:19:34 2007
@@ -1,22 +1,26 @@
 from pypy.rpython.lltypesystem import lltype
 
+
 class Node(object):
     __slots__ = "name".split()
     prefix = '%'
 
     nodename_count = {}
 
+    def mangle(self, name):
+        if name not in self.nodename_count:
+            result = name
+            self.nodename_count[name] = 1
+            return result
+        else:
+            result = '%s_%d' % (name, self.nodename_count[name])
+            self.nodename_count[name] += 1
+            return self.mangle(result)
+
     def make_name(self, name=''):
         " helper for creating names"
         name = self.prefix + name
-        if name in self.nodename_count:
-            postfix = '_%d' % self.nodename_count[name]
-            self.nodename_count[name] += 1
-        else:
-            postfix = ''
-            self.nodename_count[name] = 1
-        name += postfix
-
+        name = self.mangle(name)
         if " " in name or "<" in name: 
             name = '"%s"' % name
 

Modified: pypy/dist/pypy/translator/llvm/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_genllvm.py	Fri Nov 23 19:19:34 2007
@@ -473,6 +473,31 @@
     res = f(4)
     assert res == 4*(4+2)
 
+
+def func_with_dup_name():
+    return 1
+
+foo_func_with_dup_name = func_with_dup_name
+
+def test_dup_func():
+    def func_with_dup_name():
+        return 2
+    def func_with_dup_name_1():
+        return 3
+    def call_func(x):
+        if x > 10:
+            return foo_func_with_dup_name()
+        elif x > 5:
+            return func_with_dup_name_1()
+        elif x > 0:
+            return func_with_dup_name()
+        return 0
+    f = compile_function(call_func, [int])
+    assert f(1) == 2
+    assert f(6) == 3
+    assert f(11) == 1
+
+
 def test__del__():
     from pypy.rpython.lltypesystem.lloperation import llop
     class State:



More information about the Pypy-commit mailing list