1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #include "llvm/Linker/Linker.h"
21 RustLinker(Module &M) :
27 extern "C" RustLinker*
28 LLVMRustLinkerNew(LLVMModuleRef DstRef) {
29 Module *Dst = unwrap(DstRef);
31 auto Ret = llvm::make_unique<RustLinker>(*Dst);
36 LLVMRustLinkerFree(RustLinker *L) {
41 LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
42 std::unique_ptr<MemoryBuffer> Buf =
43 MemoryBuffer::getMemBufferCopy(StringRef(BC, Len));
45 Expected<std::unique_ptr<Module>> SrcOrError =
46 llvm::getLazyBitcodeModule(Buf->getMemBufferRef(), L->Ctx);
48 LLVMRustSetLastError(toString(SrcOrError.takeError()).c_str());
52 auto Src = std::move(*SrcOrError);
54 if (L->L.linkInModule(std::move(Src))) {
55 LLVMRustSetLastError("");