aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-06-11 22:00:26 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-06-11 22:00:26 +0000
commit279c1dbebf37cd128f3c73c70741a6b8c35ad025 (patch)
treed63cc4d0a2d13ad79bb6d2beb6534be7122d53aa
parent3612bc80fabcdd337f6d1df06e69b38c2c5f5a32 (diff)
Driver: Add an explicit argument translation phase to the driver itself. We are going to need this to handle things like -Xassembler, -Xpreprocessor, and -Xlinker which we might have to introspect.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105842 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Driver/ArgList.h18
-rw-r--r--include/clang/Driver/Compilation.h8
-rw-r--r--include/clang/Driver/Driver.h6
-rw-r--r--include/clang/Driver/ToolChain.h9
-rw-r--r--lib/Driver/ArgList.cpp4
-rw-r--r--lib/Driver/Compilation.cpp19
-rw-r--r--lib/Driver/Driver.cpp16
-rw-r--r--lib/Driver/ToolChains.cpp18
-rw-r--r--lib/Driver/ToolChains.h7
9 files changed, 62 insertions, 43 deletions
diff --git a/include/clang/Driver/ArgList.h b/include/clang/Driver/ArgList.h
index 40f6805e7d..3e28cc7dfd 100644
--- a/include/clang/Driver/ArgList.h
+++ b/include/clang/Driver/ArgList.h
@@ -96,6 +96,10 @@ namespace driver {
/// check for the presence of Arg instances for a particular Option
/// and to iterate over groups of arguments.
class ArgList {
+ private:
+ ArgList(const ArgList &); // DO NOT IMPLEMENT
+ void operator=(const ArgList &); // DO NOT IMPLEMENT
+
public:
typedef llvm::SmallVector<Arg*, 16> arglist_type;
typedef arglist_type::iterator iterator;
@@ -263,9 +267,6 @@ namespace driver {
};
class InputArgList : public ArgList {
- InputArgList(const ArgList &); // DO NOT IMPLEMENT
- void operator=(const ArgList &); // DO NOT IMPLEMENT
-
private:
/// List of argument strings used by the contained Args.
///
@@ -312,17 +313,14 @@ namespace driver {
/// DerivedArgList - An ordered collection of driver arguments,
/// whose storage may be in another argument list.
class DerivedArgList : public ArgList {
- InputArgList &BaseArgs;
+ const InputArgList &BaseArgs;
/// The list of arguments we synthesized.
mutable arglist_type SynthesizedArgs;
public:
/// Construct a new derived arg list from \arg BaseArgs.
- ///
- /// \param OnlyProxy - If true, this is only a proxy for the base
- /// list (to adapt the type), and it's Args list is unused.
- DerivedArgList(InputArgList &BaseArgs, bool OnlyProxy);
+ DerivedArgList(const InputArgList &BaseArgs);
~DerivedArgList();
virtual const char *getArgString(unsigned Index) const {
@@ -333,6 +331,10 @@ namespace driver {
return BaseArgs.getNumInputArgStrings();
}
+ const InputArgList &getBaseArgs() const {
+ return BaseArgs;
+ }
+
/// @name Arg Synthesis
/// @{
diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h
index 56786a7ae2..d9faa64103 100644
--- a/include/clang/Driver/Compilation.h
+++ b/include/clang/Driver/Compilation.h
@@ -40,6 +40,10 @@ class Compilation {
/// The original (untranslated) input argument list.
InputArgList *Args;
+ /// The driver translated arguments. Note that toolchains may perform their
+ /// own argument translation.
+ DerivedArgList *TranslatedArgs;
+
/// The list of actions.
ActionList Actions;
@@ -58,7 +62,7 @@ class Compilation {
public:
Compilation(const Driver &D, const ToolChain &DefaultToolChain,
- InputArgList *Args);
+ InputArgList *Args, DerivedArgList *TranslatedArgs);
~Compilation();
const Driver &getDriver() const { return TheDriver; }
@@ -67,6 +71,8 @@ public:
const InputArgList &getArgs() const { return *Args; }
+ const DerivedArgList &getTranslatedArgs() const { return *TranslatedArgs; }
+
ActionList &getActions() { return Actions; }
const ActionList &getActions() const { return Actions; }
diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h
index 90c3a0dcdc..153981f842 100644
--- a/include/clang/Driver/Driver.h
+++ b/include/clang/Driver/Driver.h
@@ -31,6 +31,7 @@ namespace driver {
class Action;
class ArgList;
class Compilation;
+ class DerivedArgList;
class HostInfo;
class InputArgList;
class InputInfo;
@@ -135,6 +136,11 @@ private:
std::list<std::string> TempFiles;
std::list<std::string> ResultFiles;
+private:
+ /// TranslateInputArgs - Create a new derived argument list from the input
+ /// arguments, after applying the standard argument translations.
+ DerivedArgList *TranslateInputArgs(const InputArgList &Args) const;
+
public:
Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
llvm::StringRef _DefaultHostTriple,
diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h
index 1a8ae77491..2cec22a09d 100644
--- a/include/clang/Driver/ToolChain.h
+++ b/include/clang/Driver/ToolChain.h
@@ -70,11 +70,14 @@ public:
// Tool access.
/// TranslateArgs - Create a new derived argument list for any argument
- /// translations this ToolChain may wish to perform.
+ /// translations this ToolChain may wish to perform, or 0 if no tool chain
+ /// specific translations are needed.
///
/// \param BoundArch - The bound architecture name, or 0.
- virtual DerivedArgList *TranslateArgs(InputArgList &Args,
- const char *BoundArch) const = 0;
+ virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
+ const char *BoundArch) const {
+ return 0;
+ }
/// SelectTool - Choose a tool to use to handle the action \arg JA.
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0;
diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp
index 63f1deec7f..46573022c5 100644
--- a/lib/Driver/ArgList.cpp
+++ b/lib/Driver/ArgList.cpp
@@ -240,10 +240,8 @@ const char *InputArgList::MakeArgString(llvm::StringRef Str) const {
//
-DerivedArgList::DerivedArgList(InputArgList &_BaseArgs, bool OnlyProxy)
+DerivedArgList::DerivedArgList(const InputArgList &_BaseArgs)
: BaseArgs(_BaseArgs) {
- if (OnlyProxy)
- getArgs() = _BaseArgs.getArgs();
}
DerivedArgList::~DerivedArgList() {
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp
index 227f79a75b..282e9fe82e 100644
--- a/lib/Driver/Compilation.cpp
+++ b/lib/Driver/Compilation.cpp
@@ -22,20 +22,22 @@
#include <errno.h>
using namespace clang::driver;
-Compilation::Compilation(const Driver &D,
- const ToolChain &_DefaultToolChain,
- InputArgList *_Args)
- : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args) {
+Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain,
+ InputArgList *_Args, DerivedArgList *_TranslatedArgs)
+ : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args),
+ TranslatedArgs(_TranslatedArgs) {
}
Compilation::~Compilation() {
+ delete TranslatedArgs;
delete Args;
// Free any derived arg lists.
for (llvm::DenseMap<std::pair<const ToolChain*, const char*>,
DerivedArgList*>::iterator it = TCArgs.begin(),
ie = TCArgs.end(); it != ie; ++it)
- delete it->second;
+ if (it->second != TranslatedArgs)
+ delete it->second;
// Free the actions, if built.
for (ActionList::iterator it = Actions.begin(), ie = Actions.end();
@@ -49,8 +51,11 @@ const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC,
TC = &DefaultToolChain;
DerivedArgList *&Entry = TCArgs[std::make_pair(TC, BoundArch)];
- if (!Entry)
- Entry = TC->TranslateArgs(*Args, BoundArch);
+ if (!Entry) {
+ Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch);
+ if (!Entry)
+ Entry = TranslatedArgs;
+ }
return *Entry;
}
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 7b45070912..4663fb9502 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -110,6 +110,16 @@ InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
return Args;
}
+DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
+ DerivedArgList *DAL = new DerivedArgList(Args);
+
+ for (ArgList::const_iterator it = Args.begin(),
+ ie = Args.end(); it != ie; ++it)
+ DAL->append(*it);
+
+ return DAL;
+}
+
Compilation *Driver::BuildCompilation(int argc, const char **argv) {
llvm::PrettyStackTraceString CrashInfo("Compilation construction");
@@ -179,8 +189,12 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
Host = GetHostInfo(HostTriple);
+ // Perform the default argument translations.
+ DerivedArgList *TranslatedArgs = TranslateInputArgs(*Args);
+
// The compilation takes ownership of Args.
- Compilation *C = new Compilation(*this, *Host->CreateToolChain(*Args), Args);
+ Compilation *C = new Compilation(*this, *Host->CreateToolChain(*Args), Args,
+ TranslatedArgs);
// FIXME: This behavior shouldn't be here.
if (CCCPrintOptions) {
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 92c7d793f9..ba329e3855 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -388,9 +388,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
}
}
-DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
+DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
const char *BoundArch) const {
- DerivedArgList *DAL = new DerivedArgList(Args, false);
+ DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
const OptTable &Opts = getDriver().getOpts();
// FIXME: We really want to get out of the tool chain level argument
@@ -478,7 +478,8 @@ DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
}
setTarget(iPhoneVersion, Major, Minor, Micro);
- for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
+ for (ArgList::const_iterator it = Args.begin(),
+ ie = Args.end(); it != ie; ++it) {
Arg *A = *it;
if (A->getOption().matches(options::OPT_Xarch__)) {
@@ -764,12 +765,6 @@ const char *Generic_GCC::GetForcedPicModel() const {
return 0;
}
-DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
- const char *BoundArch) const {
- return new DerivedArgList(Args, true);
-}
-
-
/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
/// Currently does not support anything else but compilation.
@@ -824,11 +819,6 @@ Tool &TCEToolChain::SelectTool(const Compilation &C,
return *T;
}
-DerivedArgList *TCEToolChain::TranslateArgs(InputArgList &Args,
- const char *BoundArch) const {
- return new DerivedArgList(Args, true);
-}
-
/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index ad975bfe6d..f561016ebe 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -33,9 +33,6 @@ public:
Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
~Generic_GCC();
- virtual DerivedArgList *TranslateArgs(InputArgList &Args,
- const char *BoundArch) const;
-
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
virtual bool IsUnwindTablesDefault() const;
@@ -147,7 +144,7 @@ public:
/// @name ToolChain Implementation
/// {
- virtual DerivedArgList *TranslateArgs(InputArgList &Args,
+ virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
const char *BoundArch) const;
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
@@ -290,8 +287,6 @@ public:
TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
~TCEToolChain();
- virtual DerivedArgList *TranslateArgs(InputArgList &Args,
- const char *BoundArch) const;
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
bool IsMathErrnoDefault() const;
bool IsUnwindTablesDefault() const;