[cfe-commits] r60132 - /cfe/trunk/Driver/CacheTokens.cpp
Ted Kremenek
kremenek at apple.com
Wed Nov 26 15:58:26 PST 2008
Author: kremenek
Date: Wed Nov 26 17:58:26 2008
New Revision: 60132
URL: http://llvm.org/viewvc/llvm-project?rev=60132&view=rev
Log:
- Enhance PTH generation to write out IdentifierInfo table in two parts:
- a table including the IdentifierInfo data
- an index from persistent IdentifierInfo IDs to indices within this file.
- Enhance PTH generation to write out file map information, mapping inodes to tokens.
Modified:
cfe/trunk/Driver/CacheTokens.cpp
Modified: cfe/trunk/Driver/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/CacheTokens.cpp?rev=60132&r1=60131&r2=60132&view=diff
==============================================================================
--- cfe/trunk/Driver/CacheTokens.cpp (original)
+++ cfe/trunk/Driver/CacheTokens.cpp Wed Nov 26 17:58:26 2008
@@ -38,6 +38,10 @@
#endif
}
+static void Emit64(llvm::raw_ostream& Out, uint64_t V) {
+ Out << V;
+}
+
static void EmitOffset(llvm::raw_ostream& Out, uint64_t V) {
assert(((uint32_t) V) == V && "Offset exceeds 32 bits.");
Emit32(Out, (uint32_t) V);
@@ -84,36 +88,70 @@
Emit32(Out, X);
}
-static uint64_t EmitIdentifierTable(llvm::raw_fd_ostream& Out,
- const IdentifierTable& T, const IDMap& IM) {
+struct IDData {
+ const IdentifierInfo* II;
+ uint32_t FileOffset;
+ const IdentifierTable::const_iterator::value_type* Str;
+};
+
+static std::pair<uint64_t,uint64_t>
+EmitIdentifierTable(llvm::raw_fd_ostream& Out, uint32_t max,
+ const IdentifierTable& T, const IDMap& IM) {
+
+ // Build an inverse map from persistent IDs -> IdentifierInfo*.
+ typedef std::vector< IDData > InverseIDMap;
+ InverseIDMap IIDMap;
+ IIDMap.reserve(max);
+
+ // Generate mapping from persistent IDs -> IdentifierInfo*.
+ for (IDMap::const_iterator I=IM.begin(), E=IM.end(); I!=E; ++I)
+ IIDMap[I->second].II = I->first;
- // Record the location within the PTH file.
- uint64_t Off = Out.tell();
-
+ // Get the string data associated with the IdentifierInfo.
for (IdentifierTable::const_iterator I=T.begin(), E=T.end(); I!=E; ++I) {
- const IdentifierInfo& II = I->getValue();
-
- // Write out the persistent identifier.
- IDMap::const_iterator IItr = IM.find(&II);
- if (IItr == IM.end()) continue;
- Emit32(Out, IItr->second);
- EmitIdentifier(Out, II);
-
- // Write out the keyword.
- unsigned len = I->getKeyLength();
+ IDMap::const_iterator IDI = IM.find(&(I->getValue()));
+ if (IDI == IM.end()) continue;
+ IIDMap[IDI->second].Str = &(*I);
+ }
+
+ uint64_t DataOff = Out.tell();
+
+ for (InverseIDMap::iterator I=IIDMap.begin(), E=IIDMap.end(); I!=E; ++I) {
+ I->FileOffset = Out.tell(); // Record the location for this data.
+ EmitIdentifier(Out, *(I->II)); // Write out the identifier data.
+ unsigned len = I->Str->getKeyLength(); // Write out the keyword.
Emit32(Out, len);
- const char* buf = I->getKeyData();
+ const char* buf = I->Str->getKeyData();
EmitBuf(Out, buf, buf+len);
}
- return Off;
+ // Now emit the table mapping from persistent IDs to PTH file offsets.
+ uint64_t IDOff = Out.tell();
+
+ for (InverseIDMap::iterator I=IIDMap.begin(), E=IIDMap.end(); I!=E; ++I)
+ EmitOffset(Out, I->FileOffset);
+
+ return std::make_pair(DataOff, IDOff);
}
static uint64_t EmitFileTable(llvm::raw_fd_ostream& Out, SourceManager& SM,
PCHMap& PM) {
uint64_t off = Out.tell();
- assert (0 && "Write out the table.");
+
+ // Output the size of the table.
+ Emit32(Out, PM.size());
+
+ for (PCHMap::iterator I=PM.begin(), E=PM.end(); I!=E; ++I) {
+ // For now emit inode information. In the future we should utilize
+ // the FileManager's internal mechanism of uniquing files, which differs
+ // for Windows and Unix-like systems.
+ const FileEntry* FE = I->first;
+ Emit64(Out, FE->getDevice());
+ Emit64(Out, FE->getInode());
+ Emit32(Out, I->second);
+ }
+
return off;
}
@@ -213,12 +251,14 @@
}
// Write out the identifier table.
- uint64_t IdTableOff = EmitIdentifierTable(Out, PP.getIdentifierTable(), IM);
+ std::pair<uint64_t,uint64_t> IdTableOff =
+ EmitIdentifierTable(Out, idcount, PP.getIdentifierTable(), IM);
// Write out the file table.
uint64_t FileTableOff = EmitFileTable(Out, SM, PM);
// Finally, write out the offset table at the end.
- EmitOffset(Out, IdTableOff);
+ EmitOffset(Out, IdTableOff.first);
+ EmitOffset(Out, IdTableOff.second);
EmitOffset(Out, FileTableOff);
}
More information about the cfe-commits
mailing list