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

Sebastian Redl sebastian.redl at getdesigned.at
Fri Jul 16 17:12:06 PDT 2010


Author: cornedbee
Date: Fri Jul 16 19:12:06 2010
New Revision: 108578

URL: http://llvm.org/viewvc/llvm-project?rev=108578&view=rev
Log:
Teach the PCH reader to load the dependency when encountering a chain metadata record. WIP

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=108578&r1=108577&r2=108578&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Fri Jul 16 19:12:06 2010
@@ -531,8 +531,7 @@
 
   void MaybeAddSystemRootToFilename(std::string &Filename);
 
-  PCHReadResult OpenPCH(llvm::StringRef FileName);
-  PCHReadResult ReadChainedPCH(llvm::StringRef FileName);
+  PCHReadResult ReadPCHCore(llvm::StringRef FileName);
   PCHReadResult ReadPCHBlock(PerFileData &F);
   bool CheckPredefinesBuffers();
   bool ParseLineTable(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=108578&r1=108577&r2=108578&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Jul 16 19:12:06 2010
@@ -1447,6 +1447,39 @@
     default:  // Default behavior: ignore.
       break;
 
+    case pch::METADATA: {
+      if (Record[0] != pch::VERSION_MAJOR) {
+        Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old
+                                           : diag::warn_pch_version_too_new);
+        return IgnorePCH;
+      }
+
+      RelocatablePCH = Record[4];
+      if (Listener) {
+        std::string TargetTriple(BlobStart, BlobLen);
+        if (Listener->ReadTargetTriple(TargetTriple))
+          return IgnorePCH;
+      }
+      break;
+    }
+
+    case pch::CHAINED_METADATA: {
+      if (Record[0] != pch::VERSION_MAJOR) {
+        Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old
+                                           : diag::warn_pch_version_too_new);
+        return IgnorePCH;
+      }
+
+      // Load the chained file.
+      switch(ReadPCHCore(llvm::StringRef(BlobStart, BlobLen))) {
+      case Failure: return Failure;
+        // If we have to ignore the dependency, we'll have to ignore this too.
+      case IgnorePCH: return IgnorePCH;
+      case Success: break;
+      }
+      break;
+    }
+
     case pch::TYPE_OFFSET:
       if (!TypesLoaded.empty()) {
         Error("duplicate TYPE_OFFSET record in PCH file");
@@ -1470,22 +1503,6 @@
         return IgnorePCH;
       break;
 
-    case pch::METADATA: {
-      if (Record[0] != pch::VERSION_MAJOR) {
-        Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old
-                                           : diag::warn_pch_version_too_new);
-        return IgnorePCH;
-      }
-
-      RelocatablePCH = Record[4];
-      if (Listener) {
-        std::string TargetTriple(BlobStart, BlobLen);
-        if (Listener->ReadTargetTriple(TargetTriple))
-          return IgnorePCH;
-      }
-      break;
-    }
-
     case pch::IDENTIFIER_TABLE:
       IdentifierTableData = BlobStart;
       if (Record[0]) {
@@ -1658,64 +1675,13 @@
 }
 
 PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
-  switch(OpenPCH(FileName)) {
+  switch(ReadPCHCore(FileName)) {
   case Failure: return Failure;
   case IgnorePCH: return IgnorePCH;
   case Success: break;
   }
-  PerFileData &F = *Chain.back();
-  llvm::BitstreamCursor &Stream = F.Stream;
 
-  while (!Stream.AtEndOfStream()) {
-    unsigned Code = Stream.ReadCode();
-
-    if (Code != llvm::bitc::ENTER_SUBBLOCK) {
-      Error("invalid record at top-level of PCH file");
-      return Failure;
-    }
-
-    unsigned BlockID = Stream.ReadSubBlockID();
-
-    // We only know the PCH subblock ID.
-    switch (BlockID) {
-    case llvm::bitc::BLOCKINFO_BLOCK_ID:
-      if (Stream.ReadBlockInfoBlock()) {
-        Error("malformed BlockInfoBlock in PCH file");
-        return Failure;
-      }
-      break;
-    case pch::PCH_BLOCK_ID:
-      switch (ReadPCHBlock(F)) {
-      case Success:
-        break;
-
-      case Failure:
-        return Failure;
-
-      case IgnorePCH:
-        // FIXME: We could consider reading through to the end of this
-        // PCH block, skipping subblocks, to see if there are other
-        // PCH blocks elsewhere.
-
-        // Clear out any preallocated source location entries, so that
-        // the source manager does not try to resolve them later.
-        SourceMgr.ClearPreallocatedSLocEntries();
-
-        // Remove the stat cache.
-        if (F.StatCache)
-          FileMgr.removeStatCache((PCHStatCache*)F.StatCache);
-
-        return IgnorePCH;
-      }
-      break;
-    default:
-      if (Stream.SkipBlock()) {
-        Error("malformed block record in PCH file");
-        return Failure;
-      }
-      break;
-    }
-  }
+  // Here comes stuff that we only do once the entire chain is loaded.
 
   // Check the predefines buffers.
   if (CheckPredefinesBuffers())
@@ -1762,7 +1728,7 @@
   return Success;
 }
 
-PCHReader::PCHReadResult PCHReader::OpenPCH(llvm::StringRef FileName) {
+PCHReader::PCHReadResult PCHReader::ReadPCHCore(llvm::StringRef FileName) {
   Chain.push_back(new PerFileData());
   PerFileData &F = *Chain.back();
 
@@ -1793,15 +1759,58 @@
     Diag(diag::err_not_a_pch_file) << FileName;
     return Failure;
   }
-  return Success;
-}
 
-PCHReader::PCHReadResult PCHReader::ReadChainedPCH(llvm::StringRef FileName) {
-  switch(OpenPCH(FileName)) {
-  case Failure: return Failure;
-  case IgnorePCH: return IgnorePCH;
-  case Success: break;
+  while (!Stream.AtEndOfStream()) {
+    unsigned Code = Stream.ReadCode();
+
+    if (Code != llvm::bitc::ENTER_SUBBLOCK) {
+      Error("invalid record at top-level of PCH file");
+      return Failure;
+    }
+
+    unsigned BlockID = Stream.ReadSubBlockID();
+
+    // We only know the PCH subblock ID.
+    switch (BlockID) {
+    case llvm::bitc::BLOCKINFO_BLOCK_ID:
+      if (Stream.ReadBlockInfoBlock()) {
+        Error("malformed BlockInfoBlock in PCH file");
+        return Failure;
+      }
+      break;
+    case pch::PCH_BLOCK_ID:
+      switch (ReadPCHBlock(F)) {
+      case Success:
+        break;
+
+      case Failure:
+        return Failure;
+
+      case IgnorePCH:
+        // FIXME: We could consider reading through to the end of this
+        // PCH block, skipping subblocks, to see if there are other
+        // PCH blocks elsewhere.
+
+        // Clear out any preallocated source location entries, so that
+        // the source manager does not try to resolve them later.
+        SourceMgr.ClearPreallocatedSLocEntries();
+
+        // Remove the stat cache.
+        if (F.StatCache)
+          FileMgr.removeStatCache((PCHStatCache*)F.StatCache);
+
+        return IgnorePCH;
+      }
+      break;
+    default:
+      if (Stream.SkipBlock()) {
+        Error("malformed block record in PCH file");
+        return Failure;
+      }
+      break;
+    }
   }
+
   return Success;
 }
 





More information about the cfe-commits mailing list