From: Daniel Dunbar Date: Tue, 17 Mar 2009 22:47:06 +0000 (+0000) Subject: Driver: Add -ccc-print-bindings option (for testing); the Python X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c3c1d7b494660ba5e8983ee4584622750725ac2;p=clang Driver: Add -ccc-print-bindings option (for testing); the Python driver has no corresponding option. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67125 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index b0e6976ea7..02ee6116ad 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -78,6 +78,9 @@ public: /// Echo commands while executing (in -v style). bool CCCEcho : 1; + /// Only print tool bindings, don't build any jobs. + bool CCCPrintBindings : 1; + /// Don't use clang for any tasks. bool CCCNoClang : 1; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index c2df48cbc1..5f29195f51 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -40,7 +40,7 @@ Driver::Driver(const char *_Name, const char *_Dir, Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple), DefaultImageName(_DefaultImageName), Host(0), - CCCIsCXX(false), CCCEcho(false), + CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false), CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false), SuppressMissingInputWarning(false) { @@ -114,6 +114,8 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) { CCCPrintOptions = true; } else if (!strcmp(Opt, "print-phases")) { CCCPrintActions = true; + } else if (!strcmp(Opt, "print-bindings")) { + CCCPrintBindings = true; } else if (!strcmp(Opt, "cxx")) { CCCIsCXX = true; } else if (!strcmp(Opt, "echo")) { @@ -729,27 +731,32 @@ void Driver::BuildJobsForAction(Compilation &C, // Determine the place to write output to (nothing, pipe, or // filename) and where to put the new job. - PipedJob *OutputJob = 0; - const char *Output = 0; 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. - if (PipedJob *PJ = dyn_cast(Dest)) { - OutputJob = PJ; - Dest = OutputJob; - } else { - OutputJob = new PipedJob(); - cast(Dest)->addJob(OutputJob); - Dest = OutputJob; + PipedJob *PJ = dyn_cast(Dest); + if (!PJ) { + PJ = new PipedJob(); + cast(Dest)->addJob(PJ); } + Result = InputInfo(PJ, A->getType(), BaseInput); } else { - Output = GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel); + Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel), + A->getType(), BaseInput); } - // FIXME: Make the job. - - Result = InputInfo(Output, A->getType(), BaseInput); + if (CCCPrintBindings) { + llvm::errs() << "bind - \"" << T.getName() << "\", inputs: ["; + for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) { + llvm::errs() << InputInfos[i].getAsString(); + if (i + 1 != e) + llvm::errs() << ", "; + } + llvm::errs() << "], output: " << Result.getAsString() << "\n"; + } else { + assert(0 && "FIXME: Make the job."); + } } const char *Driver::GetNamedOutputPath(Compilation &C, diff --git a/lib/Driver/InputInfo.h b/lib/Driver/InputInfo.h index 6fedf82a99..6cef821e39 100644 --- a/lib/Driver/InputInfo.h +++ b/lib/Driver/InputInfo.h @@ -11,6 +11,7 @@ #define CLANG_LIB_DRIVER_INPUTINFO_H_ #include +#include namespace clang { namespace driver { @@ -28,6 +29,10 @@ class InputInfo { public: InputInfo() {} + InputInfo(types::ID _Type, const char *_BaseInput) + : IsPipe(false), Type(_Type), BaseInput(_BaseInput) { + Data.Filename = 0; + } InputInfo(const char *Filename, types::ID _Type, const char *_BaseInput) : IsPipe(false), Type(_Type), BaseInput(_BaseInput) { Data.Filename = Filename; @@ -49,6 +54,17 @@ public: assert(isPipe() && "Invalid accessor."); return *Data.Pipe; } + + /// getAsString - Return a string name for this input, for + /// debugging. + std::string getAsString() const { + if (isPipe()) + return "(pipe)"; + else if (const char *N = getInputFilename()) + return std::string("\"") + N + '"'; + else + return "(nothing)"; + } }; } // end namespace driver