Driver: Pass Driver reference down into Host info, which will need it

to pass to ToolChains, which may need Driver specific information (for
example, to form search paths).

llvm-svn: 67102
This commit is contained in:
Daniel Dunbar 2009-03-17 20:45:45 +00:00
parent 62ca7d23ce
commit 52e0c70868
4 changed files with 34 additions and 24 deletions

View File

@ -220,7 +220,7 @@ public:
/// GetHostInfo - Construct a new host info object for the given
/// host triple.
static const HostInfo *GetHostInfo(const char *HostTriple);
const HostInfo *GetHostInfo(const char *HostTriple) const;
/// @}
};

View File

@ -15,6 +15,7 @@
namespace clang {
namespace driver {
class ArgList;
class Driver;
class ToolChain;
/// HostInfo - Config information about a particular host which may
@ -25,14 +26,17 @@ namespace driver {
/// being run from. For testing purposes, the HostInfo used by the
/// driver may differ from the actual host.
class HostInfo {
const Driver &TheDriver;
std::string Arch, Platform, OS;
protected:
HostInfo(const char *Arch, const char *Platform, const char *OS);
HostInfo(const Driver &D, const char *Arch,
const char *Platform, const char *OS);
public:
virtual ~HostInfo();
const Driver &getDriver() const { return TheDriver; }
const std::string &getArchName() const { return Arch; }
const std::string &getPlatformName() const { return Platform; }
const std::string &getOSName() const { return OS; }
@ -56,10 +60,10 @@ public:
const char *ArchName=0) const = 0;
};
const HostInfo *createDarwinHostInfo(const char *Arch, const char *Platform,
const char *OS);
const HostInfo *createUnknownHostInfo(const char *Arch, const char *Platform,
const char *OS);
const HostInfo *createDarwinHostInfo(const Driver &D, const char *Arch,
const char *Platform, const char *OS);
const HostInfo *createUnknownHostInfo(const Driver &D, const char *Arch,
const char *Platform, const char *OS);
} // end namespace driver
} // end namespace clang

View File

@ -154,7 +154,7 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
ArgList *Args = ParseArgStrings(Start, End);
Host = Driver::GetHostInfo(HostTriple);
Host = GetHostInfo(HostTriple);
DefaultToolChain = Host->getToolChain(*Args);
// FIXME: This behavior shouldn't be here.
@ -816,7 +816,7 @@ llvm::sys::Path Driver::GetProgramPath(const char *Name,
return llvm::sys::Path(Name);
}
const HostInfo *Driver::GetHostInfo(const char *Triple) {
const HostInfo *Driver::GetHostInfo(const char *Triple) const {
// Dice into arch, platform, and OS. This matches
// arch,platform,os = '(.*?)-(.*?)-(.*?)'
// and missing fields are left empty.
@ -842,7 +842,9 @@ const HostInfo *Driver::GetHostInfo(const char *Triple) {
Arch = "x86_64";
if (memcmp(&OS[0], "darwin", 6) == 0)
return createDarwinHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str());
return createDarwinHostInfo(*this, Arch.c_str(), Platform.c_str(),
OS.c_str());
return createUnknownHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str());
return createUnknownHostInfo(*this, Arch.c_str(), Platform.c_str(),
OS.c_str());
}

View File

@ -21,9 +21,9 @@
using namespace clang::driver;
HostInfo::HostInfo(const char *_Arch, const char *_Platform,
HostInfo::HostInfo(const Driver &D, const char *_Arch, const char *_Platform,
const char *_OS)
: Arch(_Arch), Platform(_Platform), OS(_OS)
: TheDriver(D), Arch(_Arch), Platform(_Platform), OS(_OS)
{
}
@ -47,7 +47,8 @@ class DarwinHostInfo : public HostInfo {
mutable llvm::StringMap<ToolChain*> ToolChains;
public:
DarwinHostInfo(const char *Arch, const char *Platform, const char *OS);
DarwinHostInfo(const Driver &D, const char *Arch,
const char *Platform, const char *OS);
virtual bool useDriverDriver() const;
@ -55,9 +56,9 @@ public:
const char *ArchName) const;
};
DarwinHostInfo::DarwinHostInfo(const char *_Arch, const char *_Platform,
const char *_OS)
: HostInfo(_Arch, _Platform, _OS) {
DarwinHostInfo::DarwinHostInfo(const Driver &D, const char *_Arch,
const char *_Platform, const char *_OS)
: HostInfo(D, _Arch, _Platform, _OS) {
assert((getArchName() == "i386" || getArchName() == "x86_64" ||
getArchName() == "ppc" || getArchName() == "ppc64") &&
@ -118,7 +119,8 @@ class UnknownHostInfo : public HostInfo {
mutable llvm::StringMap<ToolChain*> ToolChains;
public:
UnknownHostInfo(const char *Arch, const char *Platform, const char *OS);
UnknownHostInfo(const Driver &D, const char *Arch,
const char *Platform, const char *OS);
virtual bool useDriverDriver() const;
@ -126,9 +128,9 @@ public:
const char *ArchName) const;
};
UnknownHostInfo::UnknownHostInfo(const char *Arch, const char *Platform,
const char *OS)
: HostInfo(Arch, Platform, OS) {
UnknownHostInfo::UnknownHostInfo(const Driver &D, const char *Arch,
const char *Platform, const char *OS)
: HostInfo(D, Arch, Platform, OS) {
}
bool UnknownHostInfo::useDriverDriver() const {
@ -161,14 +163,16 @@ ToolChain *UnknownHostInfo::getToolChain(const ArgList &Args,
}
const HostInfo *clang::driver::createDarwinHostInfo(const char *Arch,
const HostInfo *clang::driver::createDarwinHostInfo(const Driver &D,
const char *Arch,
const char *Platform,
const char *OS) {
return new DarwinHostInfo(Arch, Platform, OS);
return new DarwinHostInfo(D, Arch, Platform, OS);
}
const HostInfo *clang::driver::createUnknownHostInfo(const char *Arch,
const HostInfo *clang::driver::createUnknownHostInfo(const Driver &D,
const char *Arch,
const char *Platform,
const char *OS) {
return new UnknownHostInfo(Arch, Platform, OS);
return new UnknownHostInfo(D, Arch, Platform, OS);
}