[cfe-commits] r63045 - in /cfe/trunk: Driver/CacheTokens.cpp lib/Lex/PTHLexer.cpp

Ted Kremenek kremenek at apple.com
Mon Jan 26 13:43:14 PST 2009


Author: kremenek
Date: Mon Jan 26 15:43:14 2009
New Revision: 63045

URL: http://llvm.org/viewvc/llvm-project?rev=63045&view=rev
Log:
Embed the offset of the PTH table inside the prologue of the PTH file.  This will help improve gradual versioning of PTH files instead of relying that the PTH table is at a fixed offset.

Modified:
    cfe/trunk/Driver/CacheTokens.cpp
    cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/Driver/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/CacheTokens.cpp?rev=63045&r1=63044&r2=63045&view=diff

==============================================================================
--- cfe/trunk/Driver/CacheTokens.cpp (original)
+++ cfe/trunk/Driver/CacheTokens.cpp Mon Jan 26 15:43:14 2009
@@ -454,6 +454,11 @@
 }
 
 void PTHWriter::GeneratePTH() {
+  // Generate the prologue.
+  Out << "cfe-pth";
+  Offset JumpOffset = Out.tell();
+  Emit32(0);
+  
   // Iterate over all the files in SourceManager.  Create a lexer
   // for each file and cache the tokens.
   SourceManager &SM = PP.getSourceManager();
@@ -490,10 +495,15 @@
   Offset FileTableOff = EmitFileTable();  
   
   // Finally, write out the offset table at the end.
+  Offset JumpTargetOffset = Out.tell();    
   Emit32(IdTableOff.first);
   Emit32(IdTableOff.second.first);
   Emit32(IdTableOff.second.second);
   Emit32(FileTableOff);
+  
+  // Now write the offset in the prologue.
+  Out.seek(JumpOffset);
+  Emit32(JumpTargetOffset);
 }
 
 void clang::CacheTokens(Preprocessor& PP, const std::string& OutFile) {

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=63045&r1=63044&r2=63045&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Mon Jan 26 15:43:14 2009
@@ -520,17 +520,18 @@
   // words at the end of the file.
   const unsigned char* BufBeg = (unsigned char*)File->getBufferStart();
   const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd();
-  
-  if(!(BufEnd > BufBeg + sizeof(uint32_t)*3)) {
-    assert(false && "Invalid PTH file.");
-    return 0; // FIXME: Proper error diagnostic?
-  }
+
+  // Check the prologue of the file.
+  if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3) ||
+      memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0)
+    return 0;
   
   // Compute the address of the index table at the end of the PTH file.
-  // This table contains the offset of the file lookup table, the
-  // persistent ID -> identifer data table.
-  // FIXME: We should just embed this offset in the PTH file.
-  const unsigned char* EndTable = BufEnd - sizeof(uint32_t)*4;
+  const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
+  const unsigned char *EndTable = BufBeg + ReadLE32(p);
+  
+  if (EndTable >= BufEnd)
+    return 0;
   
   // Construct the file lookup table.  This will be used for mapping from
   // FileEntry*'s to cached tokens.





More information about the cfe-commits mailing list