Driver: Support -M and -MM.
- Not particularly elegant, but my hand is forced by gcc.
Also, tweak -ccc-print-bindings output.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68027 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index a5d63e6..3f1a72d 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -245,8 +245,7 @@
llvm::errs() << "clang version 1.0 (" << vers << " " << revision << ")" << "\n";
const ToolChain &TC = C.getDefaultToolChain();
- llvm::errs() << "Target: " << TC.getArchName() << '-'
- << TC.getPlatform() << '-' << TC.getOS() << '\n';
+ llvm::errs() << "Target: " << TC.getTripleString() << '\n';
}
bool Driver::HandleImmediateArgs(const Compilation &C) {
@@ -379,9 +378,6 @@
if (Archs.size() > 1) {
// No recovery needed, the point of this is just to prevent
// overwriting the same files.
- if (const Arg *A = Args.getLastArg(options::OPT_M_Group))
- Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs)
- << A->getAsString(Args);
if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs)
<< A->getAsString(Args);
@@ -618,9 +614,15 @@
switch (Phase) {
case phases::Link: assert(0 && "link action invalid here.");
case phases::Preprocess: {
- types::ID OutputTy = types::getPreprocessedType(Input->getType());
- assert(OutputTy != types::TY_INVALID &&
- "Cannot preprocess this input type!");
+ types::ID OutputTy;
+ // -{M, MM} alter the output type.
+ if (Args.hasArg(options::OPT_M) || Args.hasArg(options::OPT_MM)) {
+ OutputTy = types::TY_Dependencies;
+ } else {
+ OutputTy = types::getPreprocessedType(Input->getType());
+ assert(OutputTy != types::TY_INVALID &&
+ "Cannot preprocess this input type!");
+ }
return new PreprocessJobAction(Input, OutputTy);
}
case phases::Precompile:
@@ -848,7 +850,8 @@
}
if (CCCPrintBindings) {
- llvm::errs() << "bind - \"" << T.getName() << "\", inputs: [";
+ llvm::errs() << "# \"" << T.getToolChain().getTripleString() << '"'
+ << " - \"" << T.getName() << "\", inputs: [";
for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) {
llvm::errs() << InputInfos[i].getAsString();
if (i + 1 != e)
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index bd833ea..3e8ccb3 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -43,7 +43,10 @@
assert(JA.getType() == types::TY_Plist && "Invalid output type.");
CmdArgs.push_back("-analyze");
} else if (isa<PreprocessJobAction>(JA)) {
- CmdArgs.push_back("-E");
+ if (Output.getType() == types::TY_Dependencies)
+ CmdArgs.push_back("-Eonly");
+ else
+ CmdArgs.push_back("-E");
} else if (isa<PrecompileJobAction>(JA)) {
// No special option needed, driven by -x.
//
@@ -218,7 +221,12 @@
(A = Args.getLastArg(options::OPT_MMD))) {
// Determine the output location.
const char *DepFile;
- if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+ if (Output.getType() == types::TY_Dependencies) {
+ if (Output.isPipe())
+ DepFile = "-";
+ else
+ DepFile = Output.getFilename();
+ } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
DepFile = MF->getValue(Args);
} else if (A->getOption().getId() == options::OPT_M ||
A->getOption().getId() == options::OPT_MM) {
@@ -234,8 +242,10 @@
if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) {
const char *DepTarget;
- // If user provided -o, that is the dependency target.
- if (Arg *A = Args.getLastArg(options::OPT_o)) {
+ // If user provided -o, that is the dependency target, except
+ // when we are only generating a dependency file.
+ Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+ if (OutputOpt && Output.getType() != types::TY_Dependencies) {
DepTarget = A->getValue(Args);
} else {
// Otherwise derive from the base input.
@@ -260,14 +270,9 @@
Args.AddLastArg(CmdArgs, options::OPT_MP);
Args.AddAllArgs(CmdArgs, options::OPT_MT);
- Arg *Unsupported = Args.getLastArg(options::OPT_M);
- if (!Unsupported)
- Unsupported = Args.getLastArg(options::OPT_MM);
- if (!Unsupported)
- Unsupported = Args.getLastArg(options::OPT_MG);
- if (!Unsupported)
- Unsupported = Args.getLastArg(options::OPT_MQ);
- if (Unsupported) {
+ Arg *Unsupported;
+ if ((Unsupported = Args.getLastArg(options::OPT_MG)) ||
+ (Unsupported = Args.getLastArg(options::OPT_MQ))) {
const Driver &D = getToolChain().getHost().getDriver();
D.Diag(clang::diag::err_drv_unsupported_opt)
<< Unsupported->getOption().getName();
@@ -371,9 +376,8 @@
CmdArgs.push_back("-arch");
CmdArgs.push_back(getToolChain().getArchName().c_str());
- // FIXME: We should have a separate type for this.
- if (Args.hasArg(options::OPT_M) || Args.hasArg(options::OPT_MM)) {
- CmdArgs.push_back("-M");
+ if (Output.getType() == types::TY_Dependencies) {
+ // Handled with other dependency code.
} else if (Output.isPipe()) {
CmdArgs.push_back("-o");
CmdArgs.push_back("-");