Driver: Handle "immediate" options.
Also, add some FIXMEs, improve doxygen & comments. llvm-svn: 66857
This commit is contained in:
parent
54e6d924ff
commit
5e0f6af190
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "clang/Driver/Util.h"
|
||||
|
||||
#include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo
|
||||
// lands.
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
@ -25,6 +27,7 @@ namespace driver {
|
|||
class Compilation;
|
||||
class HostInfo;
|
||||
class OptTable;
|
||||
class ToolChain;
|
||||
|
||||
/// Driver - Encapsulate logic for constructing compilation processes
|
||||
/// from a set of gcc-driver-like command line arguments.
|
||||
|
@ -77,6 +80,11 @@ public:
|
|||
/// will generally be the actual host platform, but not always.
|
||||
HostInfo *Host;
|
||||
|
||||
/// The default tool chain for this host.
|
||||
// FIXME: This shouldn't be here; this should be in a
|
||||
// CompilationInfo structure.
|
||||
ToolChain *DefaultToolChain;
|
||||
|
||||
/// Information about the host which can be overriden by the user.
|
||||
std::string HostBits, HostMachine, HostSystem, HostRelease;
|
||||
|
||||
|
@ -112,21 +120,26 @@ public:
|
|||
Diagnostic &_Diags);
|
||||
~Driver();
|
||||
|
||||
/// @name Accessors
|
||||
/// @{
|
||||
|
||||
const OptTable &getOpts() const { return *Opts; }
|
||||
|
||||
/// @}
|
||||
/// @name Primary Functionality
|
||||
/// @{
|
||||
|
||||
/// BuildCompilation - Construct a compilation object for a command
|
||||
/// line argument vector.
|
||||
///
|
||||
/// \return A compilation, or 0 if none was built for the given
|
||||
/// argument vector. A null return value does not necessarily
|
||||
/// indicate an error condition, the diagnostics should be queried
|
||||
/// to determine if an error occurred.
|
||||
Compilation *BuildCompilation(int argc, const char **argv);
|
||||
|
||||
/// PrintOptions - Print the list of arguments.
|
||||
void PrintOptions(const ArgList &Args) const;
|
||||
|
||||
/// PrintActions - Print the list of actions.
|
||||
void PrintActions(const ActionList &Actions) const;
|
||||
|
||||
/// GetHostInfo - Construct a new host info object for the given
|
||||
/// host triple.
|
||||
static HostInfo *GetHostInfo(const char *HostTriple);
|
||||
/// @name Driver Steps
|
||||
/// @{
|
||||
|
||||
/// BuildUniversalActions - Construct the list of actions to perform
|
||||
/// for the given arguments, which may require a universal build.
|
||||
|
@ -141,6 +154,41 @@ public:
|
|||
/// \param Args - The input arguments.
|
||||
/// \param Actions - The list to store the resulting actions onto.
|
||||
void BuildActions(ArgList &Args, ActionList &Actions);
|
||||
|
||||
/// @}
|
||||
/// @name Helper Methods
|
||||
/// @{
|
||||
|
||||
/// PrintOptions - Print the list of arguments.
|
||||
void PrintOptions(const ArgList &Args) const;
|
||||
|
||||
/// PrintVersion - Print the driver version.
|
||||
void PrintVersion() const;
|
||||
|
||||
/// PrintActions - Print the list of actions.
|
||||
void PrintActions(const ActionList &Actions) const;
|
||||
|
||||
/// GetFilePath - Lookup \arg Name in the list of file search paths.
|
||||
// FIXME: This should be in CompilationInfo.
|
||||
llvm::sys::Path GetFilePath(const char *Name) const;
|
||||
|
||||
/// GetProgramPath - Lookup \arg Name in the list of program search
|
||||
/// paths.
|
||||
// FIXME: This should be in CompilationInfo.
|
||||
llvm::sys::Path GetProgramPath(const char *Name) const;
|
||||
|
||||
/// HandleImmediateArgs - Handle any arguments which should be
|
||||
/// treated before building actions or binding tools.
|
||||
///
|
||||
/// \return Whether any compilation should be built for this
|
||||
/// invocation.
|
||||
bool HandleImmediateArgs(const ArgList &Args);
|
||||
|
||||
/// GetHostInfo - Construct a new host info object for the given
|
||||
/// host triple.
|
||||
static HostInfo *GetHostInfo(const char *HostTriple);
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
} // end namespace driver
|
||||
|
|
|
@ -47,10 +47,10 @@ public:
|
|||
/// default toolchain, for example in the presence of -m32 or -m64.
|
||||
///
|
||||
/// \param ArchName - The architecture to return a toolchain for, or
|
||||
/// 0 if unspecified. This will only be non-zero for hosts which
|
||||
/// support a driver driver.
|
||||
/// 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) const = 0;
|
||||
const char *ArchName=0) const = 0;
|
||||
};
|
||||
|
||||
/// DarwinHostInfo - Darwin host information implementation.
|
||||
|
|
|
@ -63,6 +63,14 @@ ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
|
|||
}
|
||||
|
||||
Compilation *Driver::BuildCompilation(int argc, const char **argv) {
|
||||
// FIXME: Handle environment options which effect driver behavior,
|
||||
// somewhere (client?). GCC_EXEC_PREFIX, COMPILER_PATH,
|
||||
// LIBRARY_PATH, LPATH, CC_PRINT_OPTIONS, QA_OVERRIDE_GCC3_OPTIONS.
|
||||
|
||||
// FIXME: What are we going to do with -V and -b?
|
||||
|
||||
// FIXME: Handle CCC_ADD_ARGS.
|
||||
|
||||
// FIXME: This stuff needs to go into the Compilation, not the
|
||||
// driver.
|
||||
bool CCCPrintOptions = false, CCCPrintActions = false;
|
||||
|
@ -121,16 +129,20 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
Host = Driver::GetHostInfo(HostTriple);
|
||||
|
||||
ArgList *Args = ParseArgStrings(Start, End);
|
||||
|
||||
Host = Driver::GetHostInfo(HostTriple);
|
||||
DefaultToolChain = Host->getToolChain(*Args);
|
||||
|
||||
// FIXME: This behavior shouldn't be here.
|
||||
if (CCCPrintOptions) {
|
||||
PrintOptions(*Args);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!HandleImmediateArgs(*Args))
|
||||
return 0;
|
||||
|
||||
// Construct the list of abstract actions to perform for this
|
||||
// compilation.
|
||||
ActionList Actions;
|
||||
|
@ -167,6 +179,44 @@ void Driver::PrintOptions(const ArgList &Args) const {
|
|||
}
|
||||
}
|
||||
|
||||
void Driver::PrintVersion() const {
|
||||
// FIXME: Get a reasonable version number.
|
||||
|
||||
// FIXME: The following handlers should use a callback mechanism, we
|
||||
// don't know what the client would like to do.
|
||||
llvm::outs() << "ccc version 1.0" << "\n";
|
||||
}
|
||||
|
||||
bool Driver::HandleImmediateArgs(const ArgList &Args) {
|
||||
// The order these options are handled in in gcc is all over the
|
||||
// place, but we don't expect inconsistencies w.r.t. that to matter
|
||||
// in practice.
|
||||
if (Args.hasArg(options::OPT_v) ||
|
||||
Args.hasArg(options::OPT__HASH_HASH_HASH)) {
|
||||
PrintVersion();
|
||||
SuppressMissingInputWarning = true;
|
||||
}
|
||||
|
||||
// FIXME: The following handlers should use a callback mechanism, we
|
||||
// don't know what the client would like to do.
|
||||
if (Arg *A = Args.getLastArg(options::OPT_print_file_name_EQ)) {
|
||||
llvm::outs() << GetFilePath(A->getValue(Args)).toString() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Arg *A = Args.getLastArg(options::OPT_print_prog_name_EQ)) {
|
||||
llvm::outs() << GetProgramPath(A->getValue(Args)).toString() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Arg *A = Args.getLastArg(options::OPT_print_libgcc_file_name)) {
|
||||
llvm::outs() << GetProgramPath("libgcc.a").toString() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Driver::PrintActions(const ActionList &Actions) const {
|
||||
llvm::errs() << "FIXME: Print actions.";
|
||||
}
|
||||
|
@ -372,6 +422,16 @@ void Driver::BuildActions(ArgList &Args, ActionList &Actions) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
llvm::sys::Path Driver::GetFilePath(const char *Name) const {
|
||||
// FIXME: Implement.
|
||||
return llvm::sys::Path(Name);
|
||||
}
|
||||
|
||||
llvm::sys::Path Driver::GetProgramPath(const char *Name) const {
|
||||
// FIXME: Implement.
|
||||
return llvm::sys::Path(Name);
|
||||
}
|
||||
|
||||
HostInfo *Driver::GetHostInfo(const char *Triple) {
|
||||
// Dice into arch, platform, and OS. This matches
|
||||
// arch,platform,os = '(.*?)-(.*?)-(.*?)'
|
||||
|
|
Loading…
Reference in New Issue