[cfe-commits] r67091 - in /cfe/trunk: include/clang/Driver/Driver.h include/clang/Driver/HostInfo.h lib/Driver/Driver.cpp lib/Driver/HostInfo.cpp
Daniel Dunbar
daniel at zuster.org
Tue Mar 17 12:01:09 PDT 2009
Author: ddunbar
Date: Tue Mar 17 14:00:50 2009
New Revision: 67091
URL: http://llvm.org/viewvc/llvm-project?rev=67091&view=rev
Log:
Driver: Hide HostInfo implementations.
- Also, normalize arch names a tad and stub out getToolChain
implementations.
Modified:
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/include/clang/Driver/HostInfo.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/HostInfo.cpp
Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=67091&r1=67090&r2=67091&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Tue Mar 17 14:00:50 2009
@@ -62,7 +62,7 @@
/// 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 @@
/// 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);
/// @}
};
Modified: cfe/trunk/include/clang/Driver/HostInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/HostInfo.h?rev=67091&r1=67090&r2=67091&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/HostInfo.h (original)
+++ cfe/trunk/include/clang/Driver/HostInfo.h Tue Mar 17 14:00:50 2009
@@ -49,38 +49,17 @@
/// \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
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=67091&r1=67090&r2=67091&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 17 14:00:50 2009
@@ -816,7 +816,7 @@
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 @@
} 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());
}
Modified: cfe/trunk/lib/Driver/HostInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/HostInfo.cpp?rev=67091&r1=67090&r2=67091&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/HostInfo.cpp (original)
+++ cfe/trunk/lib/Driver/HostInfo.cpp Tue Mar 17 14:00:50 2009
@@ -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 <cassert>
using namespace clang::driver;
@@ -21,11 +31,37 @@
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<ToolChain*> 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 @@
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<ToolChain*> 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 @@
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);
+}
More information about the cfe-commits
mailing list