rustllvm: Add bindings to the LLVM linker
This commit is contained in:
parent
c47a075a99
commit
729648282b
3 changed files with 22 additions and 3 deletions
|
@ -848,7 +848,9 @@ native mod llvm = llvm_lib {
|
||||||
call. */
|
call. */
|
||||||
fn LLVMRustGetLastError() -> sbuf;
|
fn LLVMRustGetLastError() -> sbuf;
|
||||||
|
|
||||||
|
/** Links LLVM modules together. `Src` is destroyed by this call and
|
||||||
|
must never be referenced again. */
|
||||||
|
fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
native mod rustllvm = llvm_lib {
|
native mod rustllvm = llvm_lib {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/Linker.h"
|
||||||
#include "llvm/PassManager.h"
|
#include "llvm/PassManager.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/FormattedStream.h"
|
||||||
|
@ -25,12 +26,13 @@
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static char *LLVMRustError;
|
static const char *LLVMRustError;
|
||||||
|
|
||||||
extern "C" LLVMMemoryBufferRef
|
extern "C" LLVMMemoryBufferRef
|
||||||
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
||||||
LLVMMemoryBufferRef MemBuf = NULL;
|
LLVMMemoryBufferRef MemBuf = NULL;
|
||||||
LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, &LLVMRustError);
|
LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf,
|
||||||
|
const_cast<char **>(&LLVMRustError));
|
||||||
return MemBuf;
|
return MemBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +51,20 @@ enum LLVMCodeGenFileType {
|
||||||
LLVMNullFile // Do not emit any output.
|
LLVMNullFile // Do not emit any output.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
|
||||||
|
static std::string err;
|
||||||
|
|
||||||
|
// For some strange reason, unwrap() doesn't work here. "No matching
|
||||||
|
// function" error.
|
||||||
|
Module *DM = reinterpret_cast<Module *>(Dest);
|
||||||
|
Module *SM = reinterpret_cast<Module *>(Src);
|
||||||
|
if (Linker::LinkModules(DM, SM, &err)) {
|
||||||
|
LLVMRustError = err.c_str();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
||||||
LLVMModuleRef M,
|
LLVMModuleRef M,
|
||||||
const char *triple,
|
const char *triple,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
LLVMRustCreateMemoryBufferWithContentsOfFile
|
LLVMRustCreateMemoryBufferWithContentsOfFile
|
||||||
LLVMRustWriteOutputFile
|
LLVMRustWriteOutputFile
|
||||||
LLVMRustGetLastError
|
LLVMRustGetLastError
|
||||||
|
LLVMLinkModules
|
||||||
LLVMCreateObjectFile
|
LLVMCreateObjectFile
|
||||||
LLVMDisposeObjectFile
|
LLVMDisposeObjectFile
|
||||||
LLVMGetSections
|
LLVMGetSections
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue