[pypy-svn] r16026 - in pypy/dist/pypy/translator/llvm2: . test

rxe at codespeak.net rxe at codespeak.net
Fri Aug 12 23:24:48 CEST 2005


Author: rxe
Date: Fri Aug 12 23:24:46 2005
New Revision: 16026

Modified:
   pypy/dist/pypy/translator/llvm2/database.py
   pypy/dist/pypy/translator/llvm2/opwriter.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
llvm has a different syntax for calls when returning a function pointer it
would seem.  Quick fix.

Thanks to ericvrp for investigating this long standing mystery and thanks to
Chris Lattner for his advice.

ericvrp: Do we need to do something similar for invoke?
 


Modified: pypy/dist/pypy/translator/llvm2/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/database.py	(original)
+++ pypy/dist/pypy/translator/llvm2/database.py	Fri Aug 12 23:24:46 2005
@@ -307,6 +307,14 @@
             else: 
                 raise TypeError("cannot represent %r" %(arg,))
 
+    def is_function_ptr(self, arg):
+        if isinstance(arg, (Constant, Variable)): 
+            arg = arg.concretetype 
+            if isinstance(arg, lltype.Ptr):
+                if isinstance(arg.TO, lltype.FuncType):
+                    return True
+        return False
+    
     def repr_argwithtype(self, arg):
         return self.repr_arg(arg), self.repr_arg_type(arg)
             

Modified: pypy/dist/pypy/translator/llvm2/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/opwriter.py	Fri Aug 12 23:24:46 2005
@@ -258,6 +258,8 @@
         argrefs = self.db.repr_arg_multi(op_args[1:])
         argtypes = self.db.repr_arg_type_multi(op_args[1:])
         if returntype != "void":
+            if self.db.is_function_ptr(op.result):
+                returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
             self.codewriter.call(targetvar, returntype, functionref, argrefs,
                                  argtypes)
         else:

Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	Fri Aug 12 23:24:46 2005
@@ -16,7 +16,6 @@
     assert f() == 1
 
 def test_simple_function_pointer(): 
-    py.test.skip("weird casting bug")
     def f1(x): 
         return x + 1
     def f2(x): 
@@ -27,7 +26,7 @@
     def pointersimple(i): 
         return l[i](i)
 
-    f = compile_function(pointersimple, [int], True)
+    f = compile_function(pointersimple, [int])
     assert f(0) == pointersimple(0)
     assert f(1) == pointersimple(1)
 



More information about the Pypy-commit mailing list