[pypy-svn] r48164 - in pypy/dist/pypy/translator/llvm: . module

rxe at codespeak.net rxe at codespeak.net
Mon Oct 29 17:04:56 CET 2007


Author: rxe
Date: Mon Oct 29 17:04:54 2007
New Revision: 48164

Modified:
   pypy/dist/pypy/translator/llvm/buildllvm.py
   pypy/dist/pypy/translator/llvm/exception.py
   pypy/dist/pypy/translator/llvm/module/excsupport.py
   pypy/dist/pypy/translator/llvm/module/support.py
Log:
attempt to handle void/bool return types

Modified: pypy/dist/pypy/translator/llvm/buildllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/buildllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/buildllvm.py	Mon Oct 29 17:04:54 2007
@@ -44,7 +44,10 @@
     result = %(name)s(*args)
     if %(name)s_raised():
         raise LLVMException("Exception raised")
-    return result
+    if %(rt_isbool)s:
+        return bool(result)
+    else:
+        return result
 """
 
     import ctypes
@@ -59,15 +62,19 @@
                  lltype.Signed: "ctypes.c_int",
                  lltype.Unsigned: "ctypes.c_uint",
                  lltype.SignedLongLong: "ctypes.c_longlong",
-                 lltype.UnsignedLongLong: "ctypes.c_ulonglong"
+                 lltype.UnsignedLongLong: "ctypes.c_ulonglong",
+                 lltype.Void: None # XXX why no ctypes.c_void ?
                  }
 
     name = genllvm.entrynode.ref.strip("%")
     
     g = genllvm.entrynode.graph  
-    returntype = TO_CTYPES[g.returnblock.inputargs[0].concretetype]
+    rt = g.returnblock.inputargs[0].concretetype
+    returntype = TO_CTYPES[rt]
     inputargtypes = [TO_CTYPES[a.concretetype] for a in g.startblock.inputargs]
     args = '[%s]' % ", ".join(inputargtypes)
+
+    rt_isbool = rt is lltype.Bool
     modfilename.write(template % locals())
     return modfilename.purebasename
 

Modified: pypy/dist/pypy/translator/llvm/exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/exception.py	(original)
+++ pypy/dist/pypy/translator/llvm/exception.py	Mon Oct 29 17:04:54 2007
@@ -1,3 +1,5 @@
+# XXX this is just so we can compile modules - need to put somewhere else
+
 
 def _noresult(returntype):
     r = returntype.strip()
@@ -13,8 +15,15 @@
 
 def llvm_implcode(entrynode):
     from pypy.translator.llvm.codewriter import DEFAULT_CCONV as cconv
-    from pypy.translator.llvm.module.excsupport import exctransform_code
+    from pypy.translator.llvm.module.excsupport import entrycode, voidentrycode, raisedcode 
     returntype, entrypointname = entrynode.getdecl().split('%', 1)
     noresult = _noresult(returntype)
-    return exctransform_code % locals()
+
+    code = raisedcode % locals()
+    if returntype == "void":
+        code += voidentrycode % locals()
+    else:
+        code += entrycode % locals()
+
+    return code
 

Modified: pypy/dist/pypy/translator/llvm/module/excsupport.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/module/excsupport.py	(original)
+++ pypy/dist/pypy/translator/llvm/module/excsupport.py	Mon Oct 29 17:04:54 2007
@@ -1,5 +1,5 @@
 
-exctransform_code = '''
+entrycode = '''
 ccc %(returntype)s%%__entrypoint__%(entrypointname)s {
     store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
     %%result = call %(cconv)s %(returntype)s%%%(entrypointname)s
@@ -13,7 +13,25 @@
 exception:
     ret %(noresult)s
 }
+'''
 
+voidentrycode = '''
+ccc %(returntype)s%%__entrypoint__%(entrypointname)s {
+    store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
+    %%result = call %(cconv)s %(returntype)s%%%(entrypointname)s
+    %%tmp    = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
+    %%exc    = seteq %%RPYTHON_EXCEPTION_VTABLE* %%tmp, null
+    br bool %%exc, label %%no_exception, label %%exception
+
+no_exception:
+    ret %(returntype)s %%result
+
+exception:
+    ret %(noresult)s
+}
+'''
+
+raisedcode = '''
 ;XXX this should use the transformation data that has the same purpose
 ccc int %%__entrypoint__raised_LLVMException() {
     %%tmp    = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
@@ -21,7 +39,4 @@
     ret int %%result
 }
 
-internal fastcc void %%unwind() {
-    ret void
-}
 '''

Modified: pypy/dist/pypy/translator/llvm/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/module/support.py	(original)
+++ pypy/dist/pypy/translator/llvm/module/support.py	Mon Oct 29 17:04:54 2007
@@ -117,7 +117,6 @@
     %%exception_type  = load %%RPYTHON_EXCEPTION_VTABLE** %%tmp
     store %%RPYTHON_EXCEPTION_VTABLE* %%exception_type, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
     store %%RPYTHON_EXCEPTION* %%exception_value, %%RPYTHON_EXCEPTION** %%last_exception_value
-    call fastcc void %%unwind()
     ret void
 }
 """ % (c_name, exc_repr)



More information about the Pypy-commit mailing list