Arrange for the preprocessor to be passed down into the PCH writer.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68790 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/ASTConsumers.h b/tools/clang-cc/ASTConsumers.h
index e7bc962..d433d05 100644
--- a/tools/clang-cc/ASTConsumers.h
+++ b/tools/clang-cc/ASTConsumers.h
@@ -55,35 +55,33 @@
                                    Diagnostic &Diags,
                                    const LangOptions &Features,
                                    const CompileOptions &CompileOpts,
-                                   const std::string& InFile,
-                                   const std::string& OutFile);
+                                   const std::string &InFile,
+                                   const std::string &OutFile);
 
 ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D,
-                               Preprocessor *PP, PreprocessorFactory* PPF);
+                               Preprocessor *PP, PreprocessorFactory *PPF);
 
 ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
-                                     FileManager& FMgr);
+                                     FileManager &FMgr);
   
-ASTConsumer *CreateASTSerializer(const std::string& InFile,
-                                 const std::string& EmitDir,
+ASTConsumer *CreateASTSerializer(const std::string &InFile,
+                                 const std::string &EmitDir,
                                  Diagnostic &Diags);
   
-ASTConsumer *CreatePCHGenerator(Diagnostic &Diags,
-                                const LangOptions &Features,
-                                const std::string& InFile,
-                                const std::string& OutFile);
+ASTConsumer *CreatePCHGenerator(Preprocessor &PP,
+                                const std::string &OutFile);
 
-ASTConsumer *CreateBlockRewriter(const std::string& InFile,
-                                 const std::string& OutFile,
+ASTConsumer *CreateBlockRewriter(const std::string &InFile,
+                                 const std::string &OutFile,
                                  Diagnostic &Diags,
                                  const LangOptions &LangOpts);
   
 ASTConsumer *CreateInheritanceViewer(const std::string& clsname);
 
-ASTConsumer* CreateAnalysisConsumer(Diagnostic &diags, Preprocessor* pp,
-                                    PreprocessorFactory* ppf,
-                                    const LangOptions& lopts,
-                                    const std::string& output);
+ASTConsumer* CreateAnalysisConsumer(Diagnostic &diags, Preprocessor *pp,
+                                    PreprocessorFactory *ppf,
+                                    const LangOptions &lopts,
+                                    const std::string &output);
 
 } // end clang namespace
 
diff --git a/tools/clang-cc/GeneratePCH.cpp b/tools/clang-cc/GeneratePCH.cpp
index a233348..a850c58 100644
--- a/tools/clang-cc/GeneratePCH.cpp
+++ b/tools/clang-cc/GeneratePCH.cpp
@@ -12,9 +12,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ASTConsumers.h"
 #include "clang/Frontend/PCHWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include "llvm/System/Path.h"
 #include "llvm/Support/Compiler.h"
@@ -27,19 +29,19 @@
 
 namespace {
   class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
-    Diagnostic &Diags;
+    Preprocessor &PP;
     std::string OutFile;
 
   public:
-    explicit PCHGenerator(Diagnostic &Diags, const std::string &OutFile)
-      : Diags(Diags), OutFile(OutFile) { }
+    explicit PCHGenerator(Preprocessor &PP, const std::string &OutFile)
+      : PP(PP), OutFile(OutFile) { }
 
     virtual void HandleTranslationUnit(ASTContext &Ctx);
   };
 }
 
 void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
-  if (Diags.hasErrorOccurred())
+  if (PP.getDiagnostics().hasErrorOccurred())
     return;
 
  // Write the PCH contents into a buffer
@@ -48,7 +50,7 @@
   PCHWriter Writer(Stream);
 
   // Emit the PCH file
-  Writer.WritePCH(Ctx);
+  Writer.WritePCH(Ctx, PP);
 
   // Open up the PCH file.
   std::string ErrMsg;
@@ -66,13 +68,7 @@
   Out.flush();
 }
 
-namespace clang {
-
-ASTConsumer *CreatePCHGenerator(Diagnostic &Diags,
-                                const LangOptions &Features,
-                                const std::string& InFile,
-                                const std::string& OutFile) {
-  return new PCHGenerator(Diags, OutFile);
-}
-
+ASTConsumer *clang::CreatePCHGenerator(Preprocessor &PP,
+                                       const std::string &OutFile) {
+  return new PCHGenerator(PP, OutFile);
 }
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 2580768..8e29dde 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1529,7 +1529,8 @@
     return CreateASTSerializer(InFile, OutputFile, Diag);
     
   case GeneratePCH:
-    return CreatePCHGenerator(Diag, LangOpts, InFile, OutputFile);    
+    assert(PP && "Generate PCH doesn't work from serialized file yet");
+    return CreatePCHGenerator(*PP, OutputFile);    
 
   case RewriteObjC:
     return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);