Driver: Add host info.
- Replace assorted -ccc-host-* options by -ccc-host-triple which is more sane. llvm-svn: 66600
This commit is contained in:
parent
d8c7ba278e
commit
4dff6a4973
|
@ -38,6 +38,9 @@ public:
|
||||||
/// The path the driver executable was in, as invoked from the
|
/// The path the driver executable was in, as invoked from the
|
||||||
/// command line.
|
/// command line.
|
||||||
std::string Dir;
|
std::string Dir;
|
||||||
|
|
||||||
|
/// Default host triple.
|
||||||
|
std::string DefaultHostTriple;
|
||||||
|
|
||||||
/// Host information for the platform the driver is running as. This
|
/// Host information for the platform the driver is running as. This
|
||||||
/// will generally be the actual host platform, but not always.
|
/// will generally be the actual host platform, but not always.
|
||||||
|
@ -73,7 +76,8 @@ public:
|
||||||
std::list<std::string> ResultFiles;
|
std::list<std::string> ResultFiles;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Driver(const char *_Name, const char *_Dir);
|
Driver(const char *_Name, const char *_Dir,
|
||||||
|
const char *_DefaultHostTriple);
|
||||||
~Driver();
|
~Driver();
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,6 +89,10 @@ public:
|
||||||
|
|
||||||
/// PrintOptions - Print the given list of arguments.
|
/// PrintOptions - Print the given list of arguments.
|
||||||
void PrintOptions(const ArgList *Args);
|
void PrintOptions(const ArgList *Args);
|
||||||
|
|
||||||
|
/// GetHostInfo - Construct a new host info object for the given
|
||||||
|
/// host triple.
|
||||||
|
static HostInfo *GetHostInfo(const char *HostTriple);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace driver
|
} // end namespace driver
|
||||||
|
|
|
@ -12,15 +12,18 @@
|
||||||
#include "clang/Driver/Arg.h"
|
#include "clang/Driver/Arg.h"
|
||||||
#include "clang/Driver/ArgList.h"
|
#include "clang/Driver/ArgList.h"
|
||||||
#include "clang/Driver/Compilation.h"
|
#include "clang/Driver/Compilation.h"
|
||||||
|
#include "clang/Driver/HostInfo.h"
|
||||||
#include "clang/Driver/Option.h"
|
#include "clang/Driver/Option.h"
|
||||||
#include "clang/Driver/Options.h"
|
#include "clang/Driver/Options.h"
|
||||||
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace clang::driver;
|
using namespace clang::driver;
|
||||||
|
|
||||||
Driver::Driver(const char *_Name, const char *_Dir)
|
Driver::Driver(const char *_Name, const char *_Dir,
|
||||||
|
const char *_DefaultHostTriple)
|
||||||
: Opts(new OptTable()),
|
: Opts(new OptTable()),
|
||||||
Name(_Name), Dir(_Dir), Host(0),
|
Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple),
|
||||||
|
Host(0),
|
||||||
CCCIsCXX(false), CCCEcho(false),
|
CCCIsCXX(false), CCCEcho(false),
|
||||||
CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false)
|
CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false)
|
||||||
{
|
{
|
||||||
|
@ -53,6 +56,7 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
|
||||||
bool CCCPrintOptions = false, CCCPrintPhases = false;
|
bool CCCPrintOptions = false, CCCPrintPhases = false;
|
||||||
|
|
||||||
const char **Start = argv + 1, **End = argv + argc;
|
const char **Start = argv + 1, **End = argv + argc;
|
||||||
|
const char *HostTriple = DefaultHostTriple.c_str();
|
||||||
|
|
||||||
// Read -ccc args.
|
// Read -ccc args.
|
||||||
//
|
//
|
||||||
|
@ -94,18 +98,9 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!strcmp(Opt, "host-bits")) {
|
} else if (!strcmp(Opt, "host-triple")) {
|
||||||
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
|
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
|
||||||
HostBits = *++Start;
|
HostTriple = *++Start;
|
||||||
} else if (!strcmp(Opt, "host-machine")) {
|
|
||||||
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
|
|
||||||
HostMachine = *++Start;
|
|
||||||
} else if (!strcmp(Opt, "host-release")) {
|
|
||||||
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
|
|
||||||
HostRelease = *++Start;
|
|
||||||
} else if (!strcmp(Opt, "host-system")) {
|
|
||||||
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
|
|
||||||
HostSystem = *++Start;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Error handling.
|
// FIXME: Error handling.
|
||||||
|
@ -113,7 +108,9 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Host = Driver::GetHostInfo(HostTriple);
|
||||||
|
|
||||||
ArgList *Args = ParseArgStrings(Start, End);
|
ArgList *Args = ParseArgStrings(Start, End);
|
||||||
|
|
||||||
// FIXME: This behavior shouldn't be here.
|
// FIXME: This behavior shouldn't be here.
|
||||||
|
@ -121,7 +118,7 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
|
||||||
PrintOptions(Args);
|
PrintOptions(Args);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(0 && "FIXME: Implement");
|
assert(0 && "FIXME: Implement");
|
||||||
|
|
||||||
return new Compilation();
|
return new Compilation();
|
||||||
|
@ -143,3 +140,26 @@ void Driver::PrintOptions(const ArgList *Args) {
|
||||||
llvm::errs() << "}\n";
|
llvm::errs() << "}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HostInfo *Driver::GetHostInfo(const char *Triple) {
|
||||||
|
// Dice into arch, platform, and OS. This matches
|
||||||
|
// arch,platform,os = '(.*?)-(.*?)-(.*?)'
|
||||||
|
// and missing fields are left empty.
|
||||||
|
std::string Arch, Platform, OS;
|
||||||
|
|
||||||
|
if (const char *ArchEnd = strchr(Triple, '-')) {
|
||||||
|
Arch = std::string(Triple, ArchEnd);
|
||||||
|
|
||||||
|
if (const char *PlatformEnd = strchr(ArchEnd+1, '-')) {
|
||||||
|
Platform = std::string(ArchEnd+1, PlatformEnd);
|
||||||
|
OS = PlatformEnd+1;
|
||||||
|
} else
|
||||||
|
Platform = ArchEnd+1;
|
||||||
|
} else
|
||||||
|
Arch = Triple;
|
||||||
|
|
||||||
|
if (memcmp(&Platform[0], "darwin", 6) == 0)
|
||||||
|
return new DarwinHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str());
|
||||||
|
|
||||||
|
return new UnknownHostInfo(Arch.c_str(), Platform.c_str(), OS.c_str());
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "clang/Driver/Options.h"
|
#include "clang/Driver/Options.h"
|
||||||
|
|
||||||
#include "llvm/ADT/OwningPtr.h"
|
#include "llvm/ADT/OwningPtr.h"
|
||||||
|
#include "llvm/Config/config.h"
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
using namespace clang::driver;
|
using namespace clang::driver;
|
||||||
|
@ -30,8 +31,11 @@ int main(int argc, const char **argv) {
|
||||||
// is that the path derived from this will influence search paths.
|
// is that the path derived from this will influence search paths.
|
||||||
llvm::sys::Path Path(argv[0]);
|
llvm::sys::Path Path(argv[0]);
|
||||||
|
|
||||||
|
// FIXME: Use the triple of the host, not the triple that we were
|
||||||
|
// compiled on.
|
||||||
llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(),
|
llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(),
|
||||||
Path.getDirname().c_str()));
|
Path.getDirname().c_str(),
|
||||||
|
LLVM_HOSTTRIPLE));
|
||||||
|
|
||||||
llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv));
|
llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue