From 1fd6c4b8abbbdcbae0e221f35100102112dabff2 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 17 Mar 2009 19:00:50 +0000 Subject: [PATCH] Driver: Hide HostInfo implementations. - Also, normalize arch names a tad and stub out getToolChain implementations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67091 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Driver.h | 4 +- include/clang/Driver/HostInfo.h | 35 ++------- lib/Driver/Driver.cpp | 14 +++- lib/Driver/HostInfo.cpp | 123 ++++++++++++++++++++++++++++++-- 4 files changed, 138 insertions(+), 38 deletions(-) diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 7bc83ae500..bf95325757 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -62,7 +62,7 @@ public: /// Host information for the platform the driver is running as. This /// will generally be the actual host platform, but not always. - HostInfo *Host; + const HostInfo *Host; /// The default tool chain for this host. // FIXME: This shouldn't be here; this should be in a @@ -220,7 +220,7 @@ public: /// GetHostInfo - Construct a new host info object for the given /// host triple. - static HostInfo *GetHostInfo(const char *HostTriple); + static const HostInfo *GetHostInfo(const char *HostTriple); /// @} }; diff --git a/include/clang/Driver/HostInfo.h b/include/clang/Driver/HostInfo.h index 0f9b728d5c..dfa3f75f89 100644 --- a/include/clang/Driver/HostInfo.h +++ b/include/clang/Driver/HostInfo.h @@ -49,38 +49,17 @@ public: /// \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. - virtual ToolChain *getToolChain(const ArgList &Args, - const char *ArchName=0) const = 0; -}; - -/// DarwinHostInfo - Darwin host information implementation. -class DarwinHostInfo : public HostInfo { - /// Darwin version of host. - unsigned DarwinVersion[3]; - - /// GCC version to use on this host. - unsigned GCCVersion[3]; - -public: - DarwinHostInfo(const char *Arch, const char *Platform, const char *OS); - - virtual bool useDriverDriver() const; + // FIXME: Pin down exactly what the HostInfo is allowed to use Args + // for here. Currently this is for -m32 / -m64 defaulting. virtual ToolChain *getToolChain(const ArgList &Args, - const char *ArchName) const; + const char *ArchName=0) const = 0; }; -/// UnknownHostInfo - Generic host information to use for unknown -/// hosts. -class UnknownHostInfo : public HostInfo { -public: - UnknownHostInfo(const char *Arch, const char *Platform, const char *OS); - - virtual bool useDriverDriver() const; - - virtual ToolChain *getToolChain(const ArgList &Args, - const char *ArchName) const; -}; +const HostInfo *createDarwinHostInfo(const char *Arch, const char *Platform, + const char *OS); +const HostInfo *createUnknownHostInfo(const char *Arch, const char *Platform, + const char *OS); } // end namespace driver } // end namespace clang diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 726823b48c..0da441f152 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -816,7 +816,7 @@ llvm::sys::Path Driver::GetProgramPath(const char *Name, return llvm::sys::Path(Name); } -HostInfo *Driver::GetHostInfo(const char *Triple) { +const HostInfo *Driver::GetHostInfo(const char *Triple) { // Dice into arch, platform, and OS. This matches // arch,platform,os = '(.*?)-(.*?)-(.*?)' // and missing fields are left empty. @@ -833,8 +833,16 @@ HostInfo *Driver::GetHostInfo(const char *Triple) { } else Arch = Triple; + // Normalize Arch a bit. + // + // FIXME: This is very incomplete. + if (Arch == "i686") + Arch = "i386"; + else if (Arch == "amd64") + Arch = "x86_64"; + if (memcmp(&OS[0], "darwin", 6) == 0) - return new DarwinHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str()); + return createDarwinHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str()); - return new UnknownHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str()); + return createUnknownHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str()); } diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 3ae0c38d39..5069bda3ed 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -8,6 +8,16 @@ //===----------------------------------------------------------------------===// #include "clang/Driver/HostInfo.h" + +#include "clang/Driver/Arg.h" +#include "clang/Driver/ArgList.h" +#include "clang/Driver/Option.h" +#include "clang/Driver/Options.h" + +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/Compiler.h" + +#include using namespace clang::driver; @@ -21,11 +31,37 @@ HostInfo::HostInfo(const char *_Arch, const char *_Platform, HostInfo::~HostInfo() { } +namespace VISIBILITY_HIDDEN { + // Darwin Host Info -DarwinHostInfo::DarwinHostInfo(const char *Arch, const char *Platform, - const char *OS) - : HostInfo(Arch, Platform, OS) { +/// DarwinHostInfo - Darwin host information implementation. +class DarwinHostInfo : public HostInfo { + /// Darwin version of host. + unsigned DarwinVersion[3]; + + /// GCC version to use on this host. + unsigned GCCVersion[3]; + + /// Cache of tool chains we have created. + mutable llvm::StringMap ToolChains; + +public: + DarwinHostInfo(const char *Arch, const char *Platform, const char *OS); + + virtual bool useDriverDriver() const; + + virtual ToolChain *getToolChain(const ArgList &Args, + const char *ArchName) const; +}; + +DarwinHostInfo::DarwinHostInfo(const char *_Arch, const char *_Platform, + const char *_OS) + : HostInfo(_Arch, _Platform, _OS) { + + assert((getArchName() == "i386" || getArchName() == "x86_64" || + getArchName() == "ppc" || getArchName() == "ppc64") && + "Unknown Darwin arch."); // FIXME: How to deal with errors? @@ -41,13 +77,57 @@ bool DarwinHostInfo::useDriverDriver() const { ToolChain *DarwinHostInfo::getToolChain(const ArgList &Args, const char *ArchName) const { - return 0; + if (!ArchName) { + ArchName = getArchName().c_str(); + + // If no arch name is specified, infer it from the host and + // -m32/-m64. + if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) { + if (getArchName() == "i386" || getArchName() == "x86_64") { + ArchName = + (A->getOption().getId() == options::OPT_m32) ? "i386" : "x86_64"; + } else if (getArchName() == "ppc" || getArchName() == "ppc64") { + ArchName = + (A->getOption().getId() == options::OPT_m32) ? "ppc" : "ppc64"; + } + } + } + + ToolChain *&TC = ToolChains[ArchName]; + if (!TC) { + TC = 0; +#if 0 + if (ArchName == "i386") + TC = new Darwin_X86_ToolChain(ArchName); + else if (ArchName == "x86_64") + TC = new Darwin_X86_ToolChain(ArchName); + else + TC = new Darwin_GCC_ToolChain(ArchName); +#endif + } + + return TC; } // 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 ToolChains; + +public: + UnknownHostInfo(const char *Arch, const char *Platform, const char *OS); + + virtual bool useDriverDriver() const; + + virtual ToolChain *getToolChain(const ArgList &Args, + const char *ArchName) const; +}; + UnknownHostInfo::UnknownHostInfo(const char *Arch, const char *Platform, - const char *OS) + const char *OS) : HostInfo(Arch, Platform, OS) { } @@ -57,5 +137,38 @@ bool UnknownHostInfo::useDriverDriver() const { ToolChain *UnknownHostInfo::getToolChain(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. + ArchName = getArchName().c_str(); + if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) { + if (getArchName() == "i386" || getArchName() == "x86_64") { + ArchName = + (A->getOption().getId() == options::OPT_m32) ? "i386" : "x86_64"; + } else if (getArchName() == "ppc" || getArchName() == "ppc64") { + ArchName = + (A->getOption().getId() == options::OPT_m32) ? "ppc" : "ppc64"; + } + } + + ToolChain *&TC = ToolChains[ArchName]; + if (!TC) + TC = 0; //new Generic_GCC_ToolChain(ArchName); + return 0; } + +} + +const HostInfo *clang::driver::createDarwinHostInfo(const char *Arch, + const char *Platform, + const char *OS) { + return new DarwinHostInfo(Arch, Platform, OS); +} + +const HostInfo *clang::driver::createUnknownHostInfo(const char *Arch, + const char *Platform, + const char *OS) { + return new UnknownHostInfo(Arch, Platform, OS); +} -- 2.40.0