[cfe-commits] r66888 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Fri Mar 13 05:19:02 PDT 2009


Author: ddunbar
Date: Fri Mar 13 07:19:02 2009
New Revision: 66888

URL: http://llvm.org/viewvc/llvm-project?rev=66888&view=rev
Log:
Driver: Support -ccc-print-phases.

Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=66888&r1=66887&r2=66888&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Fri Mar 13 07:19:02 2009
@@ -148,7 +148,7 @@
   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.

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=66888&r1=66887&r2=66888&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Mar 13 07:19:02 2009
@@ -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 @@
 
   // FIXME: This behavior shouldn't be here.
   if (CCCPrintActions) {
-    PrintActions(Actions);
+    PrintActions(*Args, Actions);
     exit(0);
   }
     
@@ -229,8 +232,48 @@
   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) {





More information about the cfe-commits mailing list