diff options
| author | Patrick Walton <[email protected]> | 2011-05-04 21:27:00 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-05-04 21:27:00 -0700 |
| commit | 729648282bf31a89cfdb9cbea47806ba4c05a1db (patch) | |
| tree | 5ab73c3cf2955a7b00789c748f7ec669c2e09d0d | |
| parent | rustllvm: Whitespace police in RustWrapper.cpp (diff) | |
| download | rust-729648282bf31a89cfdb9cbea47806ba4c05a1db.tar.xz rust-729648282bf31a89cfdb9cbea47806ba4c05a1db.zip | |
rustllvm: Add bindings to the LLVM linker
| -rw-r--r-- | src/comp/lib/llvm.rs | 4 | ||||
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 20 | ||||
| -rw-r--r-- | src/rustllvm/rustllvm.def.in | 1 |
3 files changed, 22 insertions, 3 deletions
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs index 070174ba..5e758bc6 100644 --- a/src/comp/lib/llvm.rs +++ b/src/comp/lib/llvm.rs @@ -848,7 +848,9 @@ native mod llvm = llvm_lib { call. */ 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 { diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 7f5822d1..01ea6677 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Linker.h" #include "llvm/PassManager.h" #include "llvm/ADT/Triple.h" #include "llvm/Support/FormattedStream.h" @@ -25,12 +26,13 @@ using namespace llvm; -static char *LLVMRustError; +static const char *LLVMRustError; extern "C" LLVMMemoryBufferRef LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) { LLVMMemoryBufferRef MemBuf = NULL; - LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, &LLVMRustError); + LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, + const_cast<char **>(&LLVMRustError)); return MemBuf; } @@ -49,6 +51,20 @@ enum LLVMCodeGenFileType { 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, LLVMModuleRef M, const char *triple, diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in index 0bd524c2..74acb28b 100644 --- a/src/rustllvm/rustllvm.def.in +++ b/src/rustllvm/rustllvm.def.in @@ -1,6 +1,7 @@ LLVMRustCreateMemoryBufferWithContentsOfFile LLVMRustWriteOutputFile LLVMRustGetLastError +LLVMLinkModules LLVMCreateObjectFile LLVMDisposeObjectFile LLVMGetSections |