Skip to content

Commit d5f6125

Browse files
committed
[LLVM 4.0] New bitcode headers and API
1 parent b462e8f commit d5f6125

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Diff for: src/rustllvm/RustWrapper.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -892,19 +892,34 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef Value, RustStringRef str
892892
extern "C" bool
893893
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
894894
Module *Dst = unwrap(dst);
895+
895896
std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
897+
898+
#if LLVM_VERSION_GE(4, 0)
899+
Expected<std::unique_ptr<Module>> SrcOrError =
900+
llvm::getLazyBitcodeModule(buf->getMemBufferRef(), Dst->getContext());
901+
if (!SrcOrError) {
902+
LLVMRustSetLastError(toString(SrcOrError.takeError()).c_str());
903+
return false;
904+
}
905+
906+
auto Src = std::move(*SrcOrError);
907+
#else
896908
ErrorOr<std::unique_ptr<Module>> Src =
897909
llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
898910
if (!Src) {
899911
LLVMRustSetLastError(Src.getError().message().c_str());
900912
return false;
901913
}
914+
#endif
902915

903916
std::string Err;
904917

905918
raw_string_ostream Stream(Err);
906919
DiagnosticPrinterRawOStream DP(Stream);
907-
#if LLVM_VERSION_GE(3, 8)
920+
#if LLVM_VERSION_GE(4, 0)
921+
if (Linker::linkModules(*Dst, std::move(Src))) {
922+
#elif LLVM_VERSION_GE(3, 8)
908923
if (Linker::linkModules(*Dst, std::move(Src.get()))) {
909924
#else
910925
if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) {

Diff for: src/rustllvm/rustllvm.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "llvm/Transforms/IPO.h"
4040
#include "llvm/Transforms/Instrumentation.h"
4141
#include "llvm/Transforms/Vectorize.h"
42-
#include "llvm/Bitcode/ReaderWriter.h"
4342
#include "llvm-c/Core.h"
4443
#include "llvm-c/BitReader.h"
4544
#include "llvm-c/ExecutionEngine.h"
@@ -60,6 +59,13 @@
6059
#include "llvm/PassManager.h"
6160
#endif
6261

62+
#if LLVM_VERSION_GE(4, 0)
63+
#include "llvm/Bitcode/BitcodeReader.h"
64+
#include "llvm/Bitcode/BitcodeWriter.h"
65+
#else
66+
#include "llvm/Bitcode/ReaderWriter.h"
67+
#endif
68+
6369
#include "llvm/IR/IRPrintingPasses.h"
6470
#include "llvm/IR/DebugInfo.h"
6571
#include "llvm/IR/DIBuilder.h"

0 commit comments

Comments
 (0)