Index: tools/clang/tools/clang-ast-dump/ClangASTDump.cpp
===================================================================
--- tools/clang/tools/clang-ast-dump/ClangASTDump.cpp	(revision 0)
+++ tools/clang/tools/clang-ast-dump/ClangASTDump.cpp	(revision 0)
@@ -0,0 +1,144 @@
+//===- examples/Tooling/ClangCheck.cpp - Clang check tool -----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file implements a clang-ast-dump tool that dumps specified parts
+//  of an AST of a number of translation units.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/CommandLine.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
+
+using namespace clang::tooling;
+using namespace llvm;
+
+cl::opt<std::string> BuildPath(
+  "p",
+  cl::desc("<build-path>"),
+  cl::Optional);
+
+cl::list<std::string> SourcePaths(
+  cl::Positional,
+  cl::desc("<source0> [... <sourceN>]"),
+  cl::OneOrMore);
+
+cl::opt<std::string> FilterString(
+  "f",
+  cl::desc("<filter-string>"),
+  cl::Optional);
+
+cl::opt<bool> ListAll(
+  "l",
+  cl::desc("list all filterable nodes"),
+  cl::init(false),
+  cl::Optional);
+
+
+namespace {
+  using namespace clang;
+
+  class SelectiveDumpVisitor :
+       public RecursiveASTVisitor<SelectiveDumpVisitor> {
+    typedef RecursiveASTVisitor<SelectiveDumpVisitor> base;
+  public:
+    SelectiveDumpVisitor(const std::string &FilterString, bool ListAll)
+        : FilterString(FilterString), ListAll(ListAll) {}
+
+    ASTConsumer* newASTConsumer() {
+      return new DumpConsumer(this);
+    }
+
+    bool shouldWalkTypesOfTypeLocs() const { return false; }
+
+    bool TraverseDecl(Decl *D) {
+      if (ListAll) {
+        if (isa<TranslationUnitDecl>(D)) {
+          llvm::outs().changeColor(llvm::raw_ostream::BLUE) <<
+              "Listing all filterable nodes:\n";
+          llvm::outs().resetColor();
+        }
+        std::string Name = getName(D);
+        if (!Name.empty())
+          llvm::outs() << Name << "\n";
+        return base::TraverseDecl(D);
+      }
+
+      if (FilterString.empty()) {
+        llvm::outs().changeColor(llvm::raw_ostream::BLUE) <<
+            "Dumping translation unit:\n";
+        llvm::outs().resetColor();
+        D->dumpXML(llvm::outs());
+        return true;
+      }
+
+      if (filterMatches(D)) {
+        llvm::outs().changeColor(llvm::raw_ostream::BLUE) <<
+            "Dumping " << getName(D) << ":\n";
+        llvm::outs().resetColor();
+        D->dumpXML(llvm::outs());
+        return true;
+      }
+      return base::TraverseDecl(D);
+    }
+
+  private:
+    std::string getName(Decl *D) {
+      if (isa<NamedDecl>(D))
+        return cast<NamedDecl>(D)->getQualifiedNameAsString();
+      return "";
+    }
+    bool filterMatches(Decl *D) {
+      return getName(D).find(FilterString) != std::string::npos;
+    }
+
+    class DumpConsumer : public ASTConsumer {
+    public:
+      DumpConsumer(SelectiveDumpVisitor *Visitor) : Visitor(Visitor) {}
+
+      virtual void HandleTranslationUnit(ASTContext &Context) {
+        Visitor->Context = &Context;
+        Visitor->TraverseDecl(Context.getTranslationUnitDecl());
+      }
+
+    private:
+      SelectiveDumpVisitor *Visitor;
+    };
+
+    ASTContext *Context;
+    std::string FilterString;
+    bool ListAll;
+  };
+} // namespace
+
+int main(int argc, const char **argv) {
+  llvm::OwningPtr<CompilationDatabase> Compilations(
+    FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+  cl::ParseCommandLineOptions(argc, argv);
+  if (!Compilations) {
+    std::string ErrorMessage;
+    if (!BuildPath.empty()) {
+      Compilations.reset(
+         CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage));
+
+    } else {
+      Compilations.reset(CompilationDatabase::autoDetectFromSource(
+          SourcePaths[0], ErrorMessage));
+    }
+    if (!Compilations)
+      llvm::report_fatal_error(ErrorMessage);
+  }
+  ClangTool Tool(*Compilations, SourcePaths);
+  SelectiveDumpVisitor Dumper(FilterString, ListAll);
+  return Tool.run(newFrontendActionFactory(&Dumper));
+}
Index: tools/clang/tools/clang-ast-dump/CMakeLists.txt
===================================================================
--- tools/clang/tools/clang-ast-dump/CMakeLists.txt	(revision 0)
+++ tools/clang/tools/clang-ast-dump/CMakeLists.txt	(revision 0)
@@ -0,0 +1,8 @@
+add_clang_executable(clang-ast-dump
+  ClangASTDump.cpp
+  )
+
+target_link_libraries(clang-ast-dump
+  clangTooling
+  clangBasic
+  )
Index: tools/clang/tools/clang-ast-dump/Makefile
===================================================================
--- tools/clang/tools/clang-ast-dump/Makefile	(revision 0)
+++ tools/clang/tools/clang-ast-dump/Makefile	(revision 0)
@@ -0,0 +1,23 @@
+##===- tools/clang-check/Makefile --------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+CLANG_LEVEL := ../..
+
+TOOLNAME = clang-ast-dump
+NO_INSTALL = 1
+
+# No plugins, optimize startup time.
+TOOL_NO_EXPORTS = 1
+
+LINK_COMPONENTS := support mc
+USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \
+           clangTooling.a clangParse.a clangSema.a clangAnalysis.a \
+           clangEdit.a clangAST.a clangLex.a clangBasic.a
+
+include $(CLANG_LEVEL)/Makefile
Index: tools/clang/tools/CMakeLists.txt
===================================================================
--- tools/clang/tools/CMakeLists.txt	(revision 160133)
+++ tools/clang/tools/CMakeLists.txt	(working copy)
@@ -5,3 +5,4 @@
 add_subdirectory(diagtool)
 add_subdirectory(driver)
 add_subdirectory(clang-check)
+add_subdirectory(clang-ast-dump)
Index: tools/clang/tools/Makefile
===================================================================
--- tools/clang/tools/Makefile	(revision 160133)
+++ tools/clang/tools/Makefile	(working copy)
@@ -9,7 +9,7 @@
 
 CLANG_LEVEL := ..
 DIRS := driver libclang c-index-test arcmt-test c-arcmt-test diagtool \
-        clang-check
+        clang-check clang-ast-dump
 
 include $(CLANG_LEVEL)/../../Makefile.config
 
