[cfe-commits] r108200 - in /cfe/trunk: include/clang/Frontend/PCHWriter.h lib/Frontend/PCHWriter.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Jul 12 15:02:52 PDT 2010


Author: cornedbee
Date: Mon Jul 12 17:02:52 2010
New Revision: 108200

URL: http://llvm.org/viewvc/llvm-project?rev=108200&view=rev
Log:
Split the normal and chained PCH writing paths and add a tiny bit of implementation to the latter. WIP.

Modified:
    cfe/trunk/include/clang/Frontend/PCHWriter.h
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=108200&r1=108199&r2=108200&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Mon Jul 12 17:02:52 2010
@@ -238,6 +238,11 @@
   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

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=108200&r1=108199&r2=108200&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Jul 12 17:02:52 2010
@@ -2083,11 +2083,6 @@
 
 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 @@
 
   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 @@
   // 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 @@
   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());
 }





More information about the cfe-commits mailing list