summaryrefslogtreecommitdiffstats
path: root/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2010-09-17 15:54:40 +0000
committerdim <dim@FreeBSD.org>2010-09-17 15:54:40 +0000
commit36c49e3f258dced101949edabd72e9bc3f1dedc4 (patch)
tree0bbe07708f7571f8b5291f6d7b96c102b7c99dee /lib/Driver/Driver.cpp
parentfc84956ac8b7cd244ef30e7a4d4d38a58dec5904 (diff)
downloadFreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.zip
FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.tar.gz
Vendor import of clang r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020 Approved by: rpaulo (mentor)
Diffstat (limited to 'lib/Driver/Driver.cpp')
-rw-r--r--lib/Driver/Driver.cpp126
1 files changed, 48 insertions, 78 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 2fc0a53..82f9134 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -25,6 +25,7 @@
#include "clang/Basic/Version.h"
+#include "llvm/Config/config.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/PrettyStackTrace.h"
@@ -39,13 +40,13 @@
using namespace clang::driver;
using namespace clang;
-Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
+Driver::Driver(llvm::StringRef _ClangExecutable,
llvm::StringRef _DefaultHostTriple,
llvm::StringRef _DefaultImageName,
bool IsProduction, bool CXXIsProduction,
Diagnostic &_Diags)
: Opts(createDriverOptTable()), Diags(_Diags),
- Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple),
+ ClangExecutable(_ClangExecutable), DefaultHostTriple(_DefaultHostTriple),
DefaultImageName(_DefaultImageName),
DriverTitle("clang \"gcc-compatible\" driver"),
Host(0),
@@ -68,6 +69,10 @@ Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
CCCUseClangCXX = false;
}
+ llvm::sys::Path Executable(ClangExecutable);
+ Name = Executable.getBasename();
+ Dir = Executable.getDirname();
+
// Compute the path to the resource directory.
llvm::sys::Path P(Dir);
P.eraseComponent(); // Remove /bin from foo/bin
@@ -75,11 +80,6 @@ Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
P.appendComponent("clang");
P.appendComponent(CLANG_VERSION_STRING);
ResourceDir = P.str();
-
- // Save the original clang executable path.
- P = Dir;
- P.appendComponent(Name);
- ClangExecutable = P.str();
}
Driver::~Driver() {
@@ -160,6 +160,16 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
DAL->append(*it);
}
+ // Add a default value of -mlinker-version=, if one was given and the user
+ // didn't specify one.
+#if defined(HOST_LINK_VERSION)
+ if (!Args.hasArg(options::OPT_mlinker_version_EQ)) {
+ DAL->AddJoinedArg(0, Opts->getOption(options::OPT_mlinker_version_EQ),
+ HOST_LINK_VERSION);
+ DAL->getLastArg(options::OPT_mlinker_version_EQ)->claim();
+ }
+#endif
+
return DAL;
}
@@ -176,13 +186,15 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
bool CCCPrintOptions = false, CCCPrintActions = false;
const char **Start = argv + 1, **End = argv + argc;
- const char *HostTriple = DefaultHostTriple.c_str();
InputArgList *Args = ParseArgStrings(Start, End);
// -no-canonical-prefixes is used very early in main.
Args->ClaimAllArgs(options::OPT_no_canonical_prefixes);
+ // Ignore -pipe.
+ Args->ClaimAllArgs(options::OPT_pipe);
+
// Extract -ccc args.
//
// FIXME: We need to figure out where this behavior should live. Most of it
@@ -223,14 +235,16 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
Cur = Split.second;
}
}
+ // FIXME: We shouldn't overwrite the default host triple here, but we have
+ // nowhere else to put this currently.
if (const Arg *A = Args->getLastArg(options::OPT_ccc_host_triple))
- HostTriple = A->getValue(*Args);
+ DefaultHostTriple = A->getValue(*Args);
if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
- Dir = A->getValue(*Args);
+ Dir = InstalledDir = A->getValue(*Args);
if (const Arg *A = Args->getLastArg(options::OPT_B))
PrefixDir = A->getValue(*Args);
- Host = GetHostInfo(HostTriple);
+ Host = GetHostInfo(DefaultHostTriple.c_str());
// Perform the default argument translations.
DerivedArgList *TranslatedArgs = TranslateInputArgs(*Args);
@@ -248,14 +262,12 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
if (!HandleImmediateArgs(*C))
return C;
- // Construct the list of abstract actions to perform for this compilation. We
- // avoid passing a Compilation here simply to enforce the abstraction that
- // pipelining is not host or toolchain dependent (other than the driver driver
- // test).
+ // Construct the list of abstract actions to perform for this compilation.
if (Host->useDriverDriver())
- BuildUniversalActions(C->getArgs(), C->getActions());
+ BuildUniversalActions(C->getDefaultToolChain(), C->getArgs(),
+ C->getActions());
else
- BuildActions(C->getArgs(), C->getActions());
+ BuildActions(C->getDefaultToolChain(), C->getArgs(), C->getActions());
if (CCCPrintActions) {
PrintActions(*C);
@@ -525,7 +537,8 @@ static bool ContainsCompileAction(const Action *A) {
return false;
}
-void Driver::BuildUniversalActions(const ArgList &Args,
+void Driver::BuildUniversalActions(const ToolChain &TC,
+ const ArgList &Args,
ActionList &Actions) const {
llvm::PrettyStackTraceString CrashInfo("Building universal build actions");
// Collect the list of architectures. Duplicates are allowed, but should only
@@ -570,7 +583,7 @@ void Driver::BuildUniversalActions(const ArgList &Args,
}
ActionList SingleActions;
- BuildActions(Args, SingleActions);
+ BuildActions(TC, Args, SingleActions);
// Add in arch bindings for every top level action, as well as lipo and
// dsymutil steps if needed.
@@ -620,7 +633,8 @@ void Driver::BuildUniversalActions(const ArgList &Args,
}
}
-void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
+void Driver::BuildActions(const ToolChain &TC, const ArgList &Args,
+ ActionList &Actions) const {
llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
// Start by constructing the list of inputs and their types.
@@ -660,7 +674,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
// found. We use a host hook here because Darwin at least has its own
// idea of what .s is.
if (const char *Ext = strrchr(Value, '.'))
- Ty = Host->lookupTypeForExtension(Ext + 1);
+ Ty = TC.LookupTypeForExtension(Ext + 1);
if (Ty == types::TY_INVALID)
Ty = types::TY_Object;
@@ -885,16 +899,6 @@ Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
void Driver::BuildJobs(Compilation &C) const {
llvm::PrettyStackTraceString CrashInfo("Building compilation jobs");
- bool SaveTemps = C.getArgs().hasArg(options::OPT_save_temps);
- bool UsePipes = C.getArgs().hasArg(options::OPT_pipe);
-
- // FIXME: Pipes are forcibly disabled until we support executing them.
- if (!CCCPrintBindings)
- UsePipes = false;
-
- // -save-temps inhibits pipes.
- if (SaveTemps && UsePipes)
- Diag(clang::diag::warn_drv_pipe_ignored_with_save_temps);
Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
@@ -934,7 +938,6 @@ void Driver::BuildJobs(Compilation &C) const {
InputInfo II;
BuildJobsForAction(C, A, &C.getDefaultToolChain(),
/*BoundArch*/0,
- /*CanAcceptPipe*/ true,
/*AtTopLevel*/ true,
/*LinkingOutput*/ LinkingOutput,
II);
@@ -1032,17 +1035,11 @@ void Driver::BuildJobsForAction(Compilation &C,
const Action *A,
const ToolChain *TC,
const char *BoundArch,
- bool CanAcceptPipe,
bool AtTopLevel,
const char *LinkingOutput,
InputInfo &Result) const {
llvm::PrettyStackTraceString CrashInfo("Building compilation jobs");
- bool UsePipes = C.getArgs().hasArg(options::OPT_pipe);
- // FIXME: Pipes are forcibly disabled until we support executing them.
- if (!CCCPrintBindings)
- UsePipes = false;
-
if (const InputAction *IA = dyn_cast<InputAction>(A)) {
// FIXME: It would be nice to not claim this here; maybe the old scheme of
// just using Args was better?
@@ -1064,7 +1061,7 @@ void Driver::BuildJobsForAction(Compilation &C,
TC = Host->CreateToolChain(C.getArgs(), BAA->getArchName());
BuildJobsForAction(C, *BAA->begin(), TC, BAA->getArchName(),
- CanAcceptPipe, AtTopLevel, LinkingOutput, Result);
+ AtTopLevel, LinkingOutput, Result);
return;
}
@@ -1074,7 +1071,6 @@ void Driver::BuildJobsForAction(Compilation &C,
const Tool &T = SelectToolForJob(C, TC, JA, Inputs);
// Only use pipes when there is exactly one input.
- bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput();
InputInfoList InputInfos;
for (ActionList::const_iterator it = Inputs->begin(), ie = Inputs->end();
it != ie; ++it) {
@@ -1087,33 +1083,11 @@ void Driver::BuildJobsForAction(Compilation &C,
SubJobAtTopLevel = true;
InputInfo II;
- BuildJobsForAction(C, *it, TC, BoundArch, TryToUsePipeInput,
+ BuildJobsForAction(C, *it, TC, BoundArch,
SubJobAtTopLevel, LinkingOutput, II);
InputInfos.push_back(II);
}
- // Determine if we should output to a pipe.
- bool OutputToPipe = false;
- if (CanAcceptPipe && T.canPipeOutput()) {
- // Some actions default to writing to a pipe if they are the top level phase
- // and there was no user override.
- //
- // FIXME: Is there a better way to handle this?
- if (AtTopLevel) {
- if (isa<PreprocessJobAction>(A) && !C.getArgs().hasArg(options::OPT_o))
- OutputToPipe = true;
- } else if (UsePipes)
- OutputToPipe = true;
- }
-
- // Figure out where to put the job (pipes).
- Job *Dest = &C.getJobs();
- if (InputInfos[0].isPipe()) {
- assert(TryToUsePipeInput && "Unrequested pipe!");
- assert(InputInfos.size() == 1 && "Unexpected pipe with multiple inputs.");
- Dest = &InputInfos[0].getPipe();
- }
-
// Always use the first input as the base input.
const char *BaseInput = InputInfos[0].getBaseInput();
@@ -1122,22 +1096,9 @@ void Driver::BuildJobsForAction(Compilation &C,
if (JA->getType() == types::TY_dSYM)
BaseInput = InputInfos[0].getFilename();
- // Determine the place to write output to (nothing, pipe, or filename) and
- // where to put the new job.
+ // Determine the place to write output to, if any.
if (JA->getType() == types::TY_Nothing) {
Result = InputInfo(A->getType(), BaseInput);
- } else if (OutputToPipe) {
- // Append to current piped job or create a new one as appropriate.
- PipedJob *PJ = dyn_cast<PipedJob>(Dest);
- if (!PJ) {
- PJ = new PipedJob();
- // FIXME: Temporary hack so that -ccc-print-bindings work until we have
- // pipe support. Please remove later.
- if (!CCCPrintBindings)
- cast<JobList>(Dest)->addJob(PJ);
- Dest = PJ;
- }
- Result = InputInfo(PJ, A->getType(), BaseInput);
} else {
Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel),
A->getType(), BaseInput);
@@ -1153,7 +1114,7 @@ void Driver::BuildJobsForAction(Compilation &C,
}
llvm::errs() << "], output: " << Result.getAsString() << "\n";
} else {
- T.ConstructJob(C, *JA, *Dest, Result, InputInfos,
+ T.ConstructJob(C, *JA, Result, InputInfos,
C.getArgsForToolChain(TC, BoundArch), LinkingOutput);
}
}
@@ -1169,6 +1130,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
return C.addResultFile(FinalOutput->getValue(C.getArgs()));
}
+ // Default to writing to stdout?
+ if (AtTopLevel && isa<PreprocessJobAction>(JA))
+ return "-";
+
// Output to a temporary file?
if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) {
std::string TmpName =
@@ -1307,6 +1272,11 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const {
return createMinixHostInfo(*this, Triple);
case llvm::Triple::Linux:
return createLinuxHostInfo(*this, Triple);
+ case llvm::Triple::Win32:
+ return createWindowsHostInfo(*this, Triple);
+ case llvm::Triple::MinGW32:
+ case llvm::Triple::MinGW64:
+ return createMinGWHostInfo(*this, Triple);
default:
return createUnknownHostInfo(*this, Triple);
}
OpenPOWER on IntegriCloud