1
Fork 0

Reflect supporting only LLVM 3.7+ in the LLVM wrappers

This commit is contained in:
Jake Goulding 2016-06-09 09:41:17 -04:00
parent 0740a93cc2
commit 4f01329e0e
4 changed files with 4 additions and 222 deletions

View file

@ -11,10 +11,7 @@
#include "rustllvm.h" #include "rustllvm.h"
#include "llvm/Object/Archive.h" #include "llvm/Object/Archive.h"
#if LLVM_VERSION_MINOR >= 7
#include "llvm/Object/ArchiveWriter.h" #include "llvm/Object/ArchiveWriter.h"
#endif
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
@ -34,13 +31,8 @@ struct LLVMRustArchiveMember {
~LLVMRustArchiveMember() {} ~LLVMRustArchiveMember() {}
}; };
#if LLVM_VERSION_MINOR >= 6
typedef OwningBinary<Archive> RustArchive; typedef OwningBinary<Archive> RustArchive;
#define GET_ARCHIVE(a) ((a)->getBinary()) #define GET_ARCHIVE(a) ((a)->getBinary())
#else
typedef Archive RustArchive;
#define GET_ARCHIVE(a) (a)
#endif
extern "C" void* extern "C" void*
LLVMRustOpenArchive(char *path) { LLVMRustOpenArchive(char *path) {
@ -52,7 +44,6 @@ LLVMRustOpenArchive(char *path) {
return nullptr; return nullptr;
} }
#if LLVM_VERSION_MINOR >= 6
ErrorOr<std::unique_ptr<Archive>> archive_or = ErrorOr<std::unique_ptr<Archive>> archive_or =
Archive::create(buf_or.get()->getMemBufferRef()); Archive::create(buf_or.get()->getMemBufferRef());
@ -63,14 +54,6 @@ LLVMRustOpenArchive(char *path) {
OwningBinary<Archive> *ret = new OwningBinary<Archive>( OwningBinary<Archive> *ret = new OwningBinary<Archive>(
std::move(archive_or.get()), std::move(buf_or.get())); std::move(archive_or.get()), std::move(buf_or.get()));
#else
std::error_code err;
Archive *ret = new Archive(std::move(buf_or.get()), err);
if (err) {
LLVMRustSetLastError(err.message().c_str());
return nullptr;
}
#endif
return ret; return ret;
} }
@ -137,16 +120,12 @@ LLVMRustArchiveChildName(const Archive::Child *child, size_t *size) {
extern "C" const char* extern "C" const char*
LLVMRustArchiveChildData(Archive::Child *child, size_t *size) { LLVMRustArchiveChildData(Archive::Child *child, size_t *size) {
StringRef buf; StringRef buf;
#if LLVM_VERSION_MINOR >= 7
ErrorOr<StringRef> buf_or_err = child->getBuffer(); ErrorOr<StringRef> buf_or_err = child->getBuffer();
if (buf_or_err.getError()) { if (buf_or_err.getError()) {
LLVMRustSetLastError(buf_or_err.getError().message().c_str()); LLVMRustSetLastError(buf_or_err.getError().message().c_str());
return NULL; return NULL;
} }
buf = buf_or_err.get(); buf = buf_or_err.get();
#else
buf = child->getBuffer();
#endif
*size = buf.size(); *size = buf.size();
return buf.data(); return buf.data();
} }
@ -172,7 +151,6 @@ LLVMRustWriteArchive(char *Dst,
const LLVMRustArchiveMember **NewMembers, const LLVMRustArchiveMember **NewMembers,
bool WriteSymbtab, bool WriteSymbtab,
Archive::Kind Kind) { Archive::Kind Kind) {
#if LLVM_VERSION_MINOR >= 7
std::vector<NewArchiveIterator> Members; std::vector<NewArchiveIterator> Members;
for (size_t i = 0; i < NumMembers; i++) { for (size_t i = 0; i < NumMembers; i++) {
@ -196,8 +174,5 @@ LLVMRustWriteArchive(char *Dst,
if (!pair.second) if (!pair.second)
return 0; return 0;
LLVMRustSetLastError(pair.second.message().c_str()); LLVMRustSetLastError(pair.second.message().c_str());
#else
LLVMRustSetLastError("writing archives not supported with this LLVM version");
#endif
return -1; return -1;
} }

View file

@ -90,13 +90,8 @@ extern "C" LLVMExecutionEngineRef LLVMBuildExecutionEngine(LLVMModuleRef mod)
RustJITMemoryManager *mm = new RustJITMemoryManager; RustJITMemoryManager *mm = new RustJITMemoryManager;
ExecutionEngine *ee = ExecutionEngine *ee =
#if LLVM_VERSION_MINOR >= 6
EngineBuilder(std::unique_ptr<Module>(unwrap(mod))) EngineBuilder(std::unique_ptr<Module>(unwrap(mod)))
.setMCJITMemoryManager(std::unique_ptr<RustJITMemoryManager>(mm)) .setMCJITMemoryManager(std::unique_ptr<RustJITMemoryManager>(mm))
#else
EngineBuilder(unwrap(mod))
.setMCJITMemoryManager(mm)
#endif
.setEngineKind(EngineKind::JIT) .setEngineKind(EngineKind::JIT)
.setErrorStr(&error_str) .setErrorStr(&error_str)
.setTargetOptions(options) .setTargetOptions(options)

View file

@ -15,12 +15,8 @@
#include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h" #include "llvm/Support/Host.h"
#if LLVM_VERSION_MINOR >= 7
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/TargetTransformInfo.h"
#else
#include "llvm/Target/TargetLibraryInfo.h"
#endif
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h"
@ -49,7 +45,7 @@ LLVMInitializePasses() {
initializeVectorization(Registry); initializeVectorization(Registry);
initializeIPO(Registry); initializeIPO(Registry);
initializeAnalysis(Registry); initializeAnalysis(Registry);
#if LLVM_VERSION_MINOR <= 7 #if LLVM_VERSION_MINOR == 7
initializeIPA(Registry); initializeIPA(Registry);
#endif #endif
initializeTransformUtils(Registry); initializeTransformUtils(Registry);
@ -223,17 +219,8 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
LLVMPassManagerRef PMR, LLVMPassManagerRef PMR,
LLVMModuleRef M) { LLVMModuleRef M) {
PassManagerBase *PM = unwrap(PMR); PassManagerBase *PM = unwrap(PMR);
#if LLVM_VERSION_MINOR >= 7
PM->add(createTargetTransformInfoWrapperPass( PM->add(createTargetTransformInfoWrapperPass(
unwrap(TM)->getTargetIRAnalysis())); unwrap(TM)->getTargetIRAnalysis()));
#else
#if LLVM_VERSION_MINOR == 6
PM->add(new DataLayoutPass());
#else
PM->add(new DataLayoutPass(unwrap(M)));
#endif
unwrap(TM)->addAnalysisPasses(*PM);
#endif
} }
extern "C" void extern "C" void
@ -242,10 +229,8 @@ LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
bool MergeFunctions, bool MergeFunctions,
bool SLPVectorize, bool SLPVectorize,
bool LoopVectorize) { bool LoopVectorize) {
#if LLVM_VERSION_MINOR >= 6
// Ignore mergefunc for now as enabling it causes crashes. // Ignore mergefunc for now as enabling it causes crashes.
//unwrap(PMB)->MergeFunctions = MergeFunctions; //unwrap(PMB)->MergeFunctions = MergeFunctions;
#endif
unwrap(PMB)->SLPVectorize = SLPVectorize; unwrap(PMB)->SLPVectorize = SLPVectorize;
unwrap(PMB)->OptLevel = OptLevel; unwrap(PMB)->OptLevel = OptLevel;
unwrap(PMB)->LoopVectorize = LoopVectorize; unwrap(PMB)->LoopVectorize = LoopVectorize;
@ -258,11 +243,7 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
LLVMModuleRef M, LLVMModuleRef M,
bool DisableSimplifyLibCalls) { bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple()); Triple TargetTriple(unwrap(M)->getTargetTriple());
#if LLVM_VERSION_MINOR >= 7
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple); TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple);
#else
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
#endif
if (DisableSimplifyLibCalls) if (DisableSimplifyLibCalls)
TLI->disableAllFunctions(); TLI->disableAllFunctions();
unwrap(PMB)->LibraryInfo = TLI; unwrap(PMB)->LibraryInfo = TLI;
@ -275,17 +256,10 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
LLVMModuleRef M, LLVMModuleRef M,
bool DisableSimplifyLibCalls) { bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple()); Triple TargetTriple(unwrap(M)->getTargetTriple());
#if LLVM_VERSION_MINOR >= 7
TargetLibraryInfoImpl TLII(TargetTriple); TargetLibraryInfoImpl TLII(TargetTriple);
if (DisableSimplifyLibCalls) if (DisableSimplifyLibCalls)
TLII.disableAllFunctions(); TLII.disableAllFunctions();
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII)); unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
#else
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
unwrap(PMB)->add(TLI);
#endif
} }
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over // Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
@ -323,25 +297,16 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
PassManager *PM = unwrap<PassManager>(PMR); PassManager *PM = unwrap<PassManager>(PMR);
std::string ErrorInfo; std::string ErrorInfo;
#if LLVM_VERSION_MINOR >= 6
std::error_code EC; std::error_code EC;
raw_fd_ostream OS(path, EC, sys::fs::F_None); raw_fd_ostream OS(path, EC, sys::fs::F_None);
if (EC) if (EC)
ErrorInfo = EC.message(); ErrorInfo = EC.message();
#else
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
#endif
if (ErrorInfo != "") { if (ErrorInfo != "") {
LLVMRustSetLastError(ErrorInfo.c_str()); LLVMRustSetLastError(ErrorInfo.c_str());
return false; return false;
} }
#if LLVM_VERSION_MINOR >= 7
unwrap(Target)->addPassesToEmitFile(*PM, OS, FileType, false); unwrap(Target)->addPassesToEmitFile(*PM, OS, FileType, false);
#else
formatted_raw_ostream FOS(OS);
unwrap(Target)->addPassesToEmitFile(*PM, FOS, FileType, false);
#endif
PM->run(*unwrap(M)); PM->run(*unwrap(M));
// Apparently `addPassesToEmitFile` adds a pointer to our on-the-stack output // Apparently `addPassesToEmitFile` adds a pointer to our on-the-stack output
@ -358,14 +323,10 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
PassManager *PM = unwrap<PassManager>(PMR); PassManager *PM = unwrap<PassManager>(PMR);
std::string ErrorInfo; std::string ErrorInfo;
#if LLVM_VERSION_MINOR >= 6
std::error_code EC; std::error_code EC;
raw_fd_ostream OS(path, EC, sys::fs::F_None); raw_fd_ostream OS(path, EC, sys::fs::F_None);
if (EC) if (EC)
ErrorInfo = EC.message(); ErrorInfo = EC.message();
#else
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
#endif
formatted_raw_ostream FOS(OS); formatted_raw_ostream FOS(OS);
@ -428,22 +389,10 @@ extern "C" void
LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module, LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
LLVMTargetMachineRef TMR) { LLVMTargetMachineRef TMR) {
TargetMachine *Target = unwrap(TMR); TargetMachine *Target = unwrap(TMR);
#if LLVM_VERSION_MINOR >= 7
unwrap(Module)->setDataLayout(Target->createDataLayout()); unwrap(Module)->setDataLayout(Target->createDataLayout());
#elif LLVM_VERSION_MINOR >= 6
if (const DataLayout *DL = Target->getSubtargetImpl()->getDataLayout())
unwrap(Module)->setDataLayout(DL);
#else
if (const DataLayout *DL = Target->getDataLayout())
unwrap(Module)->setDataLayout(DL);
#endif
} }
extern "C" LLVMTargetDataRef extern "C" LLVMTargetDataRef
LLVMRustGetModuleDataLayout(LLVMModuleRef M) { LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
#if LLVM_VERSION_MINOR >= 7
return wrap(&unwrap(M)->getDataLayout()); return wrap(&unwrap(M)->getDataLayout());
#else
return wrap(unwrap(M)->getDataLayout());
#endif
} }

View file

@ -243,7 +243,6 @@ extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty,
typedef DIBuilder* DIBuilderRef; typedef DIBuilder* DIBuilderRef;
#if LLVM_VERSION_MINOR >= 6
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
namespace llvm { namespace llvm {
@ -253,29 +252,15 @@ inline Metadata **unwrap(LLVMMetadataRef *Vals) {
return reinterpret_cast<Metadata**>(Vals); return reinterpret_cast<Metadata**>(Vals);
} }
} }
#else
typedef LLVMValueRef LLVMMetadataRef;
#endif
template<typename DIT> template<typename DIT>
DIT* unwrapDIptr(LLVMMetadataRef ref) { DIT* unwrapDIptr(LLVMMetadataRef ref) {
return (DIT*) (ref ? unwrap<MDNode>(ref) : NULL); return (DIT*) (ref ? unwrap<MDNode>(ref) : NULL);
} }
#if LLVM_VERSION_MINOR <= 6
template<typename DIT>
DIT unwrapDI(LLVMMetadataRef ref) {
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
}
#else
#define DIDescriptor DIScope #define DIDescriptor DIScope
#define DIArray DINodeArray #define DIArray DINodeArray
#define unwrapDI unwrapDIptr #define unwrapDI unwrapDIptr
#endif
#if LLVM_VERSION_MINOR <= 5
#define DISubroutineType DICompositeType
#endif
extern "C" uint32_t LLVMRustDebugMetadataVersion() { extern "C" uint32_t LLVMRustDebugMetadataVersion() {
return DEBUG_METADATA_VERSION; return DEBUG_METADATA_VERSION;
@ -339,16 +324,10 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(
LLVMMetadataRef File, LLVMMetadataRef File,
LLVMMetadataRef ParameterTypes) { LLVMMetadataRef ParameterTypes) {
return wrap(Builder->createSubroutineType( return wrap(Builder->createSubroutineType(
#if LLVM_VERSION_MINOR <= 7 #if LLVM_VERSION_MINOR == 7
unwrapDI<DIFile>(File), unwrapDI<DIFile>(File),
#endif #endif
#if LLVM_VERSION_MINOR >= 7
DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
#elif LLVM_VERSION_MINOR >= 6
unwrapDI<DITypeArray>(ParameterTypes)));
#else
unwrapDI<DIArray>(ParameterTypes)));
#endif
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction( extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
@ -435,11 +414,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType(
AlignInBits, AlignInBits,
Flags, Flags,
unwrapDI<DIType>(DerivedFrom), unwrapDI<DIType>(DerivedFrom),
#if LLVM_VERSION_MINOR >= 7
DINodeArray(unwrapDI<MDTuple>(Elements)), DINodeArray(unwrapDI<MDTuple>(Elements)),
#else
unwrapDI<DIArray>(Elements),
#endif
RunTimeLang, RunTimeLang,
unwrapDI<DIType>(VTableHolder), unwrapDI<DIType>(VTableHolder),
UniqueId UniqueId
@ -473,9 +448,6 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
return wrap(Builder->createLexicalBlock( return wrap(Builder->createLexicalBlock(
unwrapDI<DIDescriptor>(Scope), unwrapDI<DIDescriptor>(Scope),
unwrapDI<DIFile>(File), Line, Col unwrapDI<DIFile>(File), Line, Col
#if LLVM_VERSION_MINOR == 5
, 0
#endif
)); ));
} }
@ -490,11 +462,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable(
bool isLocalToUnit, bool isLocalToUnit,
LLVMValueRef Val, LLVMValueRef Val,
LLVMMetadataRef Decl = NULL) { LLVMMetadataRef Decl = NULL) {
#if LLVM_VERSION_MINOR >= 6
return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context), return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
#else
return wrap(Builder->createStaticVariable(unwrapDI<DIDescriptor>(Context),
#endif
Name, Name,
LinkageName, LinkageName,
unwrapDI<DIFile>(File), unwrapDI<DIFile>(File),
@ -518,25 +486,6 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
int64_t* AddrOps, int64_t* AddrOps,
unsigned AddrOpsCount, unsigned AddrOpsCount,
unsigned ArgNo) { unsigned ArgNo) {
#if LLVM_VERSION_MINOR == 5
if (AddrOpsCount > 0) {
SmallVector<llvm::Value *, 16> addr_ops;
llvm::Type *Int64Ty = Type::getInt64Ty(unwrap<MDNode>(Scope)->getContext());
for (unsigned i = 0; i < AddrOpsCount; ++i)
addr_ops.push_back(ConstantInt::get(Int64Ty, AddrOps[i]));
return wrap(Builder->createComplexVariable(
Tag,
unwrapDI<DIDescriptor>(Scope),
Name,
unwrapDI<DIFile>(File),
LineNo,
unwrapDI<DIType>(Ty),
addr_ops,
ArgNo
));
}
#endif
#if LLVM_VERSION_MINOR >= 8 #if LLVM_VERSION_MINOR >= 8
if (Tag == 0x100) { // DW_TAG_auto_variable if (Tag == 0x100) { // DW_TAG_auto_variable
return wrap(Builder->createAutoVariable( return wrap(Builder->createAutoVariable(
@ -568,11 +517,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateArrayType(
LLVMMetadataRef Subscripts) { LLVMMetadataRef Subscripts) {
return wrap(Builder->createArrayType(Size, AlignInBits, return wrap(Builder->createArrayType(Size, AlignInBits,
unwrapDI<DIType>(Ty), unwrapDI<DIType>(Ty),
#if LLVM_VERSION_MINOR >= 7
DINodeArray(unwrapDI<MDTuple>(Subscripts)) DINodeArray(unwrapDI<MDTuple>(Subscripts))
#else
unwrapDI<DIArray>(Subscripts)
#endif
)); ));
} }
@ -584,11 +529,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVectorType(
LLVMMetadataRef Subscripts) { LLVMMetadataRef Subscripts) {
return wrap(Builder->createVectorType(Size, AlignInBits, return wrap(Builder->createVectorType(Size, AlignInBits,
unwrapDI<DIType>(Ty), unwrapDI<DIType>(Ty),
#if LLVM_VERSION_MINOR >= 7
DINodeArray(unwrapDI<MDTuple>(Subscripts)) DINodeArray(unwrapDI<MDTuple>(Subscripts))
#else
unwrapDI<DIArray>(Subscripts)
#endif
)); ));
} }
@ -603,18 +544,9 @@ extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(
DIBuilderRef Builder, DIBuilderRef Builder,
LLVMMetadataRef* Ptr, LLVMMetadataRef* Ptr,
unsigned Count) { unsigned Count) {
#if LLVM_VERSION_MINOR >= 7
Metadata **DataValue = unwrap(Ptr); Metadata **DataValue = unwrap(Ptr);
return wrap(Builder->getOrCreateArray( return wrap(Builder->getOrCreateArray(
ArrayRef<Metadata*>(DataValue, Count)).get()); ArrayRef<Metadata*>(DataValue, Count)).get());
#else
return wrap(Builder->getOrCreateArray(
#if LLVM_VERSION_MINOR >= 6
ArrayRef<Metadata*>(unwrap(Ptr), Count)));
#else
ArrayRef<Value*>(reinterpret_cast<Value**>(Ptr), Count)));
#endif
#endif
} }
extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
@ -627,18 +559,10 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
LLVMBasicBlockRef InsertAtEnd) { LLVMBasicBlockRef InsertAtEnd) {
return wrap(Builder->insertDeclare( return wrap(Builder->insertDeclare(
unwrap(Val), unwrap(Val),
#if LLVM_VERSION_MINOR >= 7
unwrap<DILocalVariable>(VarInfo), unwrap<DILocalVariable>(VarInfo),
#else
unwrapDI<DIVariable>(VarInfo),
#endif
#if LLVM_VERSION_MINOR >= 6
Builder->createExpression( Builder->createExpression(
llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)), llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
#endif
#if LLVM_VERSION_MINOR >= 7
DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())), DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
#endif
unwrap(InsertAtEnd))); unwrap(InsertAtEnd)));
} }
@ -650,22 +574,12 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
unsigned AddrOpsCount, unsigned AddrOpsCount,
LLVMValueRef DL, LLVMValueRef DL,
LLVMValueRef InsertBefore) { LLVMValueRef InsertBefore) {
#if LLVM_VERSION_MINOR >= 6
#endif
return wrap(Builder->insertDeclare( return wrap(Builder->insertDeclare(
unwrap(Val), unwrap(Val),
#if LLVM_VERSION_MINOR >= 7
unwrap<DILocalVariable>(VarInfo), unwrap<DILocalVariable>(VarInfo),
#else
unwrapDI<DIVariable>(VarInfo),
#endif
#if LLVM_VERSION_MINOR >= 6
Builder->createExpression( Builder->createExpression(
llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)), llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
#endif
#if LLVM_VERSION_MINOR >= 7
DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())), DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
#endif
unwrap<Instruction>(InsertBefore))); unwrap<Instruction>(InsertBefore)));
} }
@ -695,11 +609,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
LineNumber, LineNumber,
SizeInBits, SizeInBits,
AlignInBits, AlignInBits,
#if LLVM_VERSION_MINOR >= 7
DINodeArray(unwrapDI<MDTuple>(Elements)), DINodeArray(unwrapDI<MDTuple>(Elements)),
#else
unwrapDI<DIArray>(Elements),
#endif
unwrapDI<DIType>(ClassType))); unwrapDI<DIType>(ClassType)));
} }
@ -724,11 +634,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType(
SizeInBits, SizeInBits,
AlignInBits, AlignInBits,
Flags, Flags,
#if LLVM_VERSION_MINOR >= 7
DINodeArray(unwrapDI<MDTuple>(Elements)), DINodeArray(unwrapDI<MDTuple>(Elements)),
#else
unwrapDI<DIArray>(Elements),
#endif
RunTimeLang, RunTimeLang,
UniqueId UniqueId
)); ));
@ -747,12 +653,6 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter(
unwrapDI<DIDescriptor>(Scope), unwrapDI<DIDescriptor>(Scope),
Name, Name,
unwrapDI<DIType>(Ty) unwrapDI<DIType>(Ty)
#if LLVM_VERSION_MINOR <= 6
,
unwrapDI<MDNode*>(File),
LineNo,
ColumnNo
#endif
)); ));
} }
@ -785,15 +685,8 @@ extern "C" void LLVMDICompositeTypeSetTypeArray(
LLVMMetadataRef CompositeType, LLVMMetadataRef CompositeType,
LLVMMetadataRef TypeArray) LLVMMetadataRef TypeArray)
{ {
#if LLVM_VERSION_MINOR >= 7
DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType); DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType);
Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray))); Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray)));
#elif LLVM_VERSION_MINOR >= 6
DICompositeType tmp = unwrapDI<DICompositeType>(CompositeType);
Builder->replaceArrays(tmp, unwrapDI<DIArray>(TypeArray));
#else
unwrapDI<DICompositeType>(CompositeType).setTypeArray(unwrapDI<DIArray>(TypeArray));
#endif
} }
extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation( extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
@ -810,15 +703,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
unwrapDIptr<MDNode>(Scope), unwrapDIptr<MDNode>(Scope),
unwrapDIptr<MDNode>(InlinedAt)); unwrapDIptr<MDNode>(InlinedAt));
#if LLVM_VERSION_MINOR >= 6 return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode()));
return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode(
#if LLVM_VERSION_MINOR <= 6
context
#endif
)));
#else
return wrap(debug_loc.getAsMDNode(context));
#endif
} }
extern "C" void LLVMWriteTypeToString(LLVMTypeRef Type, RustStringRef str) { extern "C" void LLVMWriteTypeToString(LLVMTypeRef Type, RustStringRef str) {
@ -838,40 +723,22 @@ extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) {
extern "C" bool extern "C" bool
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) { LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
Module *Dst = unwrap(dst); Module *Dst = unwrap(dst);
#if LLVM_VERSION_MINOR >= 6
std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len)); std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
#if LLVM_VERSION_MINOR >= 7
ErrorOr<std::unique_ptr<Module>> Src = ErrorOr<std::unique_ptr<Module>> Src =
llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext()); llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
#else
ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
#endif
#else
MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(buf, Dst->getContext());
#endif
if (!Src) { if (!Src) {
LLVMRustSetLastError(Src.getError().message().c_str()); LLVMRustSetLastError(Src.getError().message().c_str());
#if LLVM_VERSION_MINOR == 5
delete buf;
#endif
return false; return false;
} }
std::string Err; std::string Err;
#if LLVM_VERSION_MINOR >= 6
raw_string_ostream Stream(Err); raw_string_ostream Stream(Err);
DiagnosticPrinterRawOStream DP(Stream); DiagnosticPrinterRawOStream DP(Stream);
#if LLVM_VERSION_MINOR >= 8 #if LLVM_VERSION_MINOR >= 8
if (Linker::linkModules(*Dst, std::move(Src.get()))) { if (Linker::linkModules(*Dst, std::move(Src.get()))) {
#elif LLVM_VERSION_MINOR >= 7 #else
if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) { if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
#else
if (Linker::LinkModules(Dst, *Src, [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
#endif
#else
if (Linker::LinkModules(Dst, *Src, Linker::DestroySource, &Err)) {
#endif #endif
LLVMRustSetLastError(Err.c_str()); LLVMRustSetLastError(Err.c_str());
return false; return false;
@ -975,11 +842,7 @@ extern "C" void LLVMWriteDebugLocToString(
RustStringRef str) RustStringRef str)
{ {
raw_rust_string_ostream os(str); raw_rust_string_ostream os(str);
#if LLVM_VERSION_MINOR >= 7
unwrap(dl)->print(os); unwrap(dl)->print(os);
#else
unwrap(dl)->print(*unwrap(C), os);
#endif
} }
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef)