[pypy-svn] r64998 - in pypy/branch/pyjitpl5/pypy/jit/backend/llvm: . test

arigo at codespeak.net arigo at codespeak.net
Sun May 3 12:07:32 CEST 2009


Author: arigo
Date: Sun May  3 12:07:31 2009
New Revision: 64998

Added:
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/   (props changed)
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/__init__.py   (contents, props changed)
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo1.c   (contents, props changed)
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py   (contents, props changed)
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/test/   (props changed)
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/test/__init__.py   (contents, props changed)
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/test/test_llvm_rffi.py   (contents, props changed)
Log:
Start the llvm backend.  As usual, using the many llvm libs and .o files
dynamically is a complete mess.  The current solution seems to work,
even though I'm not completely sure how :-/


Added: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/__init__.py
==============================================================================

Added: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo1.c
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo1.c	Sun May  3 12:07:31 2009
@@ -0,0 +1,12 @@
+/* LLVM includes */
+#include "llvm-c/Analysis.h"
+#include "llvm-c/Transforms/Scalar.h"
+#include "llvm-c/ExecutionEngine.h"
+
+/* The following list of functions seems to be necessary to force the
+ * functions to be included in pypy_cache_llvm.so.  The list is never
+ * used.
+ */
+void* llvm_c_functions[] = {
+  (void*) LLVMModuleCreateWithName
+};

Added: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py	Sun May  3 12:07:31 2009
@@ -0,0 +1,57 @@
+import py, os, sys
+import pypy
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.translator.tool.cbuild import ExternalCompilationInfo, log
+
+if sys.platform != 'linux2':
+    py.test.skip("Linux only for now")
+
+# ____________________________________________________________
+
+llvm_config = 'llvm-config'
+cachename = os.path.join(os.path.dirname(pypy.__file__), '_cache')
+dirname = os.path.join(cachename, 'libs')
+libname = os.path.join(dirname, 'pypy_cache_llvm.so')
+cname = os.path.join(os.path.dirname(__file__), 'demo1.c')
+
+if not os.path.isfile(libname) or (os.path.getmtime(cname) >
+                                   os.path.getmtime(libname)):
+    if not os.path.isdir(dirname):
+        if not os.path.isdir(cachename):
+            os.mkdir(cachename)
+        os.mkdir(dirname)
+
+    def do(cmdline):
+        log(cmdline)
+        err = os.system(cmdline)
+        if err:
+            raise Exception("gcc command failed")
+
+    oname = os.path.join(dirname, 'demo1.o')
+    do("gcc -c '%s' -o '%s'" % (cname, oname))
+    do("g++ -shared '%s' -o '%s'" % (oname, libname) +
+       " `%s --libs jit`" % llvm_config +
+       " `%s --cflags`" % llvm_config +
+       " `%s --ldflags`" % llvm_config +
+       "")
+
+compilation_info = ExternalCompilationInfo(
+    library_dirs = [dirname],
+    libraries    = ['pypy_cache_llvm'],
+)
+
+# ____________________________________________________________
+
+def llexternal(name, args, result, **kwds):
+    return rffi.llexternal(name, args, result,
+                           compilation_info=compilation_info,
+                           **kwds)
+
+def opaqueptr(name):
+    return rffi.VOIDP  # lltype.Ptr(rffi.COpaque(name))
+
+LLVMModuleRef = opaqueptr('struct LLVMModuleOpaque')
+
+LLVMModuleCreateWithName = llexternal('LLVMModuleCreateWithName',
+                                      [rffi.CCHARP],
+                                      LLVMModuleRef)

Added: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/test/__init__.py
==============================================================================

Added: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/test/test_llvm_rffi.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/test/test_llvm_rffi.py	Sun May  3 12:07:31 2009
@@ -0,0 +1,5 @@
+
+from pypy.jit.backend.llvm.llvm_rffi import *
+
+def test_basic():
+    LLVMModuleCreateWithName("hello")



More information about the Pypy-commit mailing list