changeset 1543:21d691518d82

Use TargetRegistry instead of TargetMachineRegistry for Target lookups This fixes the build for LLVM >= r75774 and will probably break older LLVM revs.
author Benjamin Kramer <benny.kra@gmail.com>
date Wed, 15 Jul 2009 23:01:51 +0200
parents ba2a5d2fe748
children 8863cf7236e6
files gen/main.cpp
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/gen/main.cpp	Wed Jul 15 20:04:42 2009 +0200
+++ b/gen/main.cpp	Wed Jul 15 23:01:51 2009 +0200
@@ -432,22 +432,27 @@
     // Allocate target machine.
     
     // first initialize llvm
-#define LLVM_TARGET(A) LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter();
+#define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter();
 // this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ...
 LDC_TARGETS
 #undef LLVM_TARGET
 
+    const llvm::Target *theTarget;
     // Check whether the user has explicitly specified an architecture to compile for.
     if (mArch == 0)
     {
         std::string Err;
-        mArch = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(mod, Err);
-        if (mArch == 0)
+        theTarget = llvm::TargetRegistry::getClosestStaticTargetForModule(mod, Err);
+        if (theTarget == 0)
         {
             error("failed to auto-select target: %s, please use the -march option", Err.c_str());
             fatal();
         }
     }
+    else
+    {
+        theTarget = &mArch->TheTarget;
+    }
 
     // Package up features to be passed to target/subtarget
     std::string FeaturesStr;
@@ -460,7 +465,7 @@
         FeaturesStr = Features.getString();
     }
 
-    std::auto_ptr<llvm::TargetMachine> target(mArch->CtorFn(mod, FeaturesStr));
+    std::auto_ptr<llvm::TargetMachine> target(theTarget->createTargetMachine(mod, FeaturesStr));
     assert(target.get() && "Could not allocate target machine!");
     gTargetMachine = target.get();
     gTargetData = gTargetMachine->getTargetData();
@@ -469,7 +474,7 @@
     std::string datalayout = gTargetData->getStringRepresentation();
     global.params.dataLayout = datalayout.c_str();
 
-    global.params.llvmArch = mArch->Name;
+    global.params.llvmArch = theTarget->getName();
 
     if (strcmp(global.params.llvmArch,"x86")==0) {
         VersionCondition::addPredefinedGlobalIdent("X86");