Added support to clang driver to view ASTs using GraphViz.  This
functionality is still preliminary.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42152 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/ASTStreamers.cpp b/Driver/ASTStreamers.cpp
index cce19e7..029f276 100644
--- a/Driver/ASTStreamers.cpp
+++ b/Driver/ASTStreamers.cpp
@@ -131,6 +131,31 @@
 
 ASTConsumer *clang::CreateASTDumper() { return new ASTDumper(); }
 
+namespace {
+  class ASTViewer : public ASTConsumer {
+    SourceManager *SM;
+  public:
+    void Initialize(ASTContext &Context, unsigned MainFileID) {
+      SM = &Context.SourceMgr;
+    }
+    
+    virtual void HandleTopLevelDecl(Decl *D) {
+      if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+        PrintFunctionDeclStart(FD);
+        
+        if (FD->getBody()) {
+          fprintf(stderr, "\n");
+          FD->getBody()->viewAST();
+          fprintf(stderr, "\n");
+        }
+      }
+    }
+  };
+}
+
+ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); }
+
+
 //===----------------------------------------------------------------------===//
 // CFGVisitor & VisitCFGs - Boilerplate interface and logic to visit
 //   the CFGs for all function definitions.