]> granicus.if.org Git - clang/commitdiff
Arrange for the preprocessor to be passed down into the PCH writer.
authorChris Lattner <sabre@nondot.org>
Fri, 10 Apr 2009 17:15:23 +0000 (17:15 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 10 Apr 2009 17:15:23 +0000 (17:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68790 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHWriter.h
lib/Frontend/PCHWriter.cpp
tools/clang-cc/ASTConsumers.h
tools/clang-cc/GeneratePCH.cpp
tools/clang-cc/clang-cc.cpp

index 9b5f15ecf7e34fba72c36dba547057756f63ce24..01eb2b0a77428b9cace45f23b42d37de0b98e22f 100644 (file)
@@ -29,8 +29,9 @@ namespace llvm {
 
 namespace clang {
 
-class ASTContext;
 class SourceManager;
+class Preprocessor;
+class ASTContext;
 
 /// \brief Writes a precompiled header containing the contents of a
 /// translation unit.
@@ -76,6 +77,7 @@ class PCHWriter {
   unsigned NextTypeID;
 
   void WriteSourceManagerBlock(SourceManager &SourceMgr);
+  void WritePreprocessor(Preprocessor &PP);
   void WriteType(const Type *T);
   void WriteTypesBlock(ASTContext &Context);
   uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
@@ -90,7 +92,7 @@ public:
   PCHWriter(llvm::BitstreamWriter &S);
   
   /// \brief Write a precompiled header for the given AST context.
-  void WritePCH(ASTContext &Context);
+  void WritePCH(ASTContext &Context, Preprocessor &PP);
 
   /// \brief Emit a source location.
   void AddSourceLocation(SourceLocation Loc, RecordData &Record);
index d4961e4e744ff7141b02b801b8e9196cd418d339..b60fc2f4b6abbb267151c7e7a3e0681c5a92eb84 100644 (file)
@@ -474,6 +474,13 @@ void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr) {
   S.ExitBlock();
 }
 
+/// \brief Writes the block containing the serialized form of the
+/// preprocessor.
+///
+void PCHWriter::WritePreprocessor(Preprocessor &PP) {
+}
+
+
 /// \brief Write the representation of a type to the PCH stream.
 void PCHWriter::WriteType(const Type *T) {
   pch::ID &ID = TypeIDs[T];
@@ -659,7 +666,7 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) {
 PCHWriter::PCHWriter(llvm::BitstreamWriter &S) 
   : S(S), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
 
-void PCHWriter::WritePCH(ASTContext &Context) {
+void PCHWriter::WritePCH(ASTContext &Context, Preprocessor &PP) {
   // Emit the file header.
   S.Emit((unsigned)'C', 8);
   S.Emit((unsigned)'P', 8);
@@ -673,6 +680,7 @@ void PCHWriter::WritePCH(ASTContext &Context) {
   // Write the remaining PCH contents.
   S.EnterSubblock(pch::PCH_BLOCK_ID, 2);
   WriteSourceManagerBlock(Context.getSourceManager());
+  WritePreprocessor(PP);
   WriteTypesBlock(Context);
   WriteDeclsBlock(Context);
   S.ExitBlock();
index e7bc962bd922ef8c868049238bc2a4c0f7476b04..d433d05b02f93a32499b78fcb6765d1fc84cd969 100644 (file)
@@ -55,35 +55,33 @@ ASTConsumer *CreateBackendConsumer(BackendAction Action,
                                    Diagnostic &Diags,
                                    const LangOptions &Features,
                                    const CompileOptions &CompileOpts,
-                                   const std::stringInFile,
-                                   const std::stringOutFile);
+                                   const std::string &InFile,
+                                   const std::string &OutFile);
 
 ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D,
-                               Preprocessor *PP, PreprocessorFactoryPPF);
+                               Preprocessor *PP, PreprocessorFactory *PPF);
 
 ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
-                                     FileManagerFMgr);
+                                     FileManager &FMgr);
   
-ASTConsumer *CreateASTSerializer(const std::stringInFile,
-                                 const std::stringEmitDir,
+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::stringInFile,
-                                 const std::stringOutFile,
+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, Preprocessorpp,
-                                    PreprocessorFactoryppf,
-                                    const LangOptionslopts,
-                                    const std::stringoutput);
+ASTConsumer* CreateAnalysisConsumer(Diagnostic &diags, Preprocessor *pp,
+                                    PreprocessorFactory *ppf,
+                                    const LangOptions &lopts,
+                                    const std::string &output);
 
 } // end clang namespace
 
index a2333487188fcab55ed99d3ac5f26391d97a26e3..a850c582e8164fabfa891b6ddc156f43b4cec2d2 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#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 @@ using namespace llvm;
 
 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 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
   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 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
   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);
 }
index 258076836a8e2924cc5c0c9435fe25f345a97d1e..8e29dded845b9ff15fcaab36ed093d301c05f07d 100644 (file)
@@ -1529,7 +1529,8 @@ static ASTConsumer *CreateASTConsumer(const std::string& InFile,
     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);