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

Chris Lattner sabre at nondot.org
Sun Apr 26 18:05:14 PDT 2009


Author: lattner
Date: Sun Apr 26 20:05:14 2009
New Revision: 70173

URL: http://llvm.org/viewvc/llvm-project?rev=70173&view=rev
Log:
Set up DeclsCursor.

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

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=70173&r1=70172&r2=70173&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Sun Apr 26 20:05:14 2009
@@ -87,7 +87,12 @@
 
   /// \brief The bitstream reader from which we'll read the PCH file.
   llvm::BitstreamReader StreamFile;
-  llvm::BitstreamCursor Stream;    
+  llvm::BitstreamCursor Stream;
+
+  /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.  It
+  /// has read all the abbreviations at the start of the block and is ready to
+  /// jump around with these in context.
+  llvm::BitstreamCursor DeclsCursor;
 
   /// \brief The file name of the PCH file.
   std::string FileName;
@@ -292,6 +297,11 @@
   /// LazyOffsetPtr.
   virtual Stmt *GetStmt(uint64_t Offset);
 
+  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
+  /// specified cursor.  Read the abbreviations that are at the top of the block
+  /// and then leave the cursor pointing into the block.
+  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
+
   /// \brief Read all of the declarations lexically stored in a
   /// declaration context.
   ///

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70173&r1=70172&r2=70173&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Sun Apr 26 20:05:14 2009
@@ -1683,6 +1683,27 @@
   }
 }
 
+/// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
+/// specified cursor.  Read the abbreviations that are at the top of the block
+/// and then leave the cursor pointing into the block.
+bool PCHReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
+                                 unsigned BlockID) {
+  if (Cursor.EnterSubBlock(BlockID)) {
+    Error("Malformed block record");
+    return Failure;
+  }
+  
+  RecordData Record;
+  while (true) {
+    unsigned Code = Cursor.ReadCode();
+    
+    // We expect all abbrevs to be at the start of the block.
+    if (Code != llvm::bitc::DEFINE_ABBREV)
+      return false;
+    Cursor.ReadAbbrevRecord();
+  }
+}
+
 void PCHReader::ReadMacroRecord(uint64_t Offset) {
   // Keep track of where we are in the stream, then jump back there
   // after reading this macro.
@@ -1807,7 +1828,6 @@
 
     if (Code == llvm::bitc::ENTER_SUBBLOCK) {
       switch (Stream.ReadSubBlockID()) {
-      case pch::DECLS_BLOCK_ID: // Skip decls block (lazily loaded)
       case pch::TYPES_BLOCK_ID: // Skip types block (lazily loaded)
       default:  // Skip unknown content.
         if (Stream.SkipBlock()) {
@@ -1816,6 +1836,20 @@
         }
         break;
 
+      case pch::DECLS_BLOCK_ID:
+        // We lazily load the decls block, but we want to set up the
+        // DeclsCursor cursor to point into it.  Clone our current bitcode
+        // cursor to it, enter the block and read the abbrevs in that block.
+        // With the main cursor, we just skip over it.
+        DeclsCursor = Stream;
+        if (Stream.SkipBlock() ||  // Skip with the main cursor.
+            // Read the abbrevs.
+            ReadBlockAbbrevs(DeclsCursor, pch::DECLS_BLOCK_ID)) {
+          Error("Malformed block record");
+          return Failure;
+        }
+        break;
+          
       case pch::PREPROCESSOR_BLOCK_ID:
         if (Stream.SkipBlock()) {
           Error("Malformed block record");





More information about the cfe-commits mailing list