CacheTokens.cpp revision 651f13cea278ec967336033dd032faef0e9fc2ec
1//===--- CacheTokens.cpp - Caching of lexer tokens for PTH support --------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This provides a possible implementation of PTH support for Clang that is 11// based on caching lexed tokens and identifiers. 12// 13//===----------------------------------------------------------------------===// 14 15#include "clang/Frontend/Utils.h" 16#include "clang/Basic/Diagnostic.h" 17#include "clang/Basic/FileManager.h" 18#include "clang/Basic/FileSystemStatCache.h" 19#include "clang/Basic/IdentifierTable.h" 20#include "clang/Basic/OnDiskHashTable.h" 21#include "clang/Basic/SourceManager.h" 22#include "clang/Lex/Lexer.h" 23#include "clang/Lex/Preprocessor.h" 24#include "llvm/ADT/StringExtras.h" 25#include "llvm/ADT/StringMap.h" 26#include "llvm/Support/EndianStream.h" 27#include "llvm/Support/FileSystem.h" 28#include "llvm/Support/MemoryBuffer.h" 29#include "llvm/Support/Path.h" 30#include "llvm/Support/raw_ostream.h" 31 32// FIXME: put this somewhere else? 33#ifndef S_ISDIR 34#define S_ISDIR(x) (((x)&_S_IFDIR)!=0) 35#endif 36 37using namespace clang; 38using namespace clang::io; 39 40//===----------------------------------------------------------------------===// 41// PTH-specific stuff. 42//===----------------------------------------------------------------------===// 43 44namespace { 45class PTHEntry { 46 Offset TokenData, PPCondData; 47 48public: 49 PTHEntry() {} 50 51 PTHEntry(Offset td, Offset ppcd) 52 : TokenData(td), PPCondData(ppcd) {} 53 54 Offset getTokenOffset() const { return TokenData; } 55 Offset getPPCondTableOffset() const { return PPCondData; } 56}; 57 58 59class PTHEntryKeyVariant { 60 union { const FileEntry* FE; const char* Path; }; 61 enum { IsFE = 0x1, IsDE = 0x2, IsNoExist = 0x0 } Kind; 62 FileData *Data; 63 64public: 65 PTHEntryKeyVariant(const FileEntry *fe) : FE(fe), Kind(IsFE), Data(0) {} 66 67 PTHEntryKeyVariant(FileData *Data, const char *path) 68 : Path(path), Kind(IsDE), Data(new FileData(*Data)) {} 69 70 explicit PTHEntryKeyVariant(const char *path) 71 : Path(path), Kind(IsNoExist), Data(0) {} 72 73 bool isFile() const { return Kind == IsFE; } 74 75 StringRef getString() const { 76 return Kind == IsFE ? FE->getName() : Path; 77 } 78 79 unsigned getKind() const { return (unsigned) Kind; } 80 81 void EmitData(raw_ostream& Out) { 82 using namespace llvm::support; 83 endian::Writer<little> LE(Out); 84 switch (Kind) { 85 case IsFE: { 86 // Emit stat information. 87 llvm::sys::fs::UniqueID UID = FE->getUniqueID(); 88 LE.write<uint64_t>(UID.getFile()); 89 LE.write<uint64_t>(UID.getDevice()); 90 LE.write<uint64_t>(FE->getModificationTime()); 91 LE.write<uint64_t>(FE->getSize()); 92 } break; 93 case IsDE: 94 // Emit stat information. 95 LE.write<uint64_t>(Data->UniqueID.getFile()); 96 LE.write<uint64_t>(Data->UniqueID.getDevice()); 97 LE.write<uint64_t>(Data->ModTime); 98 LE.write<uint64_t>(Data->Size); 99 delete Data; 100 break; 101 default: 102 break; 103 } 104 } 105 106 unsigned getRepresentationLength() const { 107 return Kind == IsNoExist ? 0 : 4 + 4 + 2 + 8 + 8; 108 } 109}; 110 111class FileEntryPTHEntryInfo { 112public: 113 typedef PTHEntryKeyVariant key_type; 114 typedef key_type key_type_ref; 115 116 typedef PTHEntry data_type; 117 typedef const PTHEntry& data_type_ref; 118 119 static unsigned ComputeHash(PTHEntryKeyVariant V) { 120 return llvm::HashString(V.getString()); 121 } 122 123 static std::pair<unsigned,unsigned> 124 EmitKeyDataLength(raw_ostream& Out, PTHEntryKeyVariant V, 125 const PTHEntry& E) { 126 using namespace llvm::support; 127 endian::Writer<little> LE(Out); 128 129 unsigned n = V.getString().size() + 1 + 1; 130 LE.write<uint16_t>(n); 131 132 unsigned m = V.getRepresentationLength() + (V.isFile() ? 4 + 4 : 0); 133 LE.write<uint8_t>(m); 134 135 return std::make_pair(n, m); 136 } 137 138 static void EmitKey(raw_ostream& Out, PTHEntryKeyVariant V, unsigned n){ 139 using namespace llvm::support; 140 // Emit the entry kind. 141 endian::Writer<little>(Out).write<uint8_t>((unsigned)V.getKind()); 142 // Emit the string. 143 Out.write(V.getString().data(), n - 1); 144 } 145 146 static void EmitData(raw_ostream& Out, PTHEntryKeyVariant V, 147 const PTHEntry& E, unsigned) { 148 using namespace llvm::support; 149 endian::Writer<little> LE(Out); 150 151 // For file entries emit the offsets into the PTH file for token data 152 // and the preprocessor blocks table. 153 if (V.isFile()) { 154 LE.write<uint32_t>(E.getTokenOffset()); 155 LE.write<uint32_t>(E.getPPCondTableOffset()); 156 } 157 158 // Emit any other data associated with the key (i.e., stat information). 159 V.EmitData(Out); 160 } 161}; 162 163class OffsetOpt { 164 bool valid; 165 Offset off; 166public: 167 OffsetOpt() : valid(false) {} 168 bool hasOffset() const { return valid; } 169 Offset getOffset() const { assert(valid); return off; } 170 void setOffset(Offset o) { off = o; valid = true; } 171}; 172} // end anonymous namespace 173 174typedef OnDiskChainedHashTableGenerator<FileEntryPTHEntryInfo> PTHMap; 175 176namespace { 177class PTHWriter { 178 typedef llvm::DenseMap<const IdentifierInfo*,uint32_t> IDMap; 179 typedef llvm::StringMap<OffsetOpt, llvm::BumpPtrAllocator> CachedStrsTy; 180 181 IDMap IM; 182 llvm::raw_fd_ostream& Out; 183 Preprocessor& PP; 184 uint32_t idcount; 185 PTHMap PM; 186 CachedStrsTy CachedStrs; 187 Offset CurStrOffset; 188 std::vector<llvm::StringMapEntry<OffsetOpt>*> StrEntries; 189 190 //// Get the persistent id for the given IdentifierInfo*. 191 uint32_t ResolveID(const IdentifierInfo* II); 192 193 /// Emit a token to the PTH file. 194 void EmitToken(const Token& T); 195 196 void Emit8(uint32_t V) { 197 using namespace llvm::support; 198 endian::Writer<little>(Out).write<uint8_t>(V); 199 } 200 201 void Emit16(uint32_t V) { 202 using namespace llvm::support; 203 endian::Writer<little>(Out).write<uint16_t>(V); 204 } 205 206 void Emit32(uint32_t V) { 207 using namespace llvm::support; 208 endian::Writer<little>(Out).write<uint32_t>(V); 209 } 210 211 void EmitBuf(const char *Ptr, unsigned NumBytes) { 212 Out.write(Ptr, NumBytes); 213 } 214 215 void EmitString(StringRef V) { 216 using namespace llvm::support; 217 endian::Writer<little>(Out).write<uint16_t>(V.size()); 218 EmitBuf(V.data(), V.size()); 219 } 220 221 /// EmitIdentifierTable - Emits two tables to the PTH file. The first is 222 /// a hashtable mapping from identifier strings to persistent IDs. 223 /// The second is a straight table mapping from persistent IDs to string data 224 /// (the keys of the first table). 225 std::pair<Offset, Offset> EmitIdentifierTable(); 226 227 /// EmitFileTable - Emit a table mapping from file name strings to PTH 228 /// token data. 229 Offset EmitFileTable() { return PM.Emit(Out); } 230 231 PTHEntry LexTokens(Lexer& L); 232 Offset EmitCachedSpellings(); 233 234public: 235 PTHWriter(llvm::raw_fd_ostream& out, Preprocessor& pp) 236 : Out(out), PP(pp), idcount(0), CurStrOffset(0) {} 237 238 PTHMap &getPM() { return PM; } 239 void GeneratePTH(const std::string &MainFile); 240}; 241} // end anonymous namespace 242 243uint32_t PTHWriter::ResolveID(const IdentifierInfo* II) { 244 // Null IdentifierInfo's map to the persistent ID 0. 245 if (!II) 246 return 0; 247 248 IDMap::iterator I = IM.find(II); 249 if (I != IM.end()) 250 return I->second; // We've already added 1. 251 252 IM[II] = ++idcount; // Pre-increment since '0' is reserved for NULL. 253 return idcount; 254} 255 256void PTHWriter::EmitToken(const Token& T) { 257 // Emit the token kind, flags, and length. 258 Emit32(((uint32_t) T.getKind()) | ((((uint32_t) T.getFlags())) << 8)| 259 (((uint32_t) T.getLength()) << 16)); 260 261 if (!T.isLiteral()) { 262 Emit32(ResolveID(T.getIdentifierInfo())); 263 } else { 264 // We cache *un-cleaned* spellings. This gives us 100% fidelity with the 265 // source code. 266 StringRef s(T.getLiteralData(), T.getLength()); 267 268 // Get the string entry. 269 llvm::StringMapEntry<OffsetOpt> *E = &CachedStrs.GetOrCreateValue(s); 270 271 // If this is a new string entry, bump the PTH offset. 272 if (!E->getValue().hasOffset()) { 273 E->getValue().setOffset(CurStrOffset); 274 StrEntries.push_back(E); 275 CurStrOffset += s.size() + 1; 276 } 277 278 // Emit the relative offset into the PTH file for the spelling string. 279 Emit32(E->getValue().getOffset()); 280 } 281 282 // Emit the offset into the original source file of this token so that we 283 // can reconstruct its SourceLocation. 284 Emit32(PP.getSourceManager().getFileOffset(T.getLocation())); 285} 286 287PTHEntry PTHWriter::LexTokens(Lexer& L) { 288 // Pad 0's so that we emit tokens to a 4-byte alignment. 289 // This speed up reading them back in. 290 Pad(Out, 4); 291 Offset TokenOff = (Offset) Out.tell(); 292 293 // Keep track of matching '#if' ... '#endif'. 294 typedef std::vector<std::pair<Offset, unsigned> > PPCondTable; 295 PPCondTable PPCond; 296 std::vector<unsigned> PPStartCond; 297 bool ParsingPreprocessorDirective = false; 298 Token Tok; 299 300 do { 301 L.LexFromRawLexer(Tok); 302 NextToken: 303 304 if ((Tok.isAtStartOfLine() || Tok.is(tok::eof)) && 305 ParsingPreprocessorDirective) { 306 // Insert an eod token into the token cache. It has the same 307 // position as the next token that is not on the same line as the 308 // preprocessor directive. Observe that we continue processing 309 // 'Tok' when we exit this branch. 310 Token Tmp = Tok; 311 Tmp.setKind(tok::eod); 312 Tmp.clearFlag(Token::StartOfLine); 313 Tmp.setIdentifierInfo(0); 314 EmitToken(Tmp); 315 ParsingPreprocessorDirective = false; 316 } 317 318 if (Tok.is(tok::raw_identifier)) { 319 PP.LookUpIdentifierInfo(Tok); 320 EmitToken(Tok); 321 continue; 322 } 323 324 if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { 325 // Special processing for #include. Store the '#' token and lex 326 // the next token. 327 assert(!ParsingPreprocessorDirective); 328 Offset HashOff = (Offset) Out.tell(); 329 330 // Get the next token. 331 Token NextTok; 332 L.LexFromRawLexer(NextTok); 333 334 // If we see the start of line, then we had a null directive "#". In 335 // this case, discard both tokens. 336 if (NextTok.isAtStartOfLine()) 337 goto NextToken; 338 339 // The token is the start of a directive. Emit it. 340 EmitToken(Tok); 341 Tok = NextTok; 342 343 // Did we see 'include'/'import'/'include_next'? 344 if (Tok.isNot(tok::raw_identifier)) { 345 EmitToken(Tok); 346 continue; 347 } 348 349 IdentifierInfo* II = PP.LookUpIdentifierInfo(Tok); 350 tok::PPKeywordKind K = II->getPPKeywordID(); 351 352 ParsingPreprocessorDirective = true; 353 354 switch (K) { 355 case tok::pp_not_keyword: 356 // Invalid directives "#foo" can occur in #if 0 blocks etc, just pass 357 // them through. 358 default: 359 break; 360 361 case tok::pp_include: 362 case tok::pp_import: 363 case tok::pp_include_next: { 364 // Save the 'include' token. 365 EmitToken(Tok); 366 // Lex the next token as an include string. 367 L.setParsingPreprocessorDirective(true); 368 L.LexIncludeFilename(Tok); 369 L.setParsingPreprocessorDirective(false); 370 assert(!Tok.isAtStartOfLine()); 371 if (Tok.is(tok::raw_identifier)) 372 PP.LookUpIdentifierInfo(Tok); 373 374 break; 375 } 376 case tok::pp_if: 377 case tok::pp_ifdef: 378 case tok::pp_ifndef: { 379 // Add an entry for '#if' and friends. We initially set the target 380 // index to 0. This will get backpatched when we hit #endif. 381 PPStartCond.push_back(PPCond.size()); 382 PPCond.push_back(std::make_pair(HashOff, 0U)); 383 break; 384 } 385 case tok::pp_endif: { 386 // Add an entry for '#endif'. We set the target table index to itself. 387 // This will later be set to zero when emitting to the PTH file. We 388 // use 0 for uninitialized indices because that is easier to debug. 389 unsigned index = PPCond.size(); 390 // Backpatch the opening '#if' entry. 391 assert(!PPStartCond.empty()); 392 assert(PPCond.size() > PPStartCond.back()); 393 assert(PPCond[PPStartCond.back()].second == 0); 394 PPCond[PPStartCond.back()].second = index; 395 PPStartCond.pop_back(); 396 // Add the new entry to PPCond. 397 PPCond.push_back(std::make_pair(HashOff, index)); 398 EmitToken(Tok); 399 400 // Some files have gibberish on the same line as '#endif'. 401 // Discard these tokens. 402 do 403 L.LexFromRawLexer(Tok); 404 while (Tok.isNot(tok::eof) && !Tok.isAtStartOfLine()); 405 // We have the next token in hand. 406 // Don't immediately lex the next one. 407 goto NextToken; 408 } 409 case tok::pp_elif: 410 case tok::pp_else: { 411 // Add an entry for #elif or #else. 412 // This serves as both a closing and opening of a conditional block. 413 // This means that its entry will get backpatched later. 414 unsigned index = PPCond.size(); 415 // Backpatch the previous '#if' entry. 416 assert(!PPStartCond.empty()); 417 assert(PPCond.size() > PPStartCond.back()); 418 assert(PPCond[PPStartCond.back()].second == 0); 419 PPCond[PPStartCond.back()].second = index; 420 PPStartCond.pop_back(); 421 // Now add '#elif' as a new block opening. 422 PPCond.push_back(std::make_pair(HashOff, 0U)); 423 PPStartCond.push_back(index); 424 break; 425 } 426 } 427 } 428 429 EmitToken(Tok); 430 } 431 while (Tok.isNot(tok::eof)); 432 433 assert(PPStartCond.empty() && "Error: imblanced preprocessor conditionals."); 434 435 // Next write out PPCond. 436 Offset PPCondOff = (Offset) Out.tell(); 437 438 // Write out the size of PPCond so that clients can identifer empty tables. 439 Emit32(PPCond.size()); 440 441 for (unsigned i = 0, e = PPCond.size(); i!=e; ++i) { 442 Emit32(PPCond[i].first - TokenOff); 443 uint32_t x = PPCond[i].second; 444 assert(x != 0 && "PPCond entry not backpatched."); 445 // Emit zero for #endifs. This allows us to do checking when 446 // we read the PTH file back in. 447 Emit32(x == i ? 0 : x); 448 } 449 450 return PTHEntry(TokenOff, PPCondOff); 451} 452 453Offset PTHWriter::EmitCachedSpellings() { 454 // Write each cached strings to the PTH file. 455 Offset SpellingsOff = Out.tell(); 456 457 for (std::vector<llvm::StringMapEntry<OffsetOpt>*>::iterator 458 I = StrEntries.begin(), E = StrEntries.end(); I!=E; ++I) 459 EmitBuf((*I)->getKeyData(), (*I)->getKeyLength()+1 /*nul included*/); 460 461 return SpellingsOff; 462} 463 464void PTHWriter::GeneratePTH(const std::string &MainFile) { 465 // Generate the prologue. 466 Out << "cfe-pth" << '\0'; 467 Emit32(PTHManager::Version); 468 469 // Leave 4 words for the prologue. 470 Offset PrologueOffset = Out.tell(); 471 for (unsigned i = 0; i < 4; ++i) 472 Emit32(0); 473 474 // Write the name of the MainFile. 475 if (!MainFile.empty()) { 476 EmitString(MainFile); 477 } else { 478 // String with 0 bytes. 479 Emit16(0); 480 } 481 Emit8(0); 482 483 // Iterate over all the files in SourceManager. Create a lexer 484 // for each file and cache the tokens. 485 SourceManager &SM = PP.getSourceManager(); 486 const LangOptions &LOpts = PP.getLangOpts(); 487 488 for (SourceManager::fileinfo_iterator I = SM.fileinfo_begin(), 489 E = SM.fileinfo_end(); I != E; ++I) { 490 const SrcMgr::ContentCache &C = *I->second; 491 const FileEntry *FE = C.OrigEntry; 492 493 // FIXME: Handle files with non-absolute paths. 494 if (llvm::sys::path::is_relative(FE->getName())) 495 continue; 496 497 const llvm::MemoryBuffer *B = C.getBuffer(PP.getDiagnostics(), SM); 498 if (!B) continue; 499 500 FileID FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User); 501 const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID); 502 Lexer L(FID, FromFile, SM, LOpts); 503 PM.insert(FE, LexTokens(L)); 504 } 505 506 // Write out the identifier table. 507 const std::pair<Offset,Offset> &IdTableOff = EmitIdentifierTable(); 508 509 // Write out the cached strings table. 510 Offset SpellingOff = EmitCachedSpellings(); 511 512 // Write out the file table. 513 Offset FileTableOff = EmitFileTable(); 514 515 // Finally, write the prologue. 516 Out.seek(PrologueOffset); 517 Emit32(IdTableOff.first); 518 Emit32(IdTableOff.second); 519 Emit32(FileTableOff); 520 Emit32(SpellingOff); 521} 522 523namespace { 524/// StatListener - A simple "interpose" object used to monitor stat calls 525/// invoked by FileManager while processing the original sources used 526/// as input to PTH generation. StatListener populates the PTHWriter's 527/// file map with stat information for directories as well as negative stats. 528/// Stat information for files are populated elsewhere. 529class StatListener : public FileSystemStatCache { 530 PTHMap &PM; 531public: 532 StatListener(PTHMap &pm) : PM(pm) {} 533 ~StatListener() {} 534 535 LookupResult getStat(const char *Path, FileData &Data, bool isFile, 536 vfs::File **F, vfs::FileSystem &FS) override { 537 LookupResult Result = statChained(Path, Data, isFile, F, FS); 538 539 if (Result == CacheMissing) // Failed 'stat'. 540 PM.insert(PTHEntryKeyVariant(Path), PTHEntry()); 541 else if (Data.IsDirectory) { 542 // Only cache directories with absolute paths. 543 if (llvm::sys::path::is_relative(Path)) 544 return Result; 545 546 PM.insert(PTHEntryKeyVariant(&Data, Path), PTHEntry()); 547 } 548 549 return Result; 550 } 551}; 552} // end anonymous namespace 553 554 555void clang::CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS) { 556 // Get the name of the main file. 557 const SourceManager &SrcMgr = PP.getSourceManager(); 558 const FileEntry *MainFile = SrcMgr.getFileEntryForID(SrcMgr.getMainFileID()); 559 SmallString<128> MainFilePath(MainFile->getName()); 560 561 llvm::sys::fs::make_absolute(MainFilePath); 562 563 // Create the PTHWriter. 564 PTHWriter PW(*OS, PP); 565 566 // Install the 'stat' system call listener in the FileManager. 567 StatListener *StatCache = new StatListener(PW.getPM()); 568 PP.getFileManager().addStatCache(StatCache, /*AtBeginning=*/true); 569 570 // Lex through the entire file. This will populate SourceManager with 571 // all of the header information. 572 Token Tok; 573 PP.EnterMainSourceFile(); 574 do { PP.Lex(Tok); } while (Tok.isNot(tok::eof)); 575 576 // Generate the PTH file. 577 PP.getFileManager().removeStatCache(StatCache); 578 PW.GeneratePTH(MainFilePath.str()); 579} 580 581//===----------------------------------------------------------------------===// 582 583namespace { 584class PTHIdKey { 585public: 586 const IdentifierInfo* II; 587 uint32_t FileOffset; 588}; 589 590class PTHIdentifierTableTrait { 591public: 592 typedef PTHIdKey* key_type; 593 typedef key_type key_type_ref; 594 595 typedef uint32_t data_type; 596 typedef data_type data_type_ref; 597 598 static unsigned ComputeHash(PTHIdKey* key) { 599 return llvm::HashString(key->II->getName()); 600 } 601 602 static std::pair<unsigned,unsigned> 603 EmitKeyDataLength(raw_ostream& Out, const PTHIdKey* key, uint32_t) { 604 using namespace llvm::support; 605 unsigned n = key->II->getLength() + 1; 606 endian::Writer<little>(Out).write<uint16_t>(n); 607 return std::make_pair(n, sizeof(uint32_t)); 608 } 609 610 static void EmitKey(raw_ostream& Out, PTHIdKey* key, unsigned n) { 611 // Record the location of the key data. This is used when generating 612 // the mapping from persistent IDs to strings. 613 key->FileOffset = Out.tell(); 614 Out.write(key->II->getNameStart(), n); 615 } 616 617 static void EmitData(raw_ostream& Out, PTHIdKey*, uint32_t pID, 618 unsigned) { 619 using namespace llvm::support; 620 endian::Writer<little>(Out).write<uint32_t>(pID); 621 } 622}; 623} // end anonymous namespace 624 625/// EmitIdentifierTable - Emits two tables to the PTH file. The first is 626/// a hashtable mapping from identifier strings to persistent IDs. The second 627/// is a straight table mapping from persistent IDs to string data (the 628/// keys of the first table). 629/// 630std::pair<Offset,Offset> PTHWriter::EmitIdentifierTable() { 631 // Build two maps: 632 // (1) an inverse map from persistent IDs -> (IdentifierInfo*,Offset) 633 // (2) a map from (IdentifierInfo*, Offset)* -> persistent IDs 634 635 // Note that we use 'calloc', so all the bytes are 0. 636 PTHIdKey *IIDMap = (PTHIdKey*)calloc(idcount, sizeof(PTHIdKey)); 637 638 // Create the hashtable. 639 OnDiskChainedHashTableGenerator<PTHIdentifierTableTrait> IIOffMap; 640 641 // Generate mapping from persistent IDs -> IdentifierInfo*. 642 for (IDMap::iterator I = IM.begin(), E = IM.end(); I != E; ++I) { 643 // Decrement by 1 because we are using a vector for the lookup and 644 // 0 is reserved for NULL. 645 assert(I->second > 0); 646 assert(I->second-1 < idcount); 647 unsigned idx = I->second-1; 648 649 // Store the mapping from persistent ID to IdentifierInfo* 650 IIDMap[idx].II = I->first; 651 652 // Store the reverse mapping in a hashtable. 653 IIOffMap.insert(&IIDMap[idx], I->second); 654 } 655 656 // Write out the inverse map first. This causes the PCIDKey entries to 657 // record PTH file offsets for the string data. This is used to write 658 // the second table. 659 Offset StringTableOffset = IIOffMap.Emit(Out); 660 661 // Now emit the table mapping from persistent IDs to PTH file offsets. 662 Offset IDOff = Out.tell(); 663 Emit32(idcount); // Emit the number of identifiers. 664 for (unsigned i = 0 ; i < idcount; ++i) 665 Emit32(IIDMap[i].FileOffset); 666 667 // Finally, release the inverse map. 668 free(IIDMap); 669 670 return std::make_pair(IDOff, StringTableOffset); 671} 672