From: Daniel Dunbar Date: Wed, 18 Mar 2009 06:49:39 +0000 (+0000) Subject: Driver: Implement -### (hard to tell, since we don't actually X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24b5560b6ea51b8a260194710468fa060775fc01;p=clang Driver: Implement -### (hard to tell, since we don't actually construct any jobs). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67177 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h index 91e6dc6f44..566bc5e0ca 100644 --- a/include/clang/Driver/Compilation.h +++ b/include/clang/Driver/Compilation.h @@ -15,6 +15,10 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" +namespace llvm { + class raw_ostream; +} + namespace clang { namespace driver { class ArgList; @@ -80,6 +84,15 @@ public: /// Execute - Execute the compilation jobs and return an /// appropriate exit code. int Execute() const; + +private: + /// PrintJob - Print one job in -### format. + /// + /// OS - The stream to print on. + /// J - The job to print. + /// Terminator - A string to print at the end of the line. + void PrintJob(llvm::raw_ostream &OS, const Job *J, + const char *Terminator) const; }; } // end namespace driver diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 1dcb8d8f6e..364f328157 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -13,6 +13,7 @@ #include "clang/Driver/ArgList.h" #include "clang/Driver/ToolChain.h" +#include "llvm/Support/raw_ostream.h" using namespace clang::driver; Compilation::Compilation(ToolChain &_DefaultToolChain, @@ -48,6 +49,32 @@ const ArgList &Compilation::getArgsForToolChain(const ToolChain *TC) { return *Entry; } +void Compilation::PrintJob(llvm::raw_ostream &OS, const Job *J, + const char *Terminator) const { + if (const Command *C = dyn_cast(J)) { + OS << " \"" << C->getExecutable() << '"'; + for (ArgStringList::const_iterator it = C->getArguments().begin(), + ie = C->getArguments().end(); it != ie; ++it) + OS << " \"" << *it << '"'; + OS << Terminator; + } else if (const PipedJob *PJ = dyn_cast(J)) { + for (PipedJob::const_iterator + it = PJ->begin(), ie = PJ->end(); it != ie; ++it) + PrintJob(OS, *it, (it + 1 != PJ->end()) ? " |\n" : "\n"); + } else { + const JobList *Jobs = cast(J); + for (JobList::const_iterator + it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it) + PrintJob(OS, *it, Terminator); + } +} + int Compilation::Execute() const { + // Just print if -### was present. + if (getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { + PrintJob(llvm::errs(), &Jobs, "\n"); + return 0; + } + return 0; }