From 25b58eb7998ed947bc1c07e70de0b5d8f6aff857 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 2 Aug 2010 05:44:07 +0000 Subject: [PATCH] Driver/Darwin: Change where Darwin computes the host version, to normalize tool chain construction. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110028 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/HostInfo.cpp | 16 ++-------------- lib/Driver/ToolChains.cpp | 25 +++++++++++++++---------- lib/Driver/ToolChains.h | 14 ++++++++------ 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 4bd1e5a026..62358f84a5 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -38,9 +38,6 @@ namespace { /// DarwinHostInfo - Darwin host information implementation. class DarwinHostInfo : public HostInfo { - /// Darwin version of host. - unsigned DarwinVersion[3]; - /// Cache of tool chains we have created. mutable llvm::DenseMap ToolChains; @@ -56,15 +53,6 @@ public: DarwinHostInfo::DarwinHostInfo(const Driver &D, const llvm::Triple& Triple) : HostInfo(D, Triple) { - - assert(Triple.getArch() != llvm::Triple::UnknownArch && "Invalid arch!"); - assert(memcmp(&getOSName()[0], "darwin", 6) == 0 && - "Unknown Darwin platform."); - bool HadExtra; - if (!Driver::GetReleaseVersion(&getOSName()[6], - DarwinVersion[0], DarwinVersion[1], - DarwinVersion[2], HadExtra)) - D.Diag(clang::diag::err_drv_invalid_darwin_version) << getOSName(); } DarwinHostInfo::~DarwinHostInfo() { @@ -128,10 +116,10 @@ ToolChain *DarwinHostInfo::CreateToolChain(const ArgList &Args, const char *UseNewToolChain = ::getenv("CCC_ENABLE_NEW_DARWIN_TOOLCHAIN"); if (UseNewToolChain || Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) { - TC = new toolchains::DarwinClang(*this, TCTriple, DarwinVersion); + TC = new toolchains::DarwinClang(*this, TCTriple); } else if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) { // We still use the legacy DarwinGCC toolchain on X86. - TC = new toolchains::DarwinGCC(*this, TCTriple, DarwinVersion); + TC = new toolchains::DarwinGCC(*this, TCTriple); } else TC = new toolchains::Darwin_Generic_GCC(*this, TCTriple); } diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 1684fa9424..1099b6513e 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -31,13 +31,20 @@ using namespace clang::driver::toolchains; /// Darwin - Darwin tool chain for i386 and x86_64. -Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple, - const unsigned (&_DarwinVersion)[3]) +Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple) : ToolChain(Host, Triple), TargetInitialized(false) { + // Compute the initial Darwin version based on the host. + bool HadExtra; + std::string OSName = Triple.getOSName(); + if (!Driver::GetReleaseVersion(&OSName[6], + DarwinVersion[0], DarwinVersion[1], + DarwinVersion[2], HadExtra)) + getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName; + llvm::raw_string_ostream(MacosxVersionMin) - << "10." << std::max(0, (int)_DarwinVersion[0] - 4) << '.' - << _DarwinVersion[1]; + << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.' + << DarwinVersion[1]; } types::ID Darwin::LookupTypeForExtension(const char *Ext) const { @@ -113,9 +120,8 @@ llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const { } } -DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, - const unsigned (&DarwinVersion)[3]) - : Darwin(Host, Triple, DarwinVersion) +DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple) + : Darwin(Host, Triple) { // We can only work with 4.2.1 currently. GCCVersion[0] = 4; @@ -326,9 +332,8 @@ void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, } } -DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, - const unsigned (&DarwinVersion)[3]) - : Darwin(Host, Triple, DarwinVersion) +DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple) + : Darwin(Host, Triple) { // We expect 'as', 'ld', etc. to be adjacent to our install dir. getProgramPaths().push_back(getDriver().getInstalledDir()); diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index be96c97dbb..700d5fd6c2 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -42,6 +42,11 @@ public: /// Darwin - The base Darwin tool chain. class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { +public: + /// The host version. + unsigned DarwinVersion[3]; + +private: mutable llvm::DenseMap Tools; /// Whether the information on the target has been initialized. @@ -65,8 +70,7 @@ private: void AddDeploymentTarget(DerivedArgList &Args) const; public: - Darwin(const HostInfo &Host, const llvm::Triple& Triple, - const unsigned (&DarwinVersion)[3]); + Darwin(const HostInfo &Host, const llvm::Triple& Triple); ~Darwin(); /// @name Darwin Specific Toolchain API @@ -204,8 +208,7 @@ public: /// DarwinClang - The Darwin toolchain used by Clang. class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin { public: - DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, - const unsigned (&DarwinVersion)[3]); + DarwinClang(const HostInfo &Host, const llvm::Triple& Triple); /// @name Darwin ToolChain Implementation /// { @@ -228,8 +231,7 @@ class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin { std::string ToolChainDir; public: - DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, - const unsigned (&DarwinVersion)[3]); + DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple); /// @name Darwin ToolChain Implementation /// { -- 2.40.0