[PATCH] D59764: [pp-trace] Use ClangTool in pp-trace, NFC

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 25 05:48:51 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE356893: [pp-trace] Use ClangTool in pp-trace, NFC (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59764?vs=192083&id=192089#toc

Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59764/new/

https://reviews.llvm.org/D59764

Files:
  pp-trace/PPTrace.cpp


Index: pp-trace/PPTrace.cpp
===================================================================
--- pp-trace/PPTrace.cpp
+++ pp-trace/PPTrace.cpp
@@ -124,13 +124,11 @@
 
 int main(int argc, const char **argv) {
   using namespace clang::pp_trace;
-
   InitLLVM X(argc, argv);
-  auto Exec =
-      clang::tooling::createExecutorFromCommandLineArgs(argc, argv, Cat);
-  if (!Exec)
-    error(toString(Exec.takeError()));
-
+  auto OptionsParser = clang::tooling::CommonOptionsParser::create(
+      argc, argv, Cat, llvm::cl::ZeroOrMore);
+  if (!OptionsParser)
+    error(toString(OptionsParser.takeError()));
   // Parse the IgnoreCallbacks list into strings.
   SmallVector<StringRef, 32> Patterns;
   FilterType Filters;
@@ -139,20 +137,29 @@
   for (StringRef Pattern : Patterns) {
     Pattern = Pattern.trim();
     bool Enabled = !Pattern.consume_front("-");
-    if (Expected<GlobPattern> Pat = GlobPattern::create(Pattern))
+    Expected<GlobPattern> Pat = GlobPattern::create(Pattern);
+    if (Pat)
       Filters.emplace_back(std::move(*Pat), Enabled);
     else
       error(toString(Pat.takeError()));
   }
 
+  // Create the tool and run the compilation.
+  clang::tooling::ClangTool Tool(OptionsParser->getCompilations(),
+                                 OptionsParser->getSourcePathList());
+
   std::error_code EC;
   llvm::ToolOutputFile Out(OutputFileName, EC, llvm::sys::fs::F_Text);
   if (EC)
     error(EC.message());
+  PPTraceFrontendActionFactory Factory(Filters, Out.os());
+  int HadErrors = Tool.run(&Factory);
+
+  // If we had errors, exit early.
+  if (HadErrors)
+    return HadErrors;
 
-  if (auto Err = Exec->get()->execute(
-          llvm::make_unique<PPTraceFrontendActionFactory>(Filters, Out.os())))
-    error(toString(std::move(Err)));
   Out.keep();
+
   return 0;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59764.192089.patch
Type: text/x-patch
Size: 1814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190325/9c6a4084/attachment-0001.bin>


More information about the cfe-commits mailing list