From 22b36384b01e7e0fe26b86a08b379a739453b1e7 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 3 Jul 2009 17:24:35 +0200 Subject: [PATCH] Fix build for LLVM >= r74640 Some LLVM objects now take a 'Context' to make multi-threaded apps easier. Since we're not multi-threaded it's safe to use llvm::getGlobalContext() which gives us the same behavior as we had before. --- gen/main.cpp | 11 +++++++++++ gen/runtime.cpp | 8 ++++++++ gen/toobj.cpp | 9 ++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gen/main.cpp b/gen/main.cpp index 5920d8a2..603c5eb9 100644 --- a/gen/main.cpp +++ b/gen/main.cpp @@ -7,6 +7,9 @@ #include "gen/llvm-version.h" #include "llvm/LinkAllVMCore.h" #include "llvm/Linker.h" +#if LLVM_REV >= 74640 +#include "llvm/LLVMContext.h" +#endif #include "llvm/System/Signals.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/Target/TargetMachine.h" @@ -399,7 +402,11 @@ int main(int argc, char** argv) if (global.errors) fatal(); +#if LLVM_REV >= 74640 + llvm::Module mod("dummy", llvm::getGlobalContext()); +#else llvm::Module mod("dummy"); +#endif // override triple if needed const char* defaultTriple = DEFAULT_TARGET_TRIPLE; @@ -919,7 +926,11 @@ LDC_TARGETS char* name = m->toChars(); char* filename = m->objfile->name->str; +#if LLVM_REV >= 74640 + llvm::Linker linker(name, name, llvm::getGlobalContext()); +#else llvm::Linker linker(name, name); +#endif std::string errormsg; for (int i = 0; i < llvmModules.size(); i++) { diff --git a/gen/runtime.cpp b/gen/runtime.cpp index bc9a8eb6..e5fe2079 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -1,4 +1,8 @@ #include "gen/llvm.h" +#include "gen/llvm-version.h" +#if LLVM_REV >= 74640 +#include "llvm/LLVMContext.h" +#endif #include "llvm/Module.h" #include "llvm/Attributes.h" #include "llvm/Bitcode/ReaderWriter.h" @@ -149,7 +153,11 @@ static const LLType* rt_dg2() static void LLVM_D_BuildRuntimeModule() { Logger::println("building module"); +#if LLVM_REV >= 74640 + M = new llvm::Module("ldc internal runtime", llvm::getGlobalContext()); +#else M = new llvm::Module("ldc internal runtime"); +#endif Logger::println("building basic types"); const LLType* voidTy = LLType::VoidTy; diff --git a/gen/toobj.cpp b/gen/toobj.cpp index 928093a5..a7f2286c 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -11,8 +11,12 @@ #include #include "gen/llvm.h" +#include "gen/llvm-version.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Bitcode/ReaderWriter.h" +#if LLVM_REV >= 74640 +#include "llvm/LLVMContext.h" +#endif #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/PassManager.h" @@ -43,7 +47,6 @@ #include "gen/functions.h" #include "gen/irstate.h" #include "gen/llvmhelpers.h" -#include "gen/llvm-version.h" #include "gen/logger.h" #include "gen/optimizer.h" #include "gen/programs.h" @@ -94,7 +97,11 @@ llvm::Module* Module::genLLVMModule(Ir* sir) // create a new ir state // TODO look at making the instance static and moving most functionality into IrModule where it belongs +#if LLVM_REV >= 74640 + IRState ir(new llvm::Module(mname, llvm::getGlobalContext())); +#else IRState ir(new llvm::Module(mname)); +#endif gIR = &ir; ir.dmodule = this;