Extend preprocessor LLVM version checks to support LLVM 4.x
This doesn't actually do anything for LLVM 4.x yet, but sets the stage.
This commit is contained in:
parent
b786976a15
commit
e6e117c33a
@ -22,7 +22,7 @@ struct RustArchiveMember {
|
||||
Archive::Child child;
|
||||
|
||||
RustArchiveMember(): filename(NULL), name(NULL),
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
child(NULL, NULL, NULL)
|
||||
#else
|
||||
child(NULL, NULL)
|
||||
@ -35,7 +35,7 @@ struct RustArchiveMember {
|
||||
struct RustArchiveIterator {
|
||||
Archive::child_iterator cur;
|
||||
Archive::child_iterator end;
|
||||
#if LLVM_VERSION_MINOR >= 9
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
Error err;
|
||||
#endif
|
||||
};
|
||||
@ -81,7 +81,7 @@ LLVMRustOpenArchive(char *path) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
ErrorOr<std::unique_ptr<Archive>> archive_or =
|
||||
#else
|
||||
Expected<std::unique_ptr<Archive>> archive_or =
|
||||
@ -89,7 +89,7 @@ LLVMRustOpenArchive(char *path) {
|
||||
Archive::create(buf_or.get()->getMemBufferRef());
|
||||
|
||||
if (!archive_or) {
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
LLVMRustSetLastError(archive_or.getError().message().c_str());
|
||||
#else
|
||||
LLVMRustSetLastError(toString(archive_or.takeError()).c_str());
|
||||
@ -112,7 +112,7 @@ extern "C" LLVMRustArchiveIteratorRef
|
||||
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
||||
Archive *ar = ra->getBinary();
|
||||
RustArchiveIterator *rai = new RustArchiveIterator();
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
rai->cur = ar->child_begin();
|
||||
#else
|
||||
rai->cur = ar->child_begin(rai->err);
|
||||
@ -127,7 +127,7 @@ LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
||||
|
||||
extern "C" LLVMRustArchiveChildConstRef
|
||||
LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
||||
#if LLVM_VERSION_MINOR >= 9
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
return NULL;
|
||||
@ -135,7 +135,7 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
||||
#endif
|
||||
if (rai->cur == rai->end)
|
||||
return NULL;
|
||||
#if LLVM_VERSION_MINOR == 8
|
||||
#if LLVM_VERSION_EQ(3, 8)
|
||||
const ErrorOr<Archive::Child>* cur = rai->cur.operator->();
|
||||
if (!*cur) {
|
||||
LLVMRustSetLastError(cur->getError().message().c_str());
|
||||
@ -207,7 +207,7 @@ LLVMRustWriteArchive(char *Dst,
|
||||
bool WriteSymbtab,
|
||||
LLVMRustArchiveKind rust_kind) {
|
||||
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
std::vector<NewArchiveIterator> Members;
|
||||
#else
|
||||
std::vector<NewArchiveMember> Members;
|
||||
@ -218,20 +218,20 @@ LLVMRustWriteArchive(char *Dst,
|
||||
auto Member = NewMembers[i];
|
||||
assert(Member->name);
|
||||
if (Member->filename) {
|
||||
#if LLVM_VERSION_MINOR >= 9
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getFile(Member->filename, true);
|
||||
if (!MOrErr) {
|
||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||
return LLVMRustResult::Failure;
|
||||
}
|
||||
Members.push_back(std::move(*MOrErr));
|
||||
#elif LLVM_VERSION_MINOR == 8
|
||||
#elif LLVM_VERSION_EQ(3, 8)
|
||||
Members.push_back(NewArchiveIterator(Member->filename));
|
||||
#else
|
||||
Members.push_back(NewArchiveIterator(Member->filename, Member->name));
|
||||
#endif
|
||||
} else {
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Members.push_back(NewArchiveIterator(Member->child, Member->name));
|
||||
#else
|
||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getOldMember(Member->child, true);
|
||||
@ -243,7 +243,7 @@ LLVMRustWriteArchive(char *Dst,
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
auto pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
|
||||
#else
|
||||
auto pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true);
|
||||
|
@ -46,7 +46,7 @@ LLVMInitializePasses() {
|
||||
initializeVectorization(Registry);
|
||||
initializeIPO(Registry);
|
||||
initializeAnalysis(Registry);
|
||||
#if LLVM_VERSION_MINOR == 7
|
||||
#if LLVM_VERSION_EQ(3, 7)
|
||||
initializeIPA(Registry);
|
||||
#endif
|
||||
initializeTransformUtils(Registry);
|
||||
@ -297,7 +297,7 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||
bool FunctionSections,
|
||||
bool DataSections) {
|
||||
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Reloc::Model RM;
|
||||
#else
|
||||
Optional<Reloc::Model> RM;
|
||||
@ -316,7 +316,7 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||
RM = Reloc::DynamicNoPIC;
|
||||
break;
|
||||
default:
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
RM = Reloc::Default;
|
||||
#endif
|
||||
break;
|
||||
@ -337,7 +337,7 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||
}
|
||||
|
||||
TargetOptions Options;
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Options.PositionIndependentExecutable = PositionIndependentExecutable;
|
||||
#endif
|
||||
|
||||
@ -539,7 +539,7 @@ extern "C" void
|
||||
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
|
||||
llvm::legacy::PassManager passes;
|
||||
|
||||
#if LLVM_VERSION_MINOR <= 8
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
ArrayRef<const char*> ref(symbols, len);
|
||||
passes.add(llvm::createInternalizePass(ref));
|
||||
#else
|
||||
@ -593,7 +593,7 @@ LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||
#if LLVM_VERSION_MINOR >= 9
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||
#endif
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateSubroutineType(
|
||||
LLVMRustMetadataRef File,
|
||||
LLVMRustMetadataRef ParameterTypes) {
|
||||
return wrap(Builder->createSubroutineType(
|
||||
#if LLVM_VERSION_MINOR == 7
|
||||
#if LLVM_VERSION_EQ(3, 7)
|
||||
unwrapDI<DIFile>(File),
|
||||
#endif
|
||||
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
|
||||
@ -416,7 +416,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction(
|
||||
LLVMValueRef Fn,
|
||||
LLVMRustMetadataRef TParam,
|
||||
LLVMRustMetadataRef Decl) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
DITemplateParameterArray TParams =
|
||||
DITemplateParameterArray(unwrap<MDTuple>(TParam));
|
||||
DISubprogram *Sub = Builder->createFunction(
|
||||
@ -565,7 +565,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
|
||||
int64_t* AddrOps,
|
||||
unsigned AddrOpsCount,
|
||||
unsigned ArgNo) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
if (Tag == 0x100) { // DW_TAG_auto_variable
|
||||
return wrap(Builder->createAutoVariable(
|
||||
unwrapDI<DIDescriptor>(Scope), Name,
|
||||
@ -814,7 +814,7 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
|
||||
|
||||
raw_string_ostream Stream(Err);
|
||||
DiagnosticPrinterRawOStream DP(Stream);
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
if (Linker::linkModules(*Dst, std::move(Src.get()))) {
|
||||
#else
|
||||
if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
|
||||
@ -937,14 +937,14 @@ to_rust(DiagnosticKind kind)
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkMissed;
|
||||
case DK_OptimizationRemarkAnalysis:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis;
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
case DK_OptimizationRemarkAnalysisFPCommute:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
|
||||
case DK_OptimizationRemarkAnalysisAliasing:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
|
||||
#endif
|
||||
default:
|
||||
#if LLVM_VERSION_MINOR >= 9
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
return (kind >= DK_FirstRemark && kind <= DK_LastRemark) ?
|
||||
LLVMRustDiagnosticKind::OptimizationRemarkOther :
|
||||
LLVMRustDiagnosticKind::Other;
|
||||
@ -994,7 +994,7 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) {
|
||||
return LLVMVectorTypeKind;
|
||||
case Type::X86_MMXTyID:
|
||||
return LLVMX86_MMXTypeKind;
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
case Type::TokenTyID:
|
||||
return LLVMTokenTypeKind;
|
||||
#endif
|
||||
@ -1043,7 +1043,7 @@ LLVMRustBuildCleanupPad(LLVMBuilderRef Builder,
|
||||
unsigned ArgCnt,
|
||||
LLVMValueRef *LLArgs,
|
||||
const char *Name) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
Value **Args = unwrap(LLArgs);
|
||||
if (ParentPad == NULL) {
|
||||
Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
|
||||
@ -1061,7 +1061,7 @@ extern "C" LLVMValueRef
|
||||
LLVMRustBuildCleanupRet(LLVMBuilderRef Builder,
|
||||
LLVMValueRef CleanupPad,
|
||||
LLVMBasicBlockRef UnwindBB) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
CleanupPadInst *Inst = cast<CleanupPadInst>(unwrap(CleanupPad));
|
||||
return wrap(unwrap(Builder)->CreateCleanupRet(Inst, unwrap(UnwindBB)));
|
||||
#else
|
||||
@ -1075,7 +1075,7 @@ LLVMRustBuildCatchPad(LLVMBuilderRef Builder,
|
||||
unsigned ArgCnt,
|
||||
LLVMValueRef *LLArgs,
|
||||
const char *Name) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
Value **Args = unwrap(LLArgs);
|
||||
return wrap(unwrap(Builder)->CreateCatchPad(unwrap(ParentPad),
|
||||
ArrayRef<Value*>(Args, ArgCnt),
|
||||
@ -1089,7 +1089,7 @@ extern "C" LLVMValueRef
|
||||
LLVMRustBuildCatchRet(LLVMBuilderRef Builder,
|
||||
LLVMValueRef Pad,
|
||||
LLVMBasicBlockRef BB) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
return wrap(unwrap(Builder)->CreateCatchRet(cast<CatchPadInst>(unwrap(Pad)),
|
||||
unwrap(BB)));
|
||||
#else
|
||||
@ -1103,7 +1103,7 @@ LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder,
|
||||
LLVMBasicBlockRef BB,
|
||||
unsigned NumHandlers,
|
||||
const char *Name) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
if (ParentPad == NULL) {
|
||||
Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
|
||||
ParentPad = wrap(Constant::getNullValue(Ty));
|
||||
@ -1120,7 +1120,7 @@ LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder,
|
||||
extern "C" void
|
||||
LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
|
||||
LLVMBasicBlockRef Handler) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
Value *CatchSwitch = unwrap(CatchSwitchRef);
|
||||
cast<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Handler));
|
||||
#endif
|
||||
@ -1129,14 +1129,14 @@ LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
|
||||
extern "C" void
|
||||
LLVMRustSetPersonalityFn(LLVMBuilderRef B,
|
||||
LLVMValueRef Personality) {
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
unwrap(B)->GetInsertBlock()
|
||||
->getParent()
|
||||
->setPersonalityFn(cast<Function>(unwrap(Personality)));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_MINOR >= 8
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
extern "C" OperandBundleDef*
|
||||
LLVMRustBuildOperandBundleDef(const char *Name,
|
||||
LLVMValueRef *Inputs,
|
||||
|
@ -45,7 +45,16 @@
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Object.h"
|
||||
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
#define LLVM_VERSION_GE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR > (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
||||
|
||||
#define LLVM_VERSION_EQ(major, minor) \
|
||||
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
|
||||
|
||||
#define LLVM_VERSION_LE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
||||
|
||||
#if LLVM_VERSION_GE(3, 7)
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
#else
|
||||
#include "llvm/PassManager.h"
|
||||
|
Loading…
Reference in New Issue
Block a user