diff --git a/llvm/_core.cpp b/llvm/_core.cpp index 6f13c61..435ebf0 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -1279,37 +1279,38 @@ _wLLVMEngineBuilderCreateTM(PyObject *self, PyObject *args) /* Execution Engine */ /*===----------------------------------------------------------------------===*/ -static PyObject * -_wLLVMCreateExecutionEngine(PyObject *self, PyObject *args) -{ - LLVMPY_TRY - PyObject *obj; - int force_interpreter; - char *outmsg = 0; - int error; - - if (!PyArg_ParseTuple(args, "Oi", &obj, &force_interpreter)) - return NULL; - - const LLVMModuleRef mod = pycap_get( obj ) ; - - LLVMExecutionEngineRef ee; - if (force_interpreter) - error = LLVMCreateInterpreterForModule(&ee, mod, &outmsg); - else - error = LLVMCreateJITCompilerForModule(&ee, mod, 1 /*fast*/, &outmsg); - - PyObject *ret; - if (error) { - ret = PyUnicode_FromString(outmsg); - LLVMDisposeMessage(outmsg); - } else { - ret = pycap_new(ee); - } - - return ret; - LLVMPY_CATCH_ALL -} +// Use EngineBuilder +//static PyObject * +//_wLLVMCreateExecutionEngine(PyObject *self, PyObject *args) +//{ +// LLVMPY_TRY +// PyObject *obj; +// int force_interpreter; +// char *outmsg = 0; +// int error; +// +// if (!PyArg_ParseTuple(args, "Oi", &obj, &force_interpreter)) +// return NULL; +// +// const LLVMModuleRef mod = pycap_get( obj ) ; +// +// LLVMExecutionEngineRef ee; +// if (force_interpreter) +// error = LLVMCreateInterpreterForModule(&ee, mod, &outmsg); +// else +// error = LLVMCreateJITCompilerForModule(&ee, mod, 1 /*fast*/, &outmsg); +// +// PyObject *ret; +// if (error) { +// ret = PyUnicode_FromString(outmsg); +// LLVMDisposeMessage(outmsg); +// } else { +// ret = pycap_new(ee); +// } +// +// return ret; +// LLVMPY_CATCH_ALL +//} static PyObject * _wLLVMGetPointerToFunction(PyObject *self, PyObject *args) @@ -1405,6 +1406,8 @@ _wLLVMRemoveModule2(PyObject *self, PyObject *args) } _wrap_obj2none(LLVMDisposeExecutionEngine, LLVMExecutionEngineRef) +_wrap_objint2none(LLVMExecutionEngineDisableLazyCompilation, + LLVMExecutionEngineRef) _wrap_objobjlist2obj(LLVMRunFunction2, LLVMExecutionEngineRef, LLVMValueRef, LLVMGenericValueRef, LLVMGenericValueRef) _wrap_obj2obj(LLVMGetExecutionEngineTargetData, LLVMExecutionEngineRef, @@ -2116,8 +2119,10 @@ static PyMethodDef core_methods[] = { _method( LLVMEngineBuilderCreateTM ) /* Execution Engine */ - _method( LLVMCreateExecutionEngine ) +// Use EngineBuilder instead +// _method( LLVMCreateExecutionEngine ) _method( LLVMDisposeExecutionEngine ) + _method( LLVMExecutionEngineDisableLazyCompilation ) _method( LLVMRunFunction2 ) _method( LLVMGetPointerToFunction ) _method( LLVMGetPointerToGlobal ) diff --git a/llvm/ee.py b/llvm/ee.py index b6ce31d..12c987a 100644 --- a/llvm/ee.py +++ b/llvm/ee.py @@ -205,12 +205,10 @@ class ExecutionEngine(object): @staticmethod def new(module, force_interpreter=False): - core.check_is_module(module) - _util.check_is_unowned(module) - ret = _core.LLVMCreateExecutionEngine(module.ptr, int(force_interpreter)) - if isinstance(ret, str): - raise llvm.LLVMException(ret) - return ExecutionEngine(ret, module) + eb = EngineBuilder.new(module) + if force_interpreter: + eb.force_interpreter() + return eb.create() def __init__(self, ptr, module): self.ptr = ptr @@ -219,6 +217,10 @@ class ExecutionEngine(object): def __del__(self): _core.LLVMDisposeExecutionEngine(self.ptr) + def disable_lazy_compilation(self, disabled=True): + _core.LLVMExecutionEngineDisableLazyCompilation(self.ptr, + int(bool(disabled))) + def run_function(self, fn, args): core.check_is_function(fn) ptrs = _unpack_generic_values(args) diff --git a/llvm/extra.cpp b/llvm/extra.cpp index e200eec..726ebab 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -1254,6 +1254,11 @@ unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg) return 1; } +void LLVMExecutionEngineDisableLazyCompilation(LLVMExecutionEngineRef ee, int flag) +{ + llvm::unwrap(ee)->DisableLazyCompilation(flag); +} + void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn) { llvm::ExecutionEngine *eep = llvm::unwrap(ee); diff --git a/llvm/extra.h b/llvm/extra.h index 6080bdb..829de23 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -590,6 +590,11 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, size_t *len); * use, via LLVMDisposeMessage(). */ unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg); +/* Wraps llvm::ExecutionEngine::DisableLazyCompilation(bool) + */ +void LLVMExecutionEngineDisableLazyCompilation(LLVMExecutionEngineRef ee, + int flag); + /* Wraps llvm::ExecutionEngine::getPointerToFunction(). Returns a pointer * to the JITted function. */ void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn);