Fix LLVMLinkModules for LLVM-3.1

This commit is contained in:
Siu Kwan Lam 2013-01-17 18:59:20 -06:00
commit 206d512c10
3 changed files with 14 additions and 21 deletions

View file

@ -278,8 +278,8 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
const LLVMModuleRef dest = pycap_get<LLVMModuleRef>(dest_obj ) ; const LLVMModuleRef dest = pycap_get<LLVMModuleRef>(dest_obj ) ;
const LLVMModuleRef src = pycap_get<LLVMModuleRef>(src_obj) ; const LLVMModuleRef src = pycap_get<LLVMModuleRef>(src_obj) ;
PyObject *ret; PyObject *ret = NULL;
char *errmsg; char *errmsg = NULL;
if (LLVMLinkModules(dest, src, (LLVMLinkerMode)mode, &errmsg)) { if (LLVMLinkModules(dest, src, (LLVMLinkerMode)mode, &errmsg)) {
if (errmsg) { if (errmsg) {
ret = PyUnicode_FromString(errmsg); ret = PyUnicode_FromString(errmsg);

View file

@ -1191,21 +1191,15 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bitcode, unsigned bclen,
} }
#if LLVM_VERSION_MAJOR <= 3 && LLVM_VERSION_MINOR < 2 #if LLVM_VERSION_MAJOR <= 3 && LLVM_VERSION_MINOR < 2
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, unsigned int mode, // Shamelessly copy from LLVM-3.2
char **out) unsigned LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,
{ int Mode, char **OutMessages) {
llvm::Module *sourcep = llvm::unwrap(src); std::string Messages;
assert(sourcep); unsigned Result = Linker::LinkModules(unwrap(Dest), unwrap(Src), Mode,
llvm::Module *destinationp = llvm::unwrap(dest); OutMessages? &Messages : 0);
assert(destinationp); if (OutMessages)
*OutMessages = strdup(Messages.c_str());
std::string msg; return Result;
if (llvm::Linker::LinkModules(destinationp, sourcep, mode, &msg)) {
*out = strdup(msg.c_str());
return 0;
}
return 1;
} }
#endif #endif

View file

@ -46,10 +46,9 @@
#endif #endif
#include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm-c/Transforms/PassManagerBuilder.h"
#include "llvm_c_extra.h" #include "llvm_c_extra.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -578,8 +577,8 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bc, unsigned bclen,
/* Wraps llvm::Linker::LinkModules(). Returns 0 on failure (with errmsg /* Wraps llvm::Linker::LinkModules(). Returns 0 on failure (with errmsg
* filled in) and 1 on success. Dispose error message after use with * filled in) and 1 on success. Dispose error message after use with
* LLVMDisposeMessage(). */ * LLVMDisposeMessage(). */
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, int mode,
unsigned int, char **errmsg); char **errmsg);
#endif #endif
/* Returns pointer to a heap-allocated block of `*len' bytes containing bit code /* Returns pointer to a heap-allocated block of `*len' bytes containing bit code
* for the given module. NULL on error. */ * for the given module. NULL on error. */