diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-18 08:07:30 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-18 08:07:30 +0000 |
commit | b488c1dac8e53206f07103d794a62a3f5012c0f4 (patch) | |
tree | 2508403c66ff8524822cae04497a74e287309e93 /lib/Driver/Tools.cpp | |
parent | e324ffe33e179f6167d18834e15c48c49e314bb4 (diff) |
Driver: Lift out common GCC tool and implement generic GCC tool
argument translation.
Also, stub out clang tool implementation a bit more.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67185 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r-- | lib/Driver/Tools.cpp | 127 |
1 files changed, 93 insertions, 34 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 20c307417c..f7480ea974 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -10,8 +10,12 @@ #include "Tools.h" #include "clang/Driver/Arg.h" +#include "clang/Driver/ArgList.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Job.h" +#include "clang/Driver/HostInfo.h" +#include "clang/Driver/Option.h" +#include "clang/Driver/ToolChain.h" #include "clang/Driver/Util.h" #include "llvm/ADT/SmallVector.h" @@ -27,49 +31,104 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, const InputInfoList &Inputs, const ArgList &TCArgs, const char *LinkingOutput) const { + ArgStringList CmdArgs; + + for (InputInfoList::const_iterator + it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { + const InputInfo &II = *it; + if (II.isPipe()) + CmdArgs.push_back("-"); + else + CmdArgs.push_back(II.getInputFilename()); + } + + if (Output.isPipe()) { + CmdArgs.push_back("-o"); + CmdArgs.push_back("-"); + } else if (const char *N = Output.getInputFilename()) { + CmdArgs.push_back("-o"); + CmdArgs.push_back(N); + } + + Dest.addCommand(new Command("clang", CmdArgs)); } -void gcc::Preprocess::ConstructJob(Compilation &C, const JobAction &JA, - Job &Dest, - const InputInfo &Output, - const InputInfoList &Inputs, - const ArgList &TCArgs, - const char *LinkingOutput) const { - +void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, + Job &Dest, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &TCArgs, + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + for (ArgList::const_iterator + it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) { + Arg *A = *it; + if (A->getOption().hasForwardToGCC()) + A->render(TCArgs, CmdArgs); + } + + RenderExtraToolArgs(CmdArgs); + + // If using a driver driver, force the arch. + if (getToolChain().getHost().useDriverDriver()) { + CmdArgs.push_back("-arch"); + CmdArgs.push_back(getToolChain().getArchName().c_str()); + } + + if (Output.isPipe()) { + CmdArgs.push_back("-o"); + CmdArgs.push_back("-"); + } else if (const char *N = Output.getInputFilename()) { + CmdArgs.push_back("-o"); + CmdArgs.push_back(N); + } else + CmdArgs.push_back("-fsyntax-only"); + + + // Only pass -x if gcc will understand it; otherwise hope gcc + // understands the suffix correctly. The main use case this would go + // wrong in is for linker inputs if they happened to have an odd + // suffix; really the only way to get this to happen is a command + // like '-x foobar a.c' which will treat a.c like a linker input. + // + // FIXME: For the linker case specifically, can we safely convert + // inputs into '-Wl,' options? + for (InputInfoList::const_iterator + it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { + const InputInfo &II = *it; + if (types::canTypeBeUserSpecified(II.getType())) { + CmdArgs.push_back("-x"); + CmdArgs.push_back(types::getTypeName(II.getType())); + } + + if (II.isPipe()) + CmdArgs.push_back("-"); + else + // FIXME: Linker inputs + CmdArgs.push_back(II.getInputFilename()); + } + + Dest.addCommand(new Command("gcc", CmdArgs)); } -void gcc::Precompile::ConstructJob(Compilation &C, const JobAction &JA, - Job &Dest, - const InputInfo &Output, - const InputInfoList &Inputs, - const ArgList &TCArgs, - const char *LinkingOutput) const { - +void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { + CmdArgs.push_back("-E"); } -void gcc::Compile::ConstructJob(Compilation &C, const JobAction &JA, - Job &Dest, - const InputInfo &Output, - const InputInfoList &Inputs, - const ArgList &TCArgs, - const char *LinkingOutput) const { - +void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { + // The type is good enough. } -void gcc::Assemble::ConstructJob(Compilation &C, const JobAction &JA, - Job &Dest, - const InputInfo &Output, - const InputInfoList &Inputs, - const ArgList &TCArgs, - const char *LinkingOutput) const { - +void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { + CmdArgs.push_back("-S"); } -void gcc::Link::ConstructJob(Compilation &C, const JobAction &JA, - Job &Dest, - const InputInfo &Output, - const InputInfoList &Inputs, - const ArgList &TCArgs, - const char *LinkingOutput) const { +void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { + CmdArgs.push_back("-c"); +} +void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { + // The types are (hopefully) good enough. } + |