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

Sebastian Redl sebastian.redl at getdesigned.at
Mon Jul 19 13:52:06 PDT 2010


Author: cornedbee
Date: Mon Jul 19 15:52:06 2010
New Revision: 108748

URL: http://llvm.org/viewvc/llvm-project?rev=108748&view=rev
Log:
Promote the identifier table to per-file data. Also, if a CHAINED_METADATA record exists, it has to be the first thing in the PCH file.

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=108748&r1=108747&r2=108748&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Mon Jul 19 15:52:06 2010
@@ -233,6 +233,16 @@
 
     /// \brief The number of declarations in this PCH file.
     unsigned LocalNumDecls;
+
+    /// \brief Actual data for the on-disk hash table.
+    ///
+    // This pointer points into a memory buffer, where the on-disk hash
+    // table for identifiers actually lives.
+    const char *IdentifierTableData;
+
+    /// \brief A pointer to an on-disk hash table of opaque type
+    /// IdentifierHashTable.
+    void *IdentifierLookupTable;
   };
 
   /// \brief The chain of PCH files. The first entry is the one named by the
@@ -276,16 +286,6 @@
   /// DeclContext.
   DeclContextOffsetsMap DeclContextOffsets;
 
-  /// \brief Actual data for the on-disk hash table.
-  ///
-  // This pointer points into a memory buffer, where the on-disk hash
-  // table for identifiers actually lives.
-  const char *IdentifierTableData;
-
-  /// \brief A pointer to an on-disk hash table of opaque type
-  /// IdentifierHashTable.
-  void *IdentifierLookupTable;
-
   /// \brief Offsets into the identifier table data.
   ///
   /// This array is indexed by the identifier ID (-1), and provides
@@ -534,8 +534,8 @@
   PCHReadResult ReadPCHCore(llvm::StringRef FileName);
   PCHReadResult ReadPCHBlock(PerFileData &F);
   bool CheckPredefinesBuffers();
-  bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record);
-  PCHReadResult ReadSourceManagerBlock();
+  bool ParseLineTable(PerFileData &F, llvm::SmallVectorImpl<uint64_t> &Record);
+  PCHReadResult ReadSourceManagerBlock(PerFileData &F);
   PCHReadResult ReadSLocEntryRecord(unsigned ID);
 
   bool ParseLanguageOptions(const llvm::SmallVectorImpl<uint64_t> &Record);

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=108748&r1=108747&r2=108748&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Jul 19 15:52:06 2010
@@ -418,8 +418,7 @@
   : Listener(new PCHValidator(PP, *this)), DeserializationListener(0),
     SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
     Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),
-    Consumer(0), IdentifierTableData(0), IdentifierLookupTable(0),
-    IdentifierOffsets(0),
+    Consumer(0), IdentifierOffsets(0),
     MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
     TotalSelectorsInMethodPool(0), SelectorOffsets(0),
     TotalNumSelectors(0), MacroDefinitionOffsets(0), 
@@ -436,7 +435,6 @@
                      Diagnostic &Diags, const char *isysroot)
   : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr),
     Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),
-    IdentifierTableData(0), IdentifierLookupTable(0),
     IdentifierOffsets(0),
     MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
     TotalSelectorsInMethodPool(0), SelectorOffsets(0),
@@ -456,7 +454,7 @@
 }
 
 PCHReader::PerFileData::PerFileData()
-  : StatCache(0)
+  : StatCache(0), IdentifierTableData(0), IdentifierLookupTable(0)
 {}
 
 
@@ -730,10 +728,14 @@
 
 /// \brief Read the line table in the source manager block.
 /// \returns true if ther was an error.
-bool PCHReader::ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record) {
+bool PCHReader::ParseLineTable(PerFileData &F,
+                               llvm::SmallVectorImpl<uint64_t> &Record) {
   unsigned Idx = 0;
   LineTableInfo &LineTable = SourceMgr.getLineTable();
 
+  // FIXME: Handle multiple tables!
+  (void)F;
+
   // Parse the file names
   std::map<int, int> FileIDs;
   for (int I = 0, N = Record[Idx++]; I != N; ++I) {
@@ -881,20 +883,20 @@
 } // end anonymous namespace
 
 
-/// \brief Read the source manager block
-PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() {
+/// \brief Read a source manager block
+PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock(PerFileData &F) {
   using namespace SrcMgr;
 
-  llvm::BitstreamCursor &SLocEntryCursor = Chain[0]->SLocEntryCursor;
+  llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
 
   // Set the source-location entry cursor to the current position in
   // the stream. This cursor will be used to read the contents of the
   // source manager block initially, and then lazily read
   // source-location entries as needed.
-  SLocEntryCursor = Chain[0]->Stream;
+  SLocEntryCursor = F.Stream;
 
   // The stream itself is going to skip over the source manager block.
-  if (Chain[0]->Stream.SkipBlock()) {
+  if (F.Stream.SkipBlock()) {
     Error("malformed block record in PCH file");
     return Failure;
   }
@@ -940,7 +942,7 @@
       break;
 
     case pch::SM_LINE_TABLE:
-      if (ParseLineTable(Record))
+      if (ParseLineTable(F, Record))
         return Failure;
       break;
 
@@ -1378,6 +1380,7 @@
 
   // Read all of the records and blocks for the PCH file.
   RecordData Record;
+  bool First = true;
   while (!Stream.AtEndOfStream()) {
     unsigned Code = Stream.ReadCode();
     if (Code == llvm::bitc::END_BLOCK) {
@@ -1417,7 +1420,7 @@
         break;
 
       case pch::SOURCE_MANAGER_BLOCK_ID:
-        switch (ReadSourceManagerBlock()) {
+        switch (ReadSourceManagerBlock(F)) {
         case Success:
           break;
 
@@ -1430,6 +1433,7 @@
         }
         break;
       }
+      First = false;
       continue;
     }
 
@@ -1464,6 +1468,10 @@
     }
 
     case pch::CHAINED_METADATA: {
+      if (!First) {
+        Error("CHAINED_METADATA is not first record in block");
+        return Failure;
+      }
       if (Record[0] != pch::VERSION_MAJOR) {
         Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old
                                            : diag::warn_pch_version_too_new);
@@ -1504,13 +1512,13 @@
       break;
 
     case pch::IDENTIFIER_TABLE:
-      IdentifierTableData = BlobStart;
+      F.IdentifierTableData = BlobStart;
       if (Record[0]) {
-        IdentifierLookupTable
+        F.IdentifierLookupTable
           = PCHIdentifierLookupTable::Create(
-                        (const unsigned char *)IdentifierTableData + Record[0],
-                        (const unsigned char *)IdentifierTableData,
-                        PCHIdentifierLookupTrait(*this));
+                       (const unsigned char *)F.IdentifierTableData + Record[0],
+                       (const unsigned char *)F.IdentifierTableData,
+                       PCHIdentifierLookupTrait(*this));
         if (PP)
           PP->getIdentifierTable().setExternalIdentifierLookup(this);
       }
@@ -1669,6 +1677,7 @@
       MacroDefinitionsLoaded.resize(Record[1]);
       break;
     }
+    First = false;
   }
   Error("premature end of bitstream in PCH file");
   return Failure;
@@ -1706,7 +1715,7 @@
          Id != IdEnd; ++Id)
       Identifiers.push_back(Id->second);
     PCHIdentifierLookupTable *IdTable
-      = (PCHIdentifierLookupTable *)IdentifierLookupTable;
+      = (PCHIdentifierLookupTable *)Chain[0]->IdentifierLookupTable;
     for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) {
       IdentifierInfo *II = Identifiers[I];
       // Look in the on-disk hash table for an entry for
@@ -3018,7 +3027,7 @@
 IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) {
   // Try to find this name within our on-disk hash table
   PCHIdentifierLookupTable *IdTable
-    = (PCHIdentifierLookupTable *)IdentifierLookupTable;
+    = (PCHIdentifierLookupTable *)Chain[0]->IdentifierLookupTable;
   std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart);
   PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key);
   if (Pos == IdTable->end())
@@ -3104,7 +3113,7 @@
   if (ID == 0)
     return 0;
 
-  if (!IdentifierTableData || IdentifiersLoaded.empty()) {
+  if (!Chain[0]->IdentifierTableData || IdentifiersLoaded.empty()) {
     Error("no identifier table in PCH file");
     return 0;
   }
@@ -3112,7 +3121,7 @@
   assert(PP && "Forgot to set Preprocessor ?");
   if (!IdentifiersLoaded[ID - 1]) {
     uint32_t Offset = IdentifierOffsets[ID - 1];
-    const char *Str = IdentifierTableData + Offset;
+    const char *Str = Chain[0]->IdentifierTableData + Offset;
 
     // All of the strings in the PCH file are preceded by a 16-bit
     // length. Extract that 16-bit length to avoid having to execute





More information about the cfe-commits mailing list