]> granicus.if.org Git - clang/commitdiff
Split the normal and chained PCH writing paths and add a tiny bit of implementation...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 12 Jul 2010 22:02:52 +0000 (22:02 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 12 Jul 2010 22:02:52 +0000 (22:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108200 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHWriter.h
lib/Frontend/PCHWriter.cpp

index c23dde6fd59d09a1b2c66864e83ed095aa7f96a1..3d63c5e0f7eac5199ba5787c1aa58272ce8387b0 100644 (file)
@@ -238,6 +238,11 @@ private:
   unsigned ParmVarDeclAbbrev;
   void WriteDeclsBlockAbbrevs();
   void WriteDecl(ASTContext &Context, Decl *D);
+
+  void WritePCHCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
+                    const char* isysroot);
+  void WritePCHChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
+                     const PCHReader *Chain, const char* isysroot);
   
 public:
   /// \brief Create a new precompiled header writer that outputs to
index 10701d1a25e160655e5361371c13a2ad38f58b36..8d116a3993868da270b57f20a34baa82c41a6915 100644 (file)
@@ -2083,11 +2083,6 @@ PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream)
 
 void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
                          const PCHReader *Chain, const char *isysroot) {
-  using namespace llvm;
-
-  ASTContext &Context = SemaRef.Context;
-  Preprocessor &PP = SemaRef.PP;
-
   // Emit the file header.
   Stream.Emit((unsigned)'C', 8);
   Stream.Emit((unsigned)'P', 8);
@@ -2096,6 +2091,19 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
 
   WriteBlockInfoBlock();
 
+  if (Chain)
+    WritePCHChain(SemaRef, StatCalls, Chain, isysroot);
+  else
+    WritePCHCore(SemaRef, StatCalls, isysroot);
+}
+
+void PCHWriter::WritePCHCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
+                             const char *isysroot) {
+  using namespace llvm;
+
+  ASTContext &Context = SemaRef.Context;
+  Preprocessor &PP = SemaRef.PP;
+
   // The translation unit is the first declaration we'll emit.
   DeclIDs[Context.getTranslationUnitDecl()] = 1;
   DeclTypesToEmit.push(Context.getTranslationUnitDecl());
@@ -2158,9 +2166,8 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   // Write the remaining PCH contents.
   RecordData Record;
   Stream.EnterSubblock(pch::PCH_BLOCK_ID, 5);
-  WriteMetadata(Context, Chain, isysroot);
-  if (!Chain)
-    WriteLanguageOptions(Context.getLangOptions());
+  WriteMetadata(Context, 0, isysroot);
+  WriteLanguageOptions(Context.getLangOptions());
   if (StatCalls && !isysroot)
     WriteStatCache(*StatCalls, isysroot);
   WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
@@ -2269,6 +2276,64 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   Stream.ExitBlock();
 }
 
+void PCHWriter::WritePCHChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
+                              const PCHReader *Chain, const char *isysroot) {
+  using namespace llvm;
+
+  ASTContext &Context = SemaRef.Context;
+  Preprocessor &PP = SemaRef.PP;
+  (void)PP;
+  
+  RecordData Record;
+  Stream.EnterSubblock(pch::PCH_BLOCK_ID, 5);
+  WriteMetadata(Context, Chain, isysroot);
+  // FIXME: StatCache
+  // FIXME: Source manager block
+
+  // The special types are in the chained PCH.
+
+  // We don't start with the translation unit, but with its decls that
+  // don't come from the other PCH.
+  const TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
+  // FIXME: We don't want to iterate over everything here, because it needlessly
+  // deserializes the entire original PCH. Instead we only want to iterate over
+  // the stuff that's already there.
+  // All in good time, though.
+  for (DeclContext::decl_iterator I = TU->decls_begin(), E = TU->decls_end();
+       I != E; ++I) {
+    if ((*I)->getPCHLevel() == 0) {
+      (*I)->dump();
+      DeclTypesToEmit.push(*I);
+    }
+  }
+
+  Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3);
+  WriteDeclsBlockAbbrevs();
+  while (!DeclTypesToEmit.empty()) {
+    DeclOrType DOT = DeclTypesToEmit.front();
+    DeclTypesToEmit.pop();
+    if (DOT.isType())
+      WriteType(DOT.getType());
+    else
+      WriteDecl(Context, DOT.getDecl());
+  }
+  Stream.ExitBlock();
+
+  // FIXME: Preprocessor
+  // FIXME: Method pool
+  // FIXME: Identifier table
+  // FIXME: Type offsets
+  // FIXME: Declaration offsets
+  // FIXME: External unnamed definitions
+  // FIXME: Tentative definitions
+  // FIXME: Unused static functions
+  // FIXME: Locally-scoped external definitions
+  // FIXME: ext_vector type names
+  // FIXME: Dynamic classes declarations
+  // FIXME: Statistics
+  Stream.ExitBlock();
+}
+
 void PCHWriter::AddSourceLocation(SourceLocation Loc, RecordData &Record) {
   Record.push_back(Loc.getRawEncoding());
 }