diff options
author | Joerg Sonnenberger <joerg@bec.de> | 2011-03-06 23:31:01 +0000 |
---|---|---|
committer | Joerg Sonnenberger <joerg@bec.de> | 2011-03-06 23:31:01 +0000 |
commit | 9ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2 (patch) | |
tree | 40f863a2a3a64bfc81647d6ebc32185e5b381c5e /lib/Driver/Driver.cpp | |
parent | 4707b9acf75c68c90278757ffd6a05b2544bc1eb (diff) |
If called as *cpp or *cpp-[^-]*, run only the preprocessor. If no
input is specified, use stdin implicitly. Based on a patch from
Roman Divacky.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127137 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Driver.cpp')
-rw-r--r-- | lib/Driver/Driver.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index ee225f25e8..c8300d3d69 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -308,10 +308,10 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) { // Construct the list of abstract actions to perform for this compilation. if (Host->useDriverDriver()) - BuildUniversalActions(C->getDefaultToolChain(), C->getArgs(), + BuildUniversalActions(C->getDefaultToolChain(), C->getInputArgs(), C->getActions()); else - BuildActions(C->getDefaultToolChain(), C->getArgs(), C->getActions()); + BuildActions(C->getDefaultToolChain(), C->getInputArgs(), C->getActions()); if (CCCPrintActions) { PrintActions(*C); @@ -593,7 +593,7 @@ static bool ContainsCompileAction(const Action *A) { } void Driver::BuildUniversalActions(const ToolChain &TC, - const ArgList &Args, + const InputArgList &Args, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building universal build actions"); // Collect the list of architectures. Duplicates are allowed, but should only @@ -688,7 +688,7 @@ void Driver::BuildUniversalActions(const ToolChain &TC, } } -void Driver::BuildActions(const ToolChain &TC, const ArgList &Args, +void Driver::BuildActions(const ToolChain &TC, const InputArgList &Args, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building compilation actions"); // Start by constructing the list of inputs and their types. @@ -721,7 +721,7 @@ void Driver::BuildActions(const ToolChain &TC, const ArgList &Args, // // Otherwise emit an error but still use a valid type to avoid // spurious errors (e.g., no inputs). - if (!Args.hasArgNoClaim(options::OPT_E)) + if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP) Diag(clang::diag::err_drv_unknown_stdin_type); Ty = types::TY_C; } else { @@ -799,6 +799,15 @@ void Driver::BuildActions(const ToolChain &TC, const ArgList &Args, } } + if (CCCIsCPP && Inputs.empty()) { + // If called as standalone preprocessor, stdin is processed + // if no other input is present. + unsigned Index = Args.MakeIndex("-"); + Arg *A = Opts->ParseOneArg(Args, Index); + A->claim(); + Inputs.push_back(std::make_pair(types::TY_C, A)); + } + if (!SuppressMissingInputWarning && Inputs.empty()) { Diag(clang::diag::err_drv_no_input_files); return; @@ -811,7 +820,8 @@ void Driver::BuildActions(const ToolChain &TC, const ArgList &Args, phases::ID FinalPhase; // -{E,M,MM} only run the preprocessor. - if ((FinalPhaseArg = Args.getLastArg(options::OPT_E)) || + if (CCCIsCPP || + (FinalPhaseArg = Args.getLastArg(options::OPT_E)) || (FinalPhaseArg = Args.getLastArg(options::OPT_M, options::OPT_MM))) { FinalPhase = phases::Preprocess; |