[cfe-commits] r148950 - in /cfe/trunk: include/clang/Driver/Driver.h include/clang/Driver/HostInfo.h lib/Driver/CMakeLists.txt lib/Driver/Driver.cpp lib/Driver/HostInfo.cpp lib/Driver/Tools.cpp

Chandler Carruth chandlerc at gmail.com
Wed Jan 25 03:01:57 PST 2012


Author: chandlerc
Date: Wed Jan 25 05:01:57 2012
New Revision: 148950

URL: http://llvm.org/viewvc/llvm-project?rev=148950&view=rev
Log:
Delete the driver's HostInfo class. This abstraction just never really
did anything. The two big pieces of functionality it tried to provide
was to cache the ToolChain objects for each target, and to figure out
the exact target based on the flag set coming in to an invocation.
However, it had a lot of flaws even with those goals:
 - Neither of these have anything to do with the host, or its info.
 - The HostInfo class was setup as a full blown class *hierarchy* with
   a separate implementation for each "host" OS. This required
   dispatching just to create the objects in the first place.
 - The hierarchy claimed to represent the host, when in fact it was
   based on the target OS.
 - Each leaf in the hierarchy was responsible for implementing the flag
   processing and caching, resulting in a *lot* of copy-paste code and
   quite a few bugs.
 - The caching was consistently done based on architecture alone, even
   though *any* aspect of the targeted triple might change the behavior
   of the configured toolchain.
 - Flag processing was already being done in the Driver proper,
   separating the flag handling even more than it already is.

Instead of this, we can simply have the dispatch logic in the Driver
which previously created a HostInfo object create the ToolChain objects.
Adding caching in the Driver layer is a tiny amount of code. Finally,
pulling the flag processing into the Driver puts it where it belongs and
consolidates it in one location.

The result is that two functions, and maybe 100 lines of new code
replace over 10 classes and 800 lines of code. Woot.

This also paves the way to introduce more detailed ToolChain objects for
various OSes without threading through a new HostInfo type as well, and
the accompanying boiler plate. That, of course, was the yak I started to
shave that began this entire refactoring escapade. Wheee!

Removed:
    cfe/trunk/include/clang/Driver/HostInfo.h
    cfe/trunk/lib/Driver/HostInfo.cpp
Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/CMakeLists.txt
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=148950&r1=148949&r2=148950&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Wed Jan 25 05:01:57 2012
@@ -16,6 +16,7 @@
 #include "clang/Driver/Types.h"
 #include "clang/Driver/Util.h"
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Path.h" // FIXME: Kill when CompilationInfo
@@ -175,6 +176,13 @@
   std::list<std::string> TempFiles;
   std::list<std::string> ResultFiles;
 
+  /// \brief Cache of all the ToolChains in use by the driver.
+  ///
+  /// This maps from the string representation of a triple to a ToolChain
+  /// created targetting that triple. The driver owns all the ToolChain objects
+  /// stored in it, and will clean them up when torn down.
+  mutable llvm::StringMap<ToolChain *> ToolChains;
+
 private:
   /// TranslateInputArgs - Create a new derived argument list from the input
   /// arguments, after applying the standard argument translations.
@@ -390,8 +398,17 @@
 
   bool IsUsingLTO(const ArgList &Args) const;
 
+private:
+  /// \brief Retrieves a ToolChain for a particular target triple.
+  ///
+  /// Will cache ToolChains for the life of the driver object, and create them
+  /// on-demand.
+  const ToolChain &getToolChain(const ArgList &Args,
+                                StringRef DarwinArchName = "") const;
+
   /// @}
 
+public:
   /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
   /// return the grouped values as integers. Numbers which are not
   /// provided are set to 0.

Removed: cfe/trunk/include/clang/Driver/HostInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/HostInfo.h?rev=148949&view=auto
==============================================================================
--- cfe/trunk/include/clang/Driver/HostInfo.h (original)
+++ cfe/trunk/include/clang/Driver/HostInfo.h (removed)
@@ -1,90 +0,0 @@
-//===--- HostInfo.h - Host specific information -----------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef CLANG_DRIVER_HOSTINFO_H_
-#define CLANG_DRIVER_HOSTINFO_H_
-
-#include "llvm/ADT/Triple.h"
-#include <string>
-
-namespace clang {
-namespace driver {
-  class ArgList;
-  class Driver;
-  class ToolChain;
-
-/// HostInfo - Config information about a particular host which may interact
-/// with driver behavior.
-///
-/// The host information is used for controlling the parts of the driver which
-/// interact with the platform the driver is ostensibly being run from. For
-/// testing purposes, the HostInfo used by the driver may differ from the actual
-/// host.
-class HostInfo {
-protected:
-  const Driver &TheDriver;
-  const llvm::Triple Triple;
-
-  HostInfo(const Driver &D, const llvm::Triple &_Triple);
-
-public:
-  virtual ~HostInfo();
-
-  const Driver &getDriver() const { return TheDriver; }
-
-  const llvm::Triple& getTriple() const { return Triple; }
-  std::string getArchName() const { return Triple.getArchName(); }
-  std::string getPlatformName() const { return Triple.getVendorName(); }
-  std::string getOSName() const { return Triple.getOSName(); }
-
-  /// CreateToolChain - Construct the toolchain to use for this host (which the
-  /// host retains ownership of).
-  ///
-  /// \param Args - The argument list, which may be used to alter the default
-  /// toolchain, for example in the presence of -m32 or -m64.
-  ///
-  /// \param ArchName - The architecture to return a toolchain for, or 0 if
-  /// unspecified. This will only ever be non-zero for hosts which support a
-  /// driver driver.
-
-  // FIXME: Pin down exactly what the HostInfo is allowed to use Args
-  // for here. Currently this is for -m32 / -m64 defaulting.
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName=0) const = 0;
-};
-
-const HostInfo *createAuroraUXHostInfo(const Driver &D,
-                                       const llvm::Triple& Triple);
-const HostInfo *createDarwinHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple);
-const HostInfo *createOpenBSDHostInfo(const Driver &D,
-                                      const llvm::Triple& Triple);
-const HostInfo *createFreeBSDHostInfo(const Driver &D,
-                                      const llvm::Triple& Triple);
-const HostInfo *createNetBSDHostInfo(const Driver &D,
-                                      const llvm::Triple& Triple);
-const HostInfo *createMinixHostInfo(const Driver &D,
-                                      const llvm::Triple& Triple);
-const HostInfo *createDragonFlyHostInfo(const Driver &D,
-                                        const llvm::Triple& Triple);
-const HostInfo *createLinuxHostInfo(const Driver &D,
-                                    const llvm::Triple& Triple);
-const HostInfo *createTCEHostInfo(const Driver &D, 
-                                  const llvm::Triple& Triple);
-const HostInfo *createWindowsHostInfo(const Driver &D,
-                                      const llvm::Triple &Triple);
-const HostInfo *createMinGWHostInfo(const Driver &D,
-                                    const llvm::Triple &Triple);
-const HostInfo *createUnknownHostInfo(const Driver &D,
-                                      const llvm::Triple& Triple);
-
-} // end namespace driver
-} // end namespace clang
-
-#endif

Modified: cfe/trunk/lib/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CMakeLists.txt?rev=148950&r1=148949&r2=148950&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/CMakeLists.txt (original)
+++ cfe/trunk/lib/Driver/CMakeLists.txt Wed Jan 25 05:01:57 2012
@@ -9,7 +9,6 @@
   Compilation.cpp
   Driver.cpp
   DriverOptions.cpp
-  HostInfo.cpp
   Job.cpp
   Option.cpp
   OptTable.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=148950&r1=148949&r2=148950&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Jan 25 05:01:57 2012
@@ -18,7 +18,6 @@
 #include "clang/Driver/ArgList.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/DriverDiagnostic.h"
-#include "clang/Driver/HostInfo.h"
 #include "clang/Driver/Job.h"
 #include "clang/Driver/OptTable.h"
 #include "clang/Driver/Option.h"
@@ -40,6 +39,7 @@
 #include "llvm/Support/Program.h"
 
 #include "InputInfo.h"
+#include "ToolChains.h"
 
 #include <map>
 
@@ -91,7 +91,11 @@
 
 Driver::~Driver() {
   delete Opts;
-  delete Host;
+
+  for (llvm::StringMap<ToolChain *>::iterator I = ToolChains.begin(),
+                                              E = ToolChains.end();
+       I != E; ++I)
+    delete I->second;
 }
 
 InputArgList *Driver::ParseArgStrings(ArrayRef<const char *> ArgList) {
@@ -236,18 +240,6 @@
   return DAL;
 }
 
-/// \brief Compute target triple from args.
-///
-/// This routine provides the logic to compute a target triple from various
-/// args passed to the driver and the default triple string.
-static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
-                                        const ArgList &Args) {
-  if (const Arg *A = Args.getLastArg(options::OPT_target))
-    DefaultTargetTriple = A->getValue(Args);
-
-  return llvm::Triple(llvm::Triple::normalize(DefaultTargetTriple));
-}
-
 Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
   llvm::PrettyStackTraceString CrashInfo("Compilation construction");
 
@@ -329,15 +321,11 @@
   if (Args->hasArg(options::OPT_nostdlib))
     UseStdLib = false;
 
-  // Compute the target triple based on the args, and build a Host out of it.
-  // FIXME: Yes, this makes no sense. HostInfo has little to do with the host.
-  Host = GetHostInfo(computeTargetTriple(DefaultTargetTriple, *Args));
-
   // Perform the default argument translations.
   DerivedArgList *TranslatedArgs = TranslateInputArgs(*Args);
 
   // Owned by the host.
-  const ToolChain &TC = *Host->CreateToolChain(*Args);
+  const ToolChain &TC = getToolChain(*Args);
 
   // The compilation takes ownership of Args.
   Compilation *C = new Compilation(*this, TC, Args, TranslatedArgs);
@@ -1328,9 +1316,8 @@
   if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) {
     const ToolChain *TC = &C.getDefaultToolChain();
 
-    std::string Arch;
     if (BAA->getArchName())
-      TC = Host->CreateToolChain(C.getArgs(), BAA->getArchName());
+      TC = &getToolChain(C.getArgs(), BAA->getArchName());
 
     BuildJobsForAction(C, *BAA->begin(), TC, BAA->getArchName(),
                        AtTopLevel, LinkingOutput, Result);
@@ -1584,39 +1571,118 @@
   return P.str();
 }
 
-const HostInfo *Driver::GetHostInfo(const llvm::Triple &Triple) const {
-  llvm::PrettyStackTraceString CrashInfo("Constructing host");
+/// \brief Compute target triple from args.
+///
+/// This routine provides the logic to compute a target triple from various
+/// args passed to the driver and the default triple string.
+static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
+                                        const ArgList &Args,
+                                        StringRef DarwinArchName) {
+  if (const Arg *A = Args.getLastArg(options::OPT_target))
+    DefaultTargetTriple = A->getValue(Args);
+
+  llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple));
+
+  // Handle Darwin-specific options available here.
+  if (Target.isOSDarwin()) {
+    // If an explict Darwin arch name is given, that trumps all.
+    if (!DarwinArchName.empty()) {
+      Target.setArch(
+        llvm::Triple::getArchTypeForDarwinArchName(DarwinArchName));
+      return Target;
+    }
+
+    // Handle the Darwin '-arch' flag.
+    if (Arg *A = Args.getLastArg(options::OPT_arch)) {
+      llvm::Triple::ArchType DarwinArch
+        = llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args));
+      if (DarwinArch != llvm::Triple::UnknownArch)
+        Target.setArch(DarwinArch);
+    }
+  }
+
+  // Skip further flag support on OSes which don't support '-m32' or '-m64'.
+  if (Target.getArchName() == "tce" ||
+      Target.getOS() == llvm::Triple::AuroraUX ||
+      Target.getOS() == llvm::Triple::Minix)
+    return Target;
+
+  // Handle pseudo-target flags '-m32' and '-m64'.
+  // FIXME: Should this information be in llvm::Triple?
+  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
+    if (A->getOption().matches(options::OPT_m32)) {
+      if (Target.getArch() == llvm::Triple::x86_64)
+        Target.setArch(llvm::Triple::x86);
+      if (Target.getArch() == llvm::Triple::ppc64)
+        Target.setArch(llvm::Triple::ppc);
+    } else {
+      if (Target.getArch() == llvm::Triple::x86)
+        Target.setArch(llvm::Triple::x86_64);
+      if (Target.getArch() == llvm::Triple::ppc)
+        Target.setArch(llvm::Triple::ppc64);
+    }
+  }
+
+  return Target;
+}
+
+const ToolChain &Driver::getToolChain(const ArgList &Args,
+                                      StringRef DarwinArchName) const {
+  llvm::Triple Target = computeTargetTriple(DefaultTargetTriple, Args,
+                                            DarwinArchName);
 
-  // TCE is an osless target
-  if (Triple.getArchName() == "tce")
-    return createTCEHostInfo(*this, Triple);
-
-  switch (Triple.getOS()) {
-  case llvm::Triple::AuroraUX:
-    return createAuroraUXHostInfo(*this, Triple);
-  case llvm::Triple::Darwin:
-  case llvm::Triple::MacOSX:
-  case llvm::Triple::IOS:
-    return createDarwinHostInfo(*this, Triple);
-  case llvm::Triple::DragonFly:
-    return createDragonFlyHostInfo(*this, Triple);
-  case llvm::Triple::OpenBSD:
-    return createOpenBSDHostInfo(*this, Triple);
-  case llvm::Triple::NetBSD:
-    return createNetBSDHostInfo(*this, Triple);
-  case llvm::Triple::FreeBSD:
-    return createFreeBSDHostInfo(*this, Triple);
-  case llvm::Triple::Minix:
-    return createMinixHostInfo(*this, Triple);
-  case llvm::Triple::Linux:
-    return createLinuxHostInfo(*this, Triple);
-  case llvm::Triple::Win32:
-    return createWindowsHostInfo(*this, Triple);
-  case llvm::Triple::MinGW32:
-    return createMinGWHostInfo(*this, Triple);
-  default:
-    return createUnknownHostInfo(*this, Triple);
+  ToolChain *&TC = ToolChains[Target.str()];
+  if (!TC) {
+    switch (Target.getOS()) {
+    case llvm::Triple::AuroraUX:
+      TC = new toolchains::AuroraUX(*this, Target);
+      break;
+    case llvm::Triple::Darwin:
+    case llvm::Triple::MacOSX:
+    case llvm::Triple::IOS:
+      if (Target.getArch() == llvm::Triple::x86 ||
+          Target.getArch() == llvm::Triple::x86_64 ||
+          Target.getArch() == llvm::Triple::arm ||
+          Target.getArch() == llvm::Triple::thumb)
+        TC = new toolchains::DarwinClang(*this, Target);
+      else
+        TC = new toolchains::Darwin_Generic_GCC(*this, Target);
+      break;
+    case llvm::Triple::DragonFly:
+      TC = new toolchains::DragonFly(*this, Target);
+      break;
+    case llvm::Triple::OpenBSD:
+      TC = new toolchains::OpenBSD(*this, Target);
+      break;
+    case llvm::Triple::NetBSD:
+      TC = new toolchains::NetBSD(*this, Target, Target);
+      break;
+    case llvm::Triple::FreeBSD:
+      TC = new toolchains::FreeBSD(*this, Target);
+      break;
+    case llvm::Triple::Minix:
+      TC = new toolchains::Minix(*this, Target);
+      break;
+    case llvm::Triple::Linux:
+      TC = new toolchains::Linux(*this, Target);
+      break;
+    case llvm::Triple::Win32:
+      TC = new toolchains::Windows(*this, Target);
+      break;
+    case llvm::Triple::MinGW32:
+      // FIXME: We need a MinGW toolchain. Fallthrough for now.
+    default:
+      // TCE is an OSless target
+      if (Target.getArchName() == "tce") {
+        TC = new toolchains::TCEToolChain(*this, Target);
+        break;
+      }
+
+      TC = new toolchains::Generic_GCC(*this, Target);
+      break;
+    }
   }
+  return *TC;
 }
 
 bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA,

Removed: cfe/trunk/lib/Driver/HostInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/HostInfo.cpp?rev=148949&view=auto
==============================================================================
--- cfe/trunk/lib/Driver/HostInfo.cpp (original)
+++ cfe/trunk/lib/Driver/HostInfo.cpp (removed)
@@ -1,670 +0,0 @@
-//===--- HostInfo.cpp - Host specific information -------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Driver/HostInfo.h"
-
-#include "clang/Driver/Arg.h"
-#include "clang/Driver/ArgList.h"
-#include "clang/Driver/Driver.h"
-#include "clang/Driver/DriverDiagnostic.h"
-#include "clang/Driver/Option.h"
-#include "clang/Driver/Options.h"
-
-#include "llvm/ADT/StringMap.h"
-#include "llvm/Support/Compiler.h"
-
-#include "ToolChains.h"
-
-#include <cassert>
-
-using namespace clang::driver;
-
-HostInfo::HostInfo(const Driver &D, const llvm::Triple &_Triple)
-  : TheDriver(D), Triple(_Triple) {
-}
-
-HostInfo::~HostInfo() {
-}
-
-namespace {
-
-// Darwin Host Info
-
-/// DarwinHostInfo - Darwin host information implementation.
-class DarwinHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::DenseMap<unsigned, ToolChain*> ToolChains;
-
-public:
-  DarwinHostInfo(const Driver &D, const llvm::Triple &Triple);
-  ~DarwinHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-DarwinHostInfo::DarwinHostInfo(const Driver &D, const llvm::Triple& Triple)
-  : HostInfo(D, Triple) {
-}
-
-DarwinHostInfo::~DarwinHostInfo() {
-  for (llvm::DenseMap<unsigned, ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *DarwinHostInfo::CreateToolChain(const ArgList &Args,
-                                           const char *ArchName) const {
-  llvm::Triple::ArchType Arch;
-
-  if (!ArchName) {
-    // If we aren't looking for a specific arch, infer the default architecture
-    // based on -arch and -m32/-m64 command line options.
-    if (Arg *A = Args.getLastArg(options::OPT_arch)) {
-      // The gcc driver behavior with multiple -arch flags wasn't consistent for
-      // things which rely on a default architecture. We just use the last -arch
-      // to find the default tool chain (assuming it is valid).
-      Arch = llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args));
-
-      // If it was invalid just use the host, we will reject this command line
-      // later.
-      if (Arch == llvm::Triple::UnknownArch)
-        Arch = getTriple().getArch();
-    } else {
-      // Otherwise default to the arch of the host.
-      Arch = getTriple().getArch();
-    }
-
-    // Honor -m32 and -m64 when finding the default tool chain.
-    //
-    // FIXME: Should this information be in llvm::Triple?
-    if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
-      if (A->getOption().matches(options::OPT_m32)) {
-        if (Arch == llvm::Triple::x86_64)
-          Arch = llvm::Triple::x86;
-        if (Arch == llvm::Triple::ppc64)
-          Arch = llvm::Triple::ppc;
-      } else {
-        if (Arch == llvm::Triple::x86)
-          Arch = llvm::Triple::x86_64;
-        if (Arch == llvm::Triple::ppc)
-          Arch = llvm::Triple::ppc64;
-      }
-    }
-  } else
-    Arch = llvm::Triple::getArchTypeForDarwinArchName(ArchName);
-
-  assert(Arch != llvm::Triple::UnknownArch && "Unexpected arch!");
-  ToolChain *&TC = ToolChains[Arch];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArch(Arch);
-
-    // If we recognized the arch, match it to the toolchains we support.
-    if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64 ||
-        Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
-      TC = new toolchains::DarwinClang(getDriver(), TCTriple);
-    } else
-      TC = new toolchains::Darwin_Generic_GCC(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// TCE Host Info
-
-/// TCEHostInfo - TCE host information implementation (see http://tce.cs.tut.fi)
-class TCEHostInfo : public HostInfo {
-
-public:
-  TCEHostInfo(const Driver &D, const llvm::Triple &Triple);
-  ~TCEHostInfo() {}
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args, 
-                                     const char *ArchName) const;
-};
-
-TCEHostInfo::TCEHostInfo(const Driver &D, const llvm::Triple& Triple)
-  : HostInfo(D, Triple) {
-}
-
-ToolChain *TCEHostInfo::CreateToolChain(const ArgList &Args, 
-                                        const char *ArchName) const {
-  llvm::Triple TCTriple(getTriple());
-//  TCTriple.setArchName(ArchName);
-  return new toolchains::TCEToolChain(getDriver(), TCTriple);
-}
-
-
-// Unknown Host Info
-
-/// UnknownHostInfo - Generic host information to use for unknown hosts.
-class UnknownHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  UnknownHostInfo(const Driver &D, const llvm::Triple& Triple);
-  ~UnknownHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-UnknownHostInfo::UnknownHostInfo(const Driver &D, const llvm::Triple& Triple)
-  : HostInfo(D, Triple) {
-}
-
-UnknownHostInfo::~UnknownHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *UnknownHostInfo::CreateToolChain(const ArgList &Args,
-                                            const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver support.");
-
-  // Automatically handle some instances of -m32/-m64 we know about.
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
-    if (Triple.getArch() == llvm::Triple::x86 ||
-        Triple.getArch() == llvm::Triple::x86_64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
-    } else if (Triple.getArch() == llvm::Triple::ppc ||
-               Triple.getArch() == llvm::Triple::ppc64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
-    }
-  }
-
-  ToolChain *&TC = ToolChains[ArchName];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
-
-    TC = new toolchains::Generic_GCC(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// OpenBSD Host Info
-
-/// OpenBSDHostInfo -  OpenBSD host information implementation.
-class OpenBSDHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  OpenBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~OpenBSDHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-OpenBSDHostInfo::~OpenBSDHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *OpenBSDHostInfo::CreateToolChain(const ArgList &Args,
-                                            const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-
-  ToolChain *&TC = ToolChains[ArchName];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
-
-    TC = new toolchains::OpenBSD(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// AuroraUX Host Info
-
-/// AuroraUXHostInfo - AuroraUX host information implementation.
-class AuroraUXHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  AuroraUXHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~AuroraUXHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-AuroraUXHostInfo::~AuroraUXHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *AuroraUXHostInfo::CreateToolChain(const ArgList &Args,
-                                             const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  ToolChain *&TC = ToolChains[getArchName()];
-
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(getArchName());
-
-    TC = new toolchains::AuroraUX(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// FreeBSD Host Info
-
-/// FreeBSDHostInfo -  FreeBSD host information implementation.
-class FreeBSDHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  FreeBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~FreeBSDHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-FreeBSDHostInfo::~FreeBSDHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *FreeBSDHostInfo::CreateToolChain(const ArgList &Args,
-                                            const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  // Automatically handle some instances of -m32/-m64 we know about.
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
-    if (Triple.getArch() == llvm::Triple::x86 ||
-        Triple.getArch() == llvm::Triple::x86_64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
-    } else if (Triple.getArch() == llvm::Triple::ppc ||
-               Triple.getArch() == llvm::Triple::ppc64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
-    }
-  }
-
-  ToolChain *&TC = ToolChains[ArchName];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
-
-    TC = new toolchains::FreeBSD(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// NetBSD Host Info
-
-/// NetBSDHostInfo -  NetBSD host information implementation.
-class NetBSDHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  NetBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~NetBSDHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-NetBSDHostInfo::~NetBSDHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *NetBSDHostInfo::CreateToolChain(const ArgList &Args,
-                                            const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  // Automatically handle some instances of -m32/-m64 we know about.
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
-    if (Triple.getArch() == llvm::Triple::x86 ||
-        Triple.getArch() == llvm::Triple::x86_64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
-    } else if (Triple.getArch() == llvm::Triple::ppc ||
-               Triple.getArch() == llvm::Triple::ppc64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
-    }
-  }
-  llvm::Triple TargetTriple(getTriple());
-  TargetTriple.setArchName(ArchName);
-
-  ToolChain *TC;
-
-  // XXX Cache toolchain even if -m32 is used
-  if (Arch == ArchName) {
-    TC = ToolChains[ArchName];
-    if (TC)
-      return TC;
-  }
-
-  TC = new toolchains::NetBSD(getDriver(), TargetTriple, getTriple());
-
-  return TC;
-}
-
-// Minix Host Info
-
-/// MinixHostInfo -  Minix host information implementation.
-class MinixHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  MinixHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~MinixHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-MinixHostInfo::~MinixHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it){
-    delete it->second;
-  }
-}
-
-ToolChain *MinixHostInfo::CreateToolChain(const ArgList &Args,
-                                            const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-
-  ToolChain *&TC = ToolChains[ArchName];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
-
-    TC = new toolchains::Minix(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// DragonFly Host Info
-
-/// DragonFlyHostInfo -  DragonFly host information implementation.
-class DragonFlyHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  DragonFlyHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~DragonFlyHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-DragonFlyHostInfo::~DragonFlyHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *DragonFlyHostInfo::CreateToolChain(const ArgList &Args,
-                                              const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  ToolChain *&TC = ToolChains[getArchName()];
-
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(getArchName());
-
-    TC = new toolchains::DragonFly(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// Linux Host Info
-
-/// LinuxHostInfo -  Linux host information implementation.
-class LinuxHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  LinuxHostInfo(const Driver &D, const llvm::Triple& Triple)
-    : HostInfo(D, Triple) {}
-  ~LinuxHostInfo();
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-LinuxHostInfo::~LinuxHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *LinuxHostInfo::CreateToolChain(const ArgList &Args,
-                                          const char *ArchName) const {
-
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  // Automatically handle some instances of -m32/-m64 we know about.
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
-    if (Triple.getArch() == llvm::Triple::x86 ||
-        Triple.getArch() == llvm::Triple::x86_64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
-    } else if (Triple.getArch() == llvm::Triple::ppc ||
-               Triple.getArch() == llvm::Triple::ppc64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
-    }
-  }
-
-  ToolChain *&TC = ToolChains[ArchName];
-
-  if (!TC && !Arch.compare ("hexagon")) {
-    llvm::Triple TCTriple (getTriple());
-    TC = new toolchains::Hexagon_TC (getDriver(), TCTriple);
-  }
-
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
-
-    TC = new toolchains::Linux(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// Windows Host Info
-
-/// WindowsHostInfo - Host information to use on Microsoft Windows.
-class WindowsHostInfo : public HostInfo {
-  /// Cache of tool chains we have created.
-  mutable llvm::StringMap<ToolChain*> ToolChains;
-
-public:
-  WindowsHostInfo(const Driver &D, const llvm::Triple& Triple);
-  ~WindowsHostInfo();
-
-  virtual types::ID lookupTypeForExtension(const char *Ext) const {
-    return types::lookupTypeForExtension(Ext);
-  }
-
-  virtual ToolChain *CreateToolChain(const ArgList &Args,
-                                     const char *ArchName) const;
-};
-
-WindowsHostInfo::WindowsHostInfo(const Driver &D, const llvm::Triple& Triple)
-  : HostInfo(D, Triple) {
-}
-
-WindowsHostInfo::~WindowsHostInfo() {
-  for (llvm::StringMap<ToolChain*>::iterator
-         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
-    delete it->second;
-}
-
-ToolChain *WindowsHostInfo::CreateToolChain(const ArgList &Args,
-                                            const char *ArchName) const {
-  assert(!ArchName &&
-         "Unexpected arch name on platform without driver driver support.");
-
-  // Automatically handle some instances of -m32/-m64 we know about.
-  std::string Arch = getArchName();
-  ArchName = Arch.c_str();
-  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
-    if (Triple.getArch() == llvm::Triple::x86 ||
-        Triple.getArch() == llvm::Triple::x86_64) {
-      ArchName =
-        (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
-    }
-  }
-
-  ToolChain *&TC = ToolChains[ArchName];
-  if (!TC) {
-    llvm::Triple TCTriple(getTriple());
-    TCTriple.setArchName(ArchName);
-
-    TC = new toolchains::Windows(getDriver(), TCTriple);
-  }
-
-  return TC;
-}
-
-// FIXME: This is a placeholder.
-class MinGWHostInfo : public UnknownHostInfo {
-public:
-  MinGWHostInfo(const Driver &D, const llvm::Triple& Triple);
-};
-
-MinGWHostInfo::MinGWHostInfo(const Driver &D, const llvm::Triple& Triple)
-  : UnknownHostInfo(D, Triple) {}
-
-} // end anon namespace
-
-const HostInfo *
-clang::driver::createAuroraUXHostInfo(const Driver &D,
-                                      const llvm::Triple& Triple){
-  return new AuroraUXHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createDarwinHostInfo(const Driver &D,
-                                    const llvm::Triple& Triple){
-  return new DarwinHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createOpenBSDHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple) {
-  return new OpenBSDHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createFreeBSDHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple) {
-  return new FreeBSDHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createNetBSDHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple) {
-  return new NetBSDHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createMinixHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple) {
-  return new MinixHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createDragonFlyHostInfo(const Driver &D,
-                                       const llvm::Triple& Triple) {
-  return new DragonFlyHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createLinuxHostInfo(const Driver &D,
-                                   const llvm::Triple& Triple) {
-  return new LinuxHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createTCEHostInfo(const Driver &D,
-                                   const llvm::Triple& Triple) {
-  return new TCEHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createWindowsHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple) {
-  return new WindowsHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createMinGWHostInfo(const Driver &D,
-                                   const llvm::Triple& Triple) {
-  return new MinGWHostInfo(D, Triple);
-}
-
-const HostInfo *
-clang::driver::createUnknownHostInfo(const Driver &D,
-                                     const llvm::Triple& Triple) {
-  return new UnknownHostInfo(D, Triple);
-}

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=148950&r1=148949&r2=148950&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Jan 25 05:01:57 2012
@@ -16,7 +16,6 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Job.h"
-#include "clang/Driver/HostInfo.h"
 #include "clang/Driver/ObjCRuntime.h"
 #include "clang/Driver/Option.h"
 #include "clang/Driver/Options.h"





More information about the cfe-commits mailing list