From ba1021388e6839b76c8968b931189361c7286674 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 13 Mar 2009 12:19:02 +0000 Subject: [PATCH] Driver: Support -ccc-print-phases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66888 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Driver.h | 2 +- lib/Driver/Driver.cpp | 49 ++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 7385f11ddc..896c844bd6 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -148,7 +148,7 @@ public: void PrintVersion() const; /// PrintActions - Print the list of actions. - void PrintActions(const ActionList &Actions) const; + void PrintActions(const ArgList &Args, const ActionList &Actions) const; /// GetFilePath - Lookup \arg Name in the list of file search paths. // FIXME: This should be in CompilationInfo. diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 75e9df25e0..4efd4608e1 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -22,6 +22,9 @@ #include "llvm/ADT/StringMap.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" + +#include + using namespace clang::driver; Driver::Driver(const char *_Name, const char *_Dir, @@ -165,7 +168,7 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) { // FIXME: This behavior shouldn't be here. if (CCCPrintActions) { - PrintActions(Actions); + PrintActions(*Args, Actions); exit(0); } @@ -229,8 +232,48 @@ bool Driver::HandleImmediateArgs(const ArgList &Args) { return true; } -void Driver::PrintActions(const ActionList &Actions) const { - llvm::errs() << "FIXME: Print actions."; +// FIXME: This shouldn't be here? +static unsigned PrintActions1(const ArgList &Args, + Action *A, + std::map &Ids) { + if (Ids.count(A)) + return Ids[A]; + + std::string str; + llvm::raw_string_ostream os(str); + + os << Action::getClassName(A->getKind()) << ", "; + if (InputAction *IA = dyn_cast(A)) { + os << IA->getInputArg().getValue(Args) << "\""; + } else if (BindArchAction *BIA = dyn_cast(A)) { + os << "\"" << BIA->getArchName() << "\", " + << "{" << PrintActions1(Args, *BIA->begin(), Ids) << "}"; + } else { + os << "{"; + for (Action::iterator it = A->begin(), ie = A->end(); it != ie;) { + os << PrintActions1(Args, *it, Ids); + ++it; + if (it != ie) + os << ", "; + } + os << "}"; + } + + unsigned Id = Ids.size(); + Ids[A] = Id; + llvm::outs() << Id << ": " << os.str() << ", " + << types::getTypeName(A->getType()) << "\n"; + + return Id; +} + +void Driver::PrintActions(const ArgList &Args, + const ActionList &Actions) const { + std::map Ids; + for (ActionList::const_iterator it = Actions.begin(), ie = Actions.end(); + it != ie; ++it) { + PrintActions1(Args, *it, Ids); + } } void Driver::BuildUniversalActions(ArgList &Args, ActionList &Actions) {