r297312 - Driver/ToolChains: Mips -> MipsLinux

Konstantin Zhuravlyov via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 8 14:36:05 PST 2017


Author: kzhuravl
Date: Wed Mar  8 16:36:04 2017
New Revision: 297312

URL: http://llvm.org/viewvc/llvm-project?rev=297312&view=rev
Log:
Driver/ToolChains: Mips -> MipsLinux
  - Mips is architecture, not a toolchain
  - Might help eliminate the confusion in the future by not having header files with the same name

Differential Revision: https://reviews.llvm.org/D30753

Added:
    cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp
    cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
Removed:
    cfe/trunk/lib/Driver/ToolChains/Mips.cpp
    cfe/trunk/lib/Driver/ToolChains/Mips.h
Modified:
    cfe/trunk/lib/Driver/CMakeLists.txt
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CMakeLists.txt?rev=297312&r1=297311&r2=297312&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/CMakeLists.txt (original)
+++ cfe/trunk/lib/Driver/CMakeLists.txt Wed Mar  8 16:36:04 2017
@@ -44,7 +44,7 @@ add_clang_library(clangDriver
   ToolChains/Haiku.cpp
   ToolChains/Hexagon.cpp
   ToolChains/Linux.cpp
-  ToolChains/Mips.cpp
+  ToolChains/MipsLinux.cpp
   ToolChains/MinGW.cpp
   ToolChains/Minix.cpp
   ToolChains/MSVC.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=297312&r1=297311&r2=297312&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Mar  8 16:36:04 2017
@@ -28,7 +28,7 @@
 #include "ToolChains/Linux.h"
 #include "ToolChains/MinGW.h"
 #include "ToolChains/Minix.h"
-#include "ToolChains/Mips.h"
+#include "ToolChains/MipsLinux.h"
 #include "ToolChains/MSVC.h"
 #include "ToolChains/Myriad.h"
 #include "ToolChains/NaCl.h"

Removed: cfe/trunk/lib/Driver/ToolChains/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Mips.cpp?rev=297311&view=auto
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Mips.cpp (removed)
@@ -1,128 +0,0 @@
-//===--- Mips.cpp - Mips ToolChain Implementations --------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Mips.h"
-#include "Arch/Mips.h"
-#include "CommonArgs.h"
-#include "clang/Config/config.h"
-#include "clang/Driver/Driver.h"
-#include "clang/Driver/DriverDiagnostic.h"
-#include "clang/Driver/Options.h"
-#include "llvm/Option/ArgList.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
-
-using namespace clang::driver;
-using namespace clang::driver::toolchains;
-using namespace clang;
-using namespace llvm::opt;
-
-/// Mips Toolchain
-MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D,
-                                     const llvm::Triple &Triple,
-                                     const ArgList &Args)
-    : Linux(D, Triple, Args) {
-  // Select the correct multilib according to the given arguments.
-  DetectedMultilibs Result;
-  findMIPSMultilibs(D, Triple, "", Args, Result);
-  Multilibs = Result.Multilibs;
-  SelectedMultilib = Result.SelectedMultilib;
-
-  // Find out the library suffix based on the ABI.
-  LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
-  getFilePaths().clear();
-  getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
-}
-
-void MipsLLVMToolChain::AddClangSystemIncludeArgs(
-    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
-  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
-    return;
-
-  const Driver &D = getDriver();
-
-  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
-    SmallString<128> P(D.ResourceDir);
-    llvm::sys::path::append(P, "include");
-    addSystemInclude(DriverArgs, CC1Args, P);
-  }
-
-  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
-    return;
-
-  const auto &Callback = Multilibs.includeDirsCallback();
-  if (Callback) {
-    for (const auto &Path : Callback(SelectedMultilib))
-      addExternCSystemIncludeIfExists(DriverArgs, CC1Args,
-                                      D.getInstalledDir() + Path);
-  }
-}
-
-Tool *MipsLLVMToolChain::buildLinker() const {
-  return new tools::gnutools::Linker(*this);
-}
-
-std::string MipsLLVMToolChain::computeSysRoot() const {
-  if (!getDriver().SysRoot.empty())
-    return getDriver().SysRoot + SelectedMultilib.osSuffix();
-
-  const std::string InstalledDir(getDriver().getInstalledDir());
-  std::string SysRootPath =
-      InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix();
-  if (llvm::sys::fs::exists(SysRootPath))
-    return SysRootPath;
-
-  return std::string();
-}
-
-ToolChain::CXXStdlibType
-MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const {
-  Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
-  if (A) {
-    StringRef Value = A->getValue();
-    if (Value != "libc++")
-      getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name)
-          << A->getAsString(Args);
-  }
-
-  return ToolChain::CST_Libcxx;
-}
-
-std::string MipsLLVMToolChain::findLibCxxIncludePath() const {
-  if (const auto &Callback = Multilibs.includeDirsCallback()) {
-    for (std::string Path : Callback(SelectedMultilib)) {
-      Path = getDriver().getInstalledDir() + Path + "/c++/v1";
-      if (llvm::sys::fs::exists(Path)) {
-        return Path;
-      }
-    }
-  }
-  return "";
-}
-
-void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
-                                            ArgStringList &CmdArgs) const {
-  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
-         "Only -lc++ (aka libxx) is suported in this toolchain.");
-
-  CmdArgs.push_back("-lc++");
-  CmdArgs.push_back("-lc++abi");
-  CmdArgs.push_back("-lunwind");
-}
-
-std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
-                                             StringRef Component,
-                                             bool Shared) const {
-  SmallString<128> Path(getDriver().ResourceDir);
-  llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix,
-                          getOS());
-  llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" +
-                                      "mips" + (Shared ? ".so" : ".a")));
-  return Path.str();
-}

Removed: cfe/trunk/lib/Driver/ToolChains/Mips.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Mips.h?rev=297311&view=auto
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Mips.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Mips.h (removed)
@@ -1,62 +0,0 @@
-//===--- Mips.h - Mips ToolChain Implementations ----------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MIPS_H
-#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MIPS_H
-
-#include "Linux.h"
-#include "clang/Driver/ToolChain.h"
-
-namespace clang {
-namespace driver {
-namespace toolchains {
-
-class LLVM_LIBRARY_VISIBILITY MipsLLVMToolChain : public Linux {
-protected:
-  Tool *buildLinker() const override;
-
-public:
-  MipsLLVMToolChain(const Driver &D, const llvm::Triple &Triple,
-                    const llvm::opt::ArgList &Args);
-
-  void
-  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
-                            llvm::opt::ArgStringList &CC1Args) const override;
-
-  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
-
-  std::string findLibCxxIncludePath() const override;
-
-  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
-                           llvm::opt::ArgStringList &CmdArgs) const override;
-
-  std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
-                            bool Shared = false) const override;
-
-  std::string computeSysRoot() const override;
-
-  RuntimeLibType GetDefaultRuntimeLibType() const override {
-    return GCCInstallation.isValid() ? RuntimeLibType::RLT_Libgcc
-                                     : RuntimeLibType::RLT_CompilerRT;
-  }
-
-  const char *getDefaultLinker() const override {
-    return "lld";
-  }
-
-private:
-  Multilib SelectedMultilib;
-  std::string LibSuffix;
-};
-
-} // end namespace toolchains
-} // end namespace driver
-} // end namespace clang
-
-#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MIPS_H

Added: cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp?rev=297312&view=auto
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp (added)
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp Wed Mar  8 16:36:04 2017
@@ -0,0 +1,128 @@
+//===--- Mips.cpp - Mips ToolChain Implementations --------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "MipsLinux.h"
+#include "Arch/Mips.h"
+#include "CommonArgs.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/Options.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+/// Mips Toolchain
+MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D,
+                                     const llvm::Triple &Triple,
+                                     const ArgList &Args)
+    : Linux(D, Triple, Args) {
+  // Select the correct multilib according to the given arguments.
+  DetectedMultilibs Result;
+  findMIPSMultilibs(D, Triple, "", Args, Result);
+  Multilibs = Result.Multilibs;
+  SelectedMultilib = Result.SelectedMultilib;
+
+  // Find out the library suffix based on the ABI.
+  LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
+  getFilePaths().clear();
+  getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
+}
+
+void MipsLLVMToolChain::AddClangSystemIncludeArgs(
+    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+    return;
+
+  const Driver &D = getDriver();
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+    SmallString<128> P(D.ResourceDir);
+    llvm::sys::path::append(P, "include");
+    addSystemInclude(DriverArgs, CC1Args, P);
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+    return;
+
+  const auto &Callback = Multilibs.includeDirsCallback();
+  if (Callback) {
+    for (const auto &Path : Callback(SelectedMultilib))
+      addExternCSystemIncludeIfExists(DriverArgs, CC1Args,
+                                      D.getInstalledDir() + Path);
+  }
+}
+
+Tool *MipsLLVMToolChain::buildLinker() const {
+  return new tools::gnutools::Linker(*this);
+}
+
+std::string MipsLLVMToolChain::computeSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+    return getDriver().SysRoot + SelectedMultilib.osSuffix();
+
+  const std::string InstalledDir(getDriver().getInstalledDir());
+  std::string SysRootPath =
+      InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix();
+  if (llvm::sys::fs::exists(SysRootPath))
+    return SysRootPath;
+
+  return std::string();
+}
+
+ToolChain::CXXStdlibType
+MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const {
+  Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
+  if (A) {
+    StringRef Value = A->getValue();
+    if (Value != "libc++")
+      getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name)
+          << A->getAsString(Args);
+  }
+
+  return ToolChain::CST_Libcxx;
+}
+
+std::string MipsLLVMToolChain::findLibCxxIncludePath() const {
+  if (const auto &Callback = Multilibs.includeDirsCallback()) {
+    for (std::string Path : Callback(SelectedMultilib)) {
+      Path = getDriver().getInstalledDir() + Path + "/c++/v1";
+      if (llvm::sys::fs::exists(Path)) {
+        return Path;
+      }
+    }
+  }
+  return "";
+}
+
+void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
+                                            ArgStringList &CmdArgs) const {
+  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
+         "Only -lc++ (aka libxx) is suported in this toolchain.");
+
+  CmdArgs.push_back("-lc++");
+  CmdArgs.push_back("-lc++abi");
+  CmdArgs.push_back("-lunwind");
+}
+
+std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
+                                             StringRef Component,
+                                             bool Shared) const {
+  SmallString<128> Path(getDriver().ResourceDir);
+  llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix,
+                          getOS());
+  llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" +
+                                      "mips" + (Shared ? ".so" : ".a")));
+  return Path.str();
+}

Added: cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MipsLinux.h?rev=297312&view=auto
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.h (added)
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.h Wed Mar  8 16:36:04 2017
@@ -0,0 +1,62 @@
+//===--- Mips.h - Mips ToolChain Implementations ----------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MIPS_LINUX_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MIPS_LINUX_H
+
+#include "Linux.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY MipsLLVMToolChain : public Linux {
+protected:
+  Tool *buildLinker() const override;
+
+public:
+  MipsLLVMToolChain(const Driver &D, const llvm::Triple &Triple,
+                    const llvm::opt::ArgList &Args);
+
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+                            llvm::opt::ArgStringList &CC1Args) const override;
+
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
+
+  std::string findLibCxxIncludePath() const override;
+
+  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
+                           llvm::opt::ArgStringList &CmdArgs) const override;
+
+  std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
+                            bool Shared = false) const override;
+
+  std::string computeSysRoot() const override;
+
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+    return GCCInstallation.isValid() ? RuntimeLibType::RLT_Libgcc
+                                     : RuntimeLibType::RLT_CompilerRT;
+  }
+
+  const char *getDefaultLinker() const override {
+    return "lld";
+  }
+
+private:
+  Multilib SelectedMultilib;
+  std::string LibSuffix;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MIPS_LINUX_H




More information about the cfe-commits mailing list