Added llvm.core.load_library_permanently() (Issue #12).
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@46 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
ecdc9ebd95
commit
b0a11dbbbc
6 changed files with 77 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
0.4, in progress:
|
0.4, in progress:
|
||||||
|
|
||||||
|
* Added llvm.core.load_library_permanently() (Issue #12).
|
||||||
* Fix comparison using != (Issue #11).
|
* Fix comparison using != (Issue #11).
|
||||||
* Instruction.is_terminator added.
|
* Instruction.is_terminator added.
|
||||||
* Fix Builder.select (Paulo Silva).
|
* Fix Builder.select (Paulo Silva).
|
||||||
|
|
|
||||||
30
llvm/_core.c
30
llvm/_core.c
|
|
@ -917,9 +917,37 @@ _wLLVMGenericValueToFloat(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
_wrap_obj2none(LLVMDisposeGenericValue, LLVMGenericValueRef)
|
_wrap_obj2none(LLVMDisposeGenericValue, LLVMGenericValueRef)
|
||||||
|
|
||||||
|
|
||||||
|
/*===----------------------------------------------------------------------===*/
|
||||||
|
/* Misc */
|
||||||
|
/*===----------------------------------------------------------------------===*/
|
||||||
|
|
||||||
_wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
|
_wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
|
||||||
LLVMValueRef)
|
LLVMValueRef)
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
const char *filename;
|
||||||
|
char *outmsg;
|
||||||
|
PyObject *ret;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "s", &filename))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
outmsg = 0;
|
||||||
|
if (!LLVMLoadLibraryPermanently(filename, &outmsg)) {
|
||||||
|
if (outmsg) {
|
||||||
|
ret = PyString_FromString(outmsg);
|
||||||
|
LLVMDisposeMessage(outmsg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* note: success => None, failure => string with error message */
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*===----------------------------------------------------------------------===*/
|
/*===----------------------------------------------------------------------===*/
|
||||||
/* Python member method table */
|
/* Python member method table */
|
||||||
|
|
@ -1359,7 +1387,9 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMGenericValueToFloat )
|
_method( LLVMGenericValueToFloat )
|
||||||
_method( LLVMDisposeGenericValue )
|
_method( LLVMDisposeGenericValue )
|
||||||
|
|
||||||
|
/* Misc */
|
||||||
_method( LLVMGetIntrinsic )
|
_method( LLVMGetIntrinsic )
|
||||||
|
_method( LLVMLoadLibraryPermanently )
|
||||||
|
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
16
llvm/core.py
16
llvm/core.py
|
|
@ -2224,3 +2224,19 @@ class MemoryBuffer(object):
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
_core.LLVMDisposeMemoryBuffer(self.ptr)
|
_core.LLVMDisposeMemoryBuffer(self.ptr)
|
||||||
|
|
||||||
|
|
||||||
|
#===----------------------------------------------------------------------===
|
||||||
|
# Misc
|
||||||
|
#===----------------------------------------------------------------------===
|
||||||
|
|
||||||
|
def load_library_permanently(filename):
|
||||||
|
"""Load a shared library.
|
||||||
|
|
||||||
|
Load the given shared library (filename argument specifies the full
|
||||||
|
path of the .so file) using LLVM. Symbols from these are available
|
||||||
|
from the execution engine thereafter."""
|
||||||
|
|
||||||
|
ret = _core.LLVMLoadLibraryPermanently(filename)
|
||||||
|
if isinstance(ret, str):
|
||||||
|
raise llvm.LLVMException, ret
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/Analysis/Verifier.h"
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Assembly/Parser.h"
|
#include "llvm/Assembly/Parser.h"
|
||||||
|
#include "llvm/System/DynamicLibrary.h"
|
||||||
// +includes for passes
|
// +includes for passes
|
||||||
#include "llvm/PassManager.h"
|
#include "llvm/PassManager.h"
|
||||||
#include "llvm/Analysis/LoopPass.h"
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
|
|
@ -198,6 +199,20 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len)
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return 0 on failure (with ErrMsg filled in), 1 on success. */
|
||||||
|
unsigned LLVMLoadLibraryPermanently(const char* filename, char **ErrMsg)
|
||||||
|
{
|
||||||
|
std::string msg;
|
||||||
|
|
||||||
|
/* Note: the LLVM API returns true on failure. Don't ask why. */
|
||||||
|
if (sys::DynamicLibrary::LoadLibraryPermanently(filename, &msg)) {
|
||||||
|
*ErrMsg = strdup(msg.c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* passes */
|
/* passes */
|
||||||
|
|
||||||
#define define_pass(P) \
|
#define define_pass(P) \
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,8 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *BC, unsigned Len,
|
||||||
char **OutMessage);
|
char **OutMessage);
|
||||||
unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len);
|
unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len);
|
||||||
|
|
||||||
|
unsigned LLVMLoadLibraryPermanently(const char* filename, char **ErrMsg);
|
||||||
|
|
||||||
/* passes */
|
/* passes */
|
||||||
|
|
||||||
#define declare_pass(P) \
|
#define declare_pass(P) \
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,23 @@ def do_ownable():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def do_misc():
|
||||||
|
print " Testing miscellaneous functions"
|
||||||
|
try:
|
||||||
|
load_library_permanently("/usr/lib/libm.so")
|
||||||
|
except LLVMException:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
load_library_permanently("no*such*so")
|
||||||
|
except LLVMException:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def do_llvm():
|
def do_llvm():
|
||||||
print " Testing module llvm"
|
print " Testing module llvm"
|
||||||
do_llvmexception()
|
do_llvmexception()
|
||||||
do_ownable()
|
do_ownable()
|
||||||
|
do_misc()
|
||||||
|
|
||||||
|
|
||||||
def do_module():
|
def do_module():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue