summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/FrontendActions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r--clang/lib/Frontend/FrontendActions.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 9e863235457..7d54d665146 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -14,6 +14,7 @@
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Frontend/Utils.h"
+#include "clang/Lex/DependencyDirectivesSourceMinimizer.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
@@ -23,8 +24,8 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
#include <memory>
#include <system_error>
@@ -908,3 +909,33 @@ void DumpCompilerOptionsAction::ExecuteAction() {
OS << "}";
}
+
+void PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction() {
+ CompilerInstance &CI = getCompilerInstance();
+ SourceManager &SM = CI.getPreprocessor().getSourceManager();
+ const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
+
+ llvm::SmallString<1024> Output;
+ llvm::SmallVector<minimize_source_to_dependency_directives::Token, 32> Toks;
+ if (minimizeSourceToDependencyDirectives(
+ FromFile->getBuffer(), Output, Toks, &CI.getDiagnostics(),
+ SM.getLocForStartOfFile(SM.getMainFileID()))) {
+ assert(CI.getDiagnostics().hasErrorOccurred() &&
+ "no errors reported for failure");
+
+ // Preprocess the source when verifying the diagnostics to capture the
+ // 'expected' comments.
+ if (CI.getDiagnosticOpts().VerifyDiagnostics) {
+ // Make sure we don't emit new diagnostics!
+ CI.getDiagnostics().setSuppressAllDiagnostics();
+ Preprocessor &PP = getCompilerInstance().getPreprocessor();
+ PP.EnterMainSourceFile();
+ Token Tok;
+ do {
+ PP.Lex(Tok);
+ } while (Tok.isNot(tok::eof));
+ }
+ return;
+ }
+ llvm::outs() << Output;
+}
OpenPOWER on IntegriCloud