]> granicus.if.org Git - clang/commitdiff
Driver: Support -ccc-print-phases.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Mar 2009 12:19:02 +0000 (12:19 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Mar 2009 12:19:02 +0000 (12:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66888 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Driver.h
lib/Driver/Driver.cpp

index 7385f11ddc317e472763c26a3635768dc82bc23d..896c844bd6e0ec8a0e96251d4d074fb3580192f8 100644 (file)
@@ -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.
index 75e9df25e05105bf33cf0ddd4d1ac093e4e26419..4efd4608e1a4bfe4734e76be9573588e248288ac 100644 (file)
@@ -22,6 +22,9 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
+
+#include <map>
+
 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<Action*, unsigned> &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<InputAction>(A)) {    
+    os << IA->getInputArg().getValue(Args) << "\"";
+  } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(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<Action*, unsigned> 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) {