[pypy-svn] r25076 - pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Mar 28 13:12:37 CEST 2006


Author: ericvrp
Date: Tue Mar 28 13:12:35 2006
New Revision: 25076

Added:
   pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/cc.py
   pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/create_pyllvm.sh   (contents, props changed)
   pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/pyllvm.py
Modified:
   pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.cpp
   pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.h
Log:
Example (create_pyllvm.sh) that creates the ctypes wrapper code
to interface with a C shared library (llvmcapi.so).

The wrapper is generated using ctypes codegenerator (that depends
on gccxml). 

llvmcapi.so is generated by setup.py (CPython distutils)

note: pyllvm.py is added for ease of use. It can be reconstructed,
      but at least this way not everyone has to install gccxml.



Added: pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/cc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/cc.py	Tue Mar 28 13:12:35 2006
@@ -0,0 +1,16 @@
+'''
+Added this because ctypes on my computer was missing cdecl.
+'''
+from ctypes import *
+
+class cdecl(object):
+    def __init__(self, restype, libname, argtypes):
+        self.library  = cdll.load(libname + ".so")
+        self.restype  = restype
+        self.argtypes = argtypes
+
+    def __call__(self, func):
+        func._api_          = getattr(self.library, func.__name__)
+        func._api_.restype  = self.restype
+        func._api_.argtypes = self.argtypes
+        return func

Added: pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/create_pyllvm.sh
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/create_pyllvm.sh	Tue Mar 28 13:12:35 2006
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+python setup.py build_ext -i -q
+
+if [ -f ~/projects/ctypes/ctypes/wrap/h2xml.py ] 
+then 
+    python ~/projects/ctypes/ctypes/wrap/h2xml.py llvmcapi.h -q -I . -o llvmcapi.xml
+    python ~/projects/ctypes/ctypes/wrap/xml2py.py llvmcapi.xml -l llvmcapi.so -o pyllvm.tmp
+    sed -e s/from\ ctypes\ import/from\ cc\ import/ pyllvm.tmp > pyllvm.py
+    rm -f pyllvm.tmp llvmcapi.xml
+fi

Modified: pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.cpp
==============================================================================
--- pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.cpp	(original)
+++ pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.cpp	Tue Mar 28 13:12:35 2006
@@ -20,6 +20,10 @@
 #include <iostream>
 
 
-int testme(int n) {
+int testme1(int n) {
     return n * n;
 }
+
+float testme2(float f) {
+    return f * f;
+}

Modified: pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.h
==============================================================================
--- pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.h	(original)
+++ pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/llvmcapi.h	Tue Mar 28 13:12:35 2006
@@ -6,7 +6,8 @@
 extern "C" {
 #endif
 
-	int testme(int n);
+int     testme1(int n);
+float   testme2(float f);
 
 #ifdef __cplusplus
 };

Added: pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/pyllvm.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/pyllvm/llvmcapi/pyllvm.py	Tue Mar 28 13:12:35 2006
@@ -0,0 +1,17 @@
+# generated by 'xml2py'
+# flags 'llvmcapi.xml -l llvmcapi.so -o pyllvm.tmp'
+from cc import *
+
+
+
+def testme1(n):
+    # llvmcapi.h 9
+    return testme1._api_(n)
+testme1 = cdecl(c_int, 'llvmcapi', [c_int]) (testme1)
+
+
+def testme2(f):
+    # llvmcapi.h 10
+    return testme2._api_(f)
+testme2 = cdecl(c_float, 'llvmcapi', [c_float]) (testme2)
+



More information about the Pypy-commit mailing list