2009-02-13 22:13:46 +03:00
|
|
|
//===--- CacheTokens.cpp - Caching of lexer tokens for PTH support --------===//
|
2008-10-21 04:54:44 +04:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-13 22:13:46 +03:00
|
|
|
// This provides a possible implementation of PTH support for Clang that is
|
2008-10-21 04:54:44 +04:00
|
|
|
// based on caching lexed tokens and identifiers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-05-19 08:14:29 +04:00
|
|
|
#include "clang/Frontend/Utils.h"
|
2008-10-21 04:54:44 +04:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2009-04-20 11:08:21 +04:00
|
|
|
#include "clang/Basic/OnDiskHashTable.h"
|
2008-10-21 04:54:44 +04:00
|
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2009-10-18 00:43:58 +04:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2008-10-21 04:54:44 +04:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-12-02 22:44:08 +03:00
|
|
|
#include "llvm/System/Path.h"
|
2008-10-21 04:54:44 +04:00
|
|
|
|
2009-02-14 19:15:20 +03:00
|
|
|
// FIXME: put this somewhere else?
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(x) (((x)&_S_IFDIR)!=0)
|
|
|
|
#endif
|
|
|
|
|
2008-10-21 04:54:44 +04:00
|
|
|
using namespace clang;
|
2009-04-20 11:08:21 +04:00
|
|
|
using namespace clang::io;
|
2009-02-10 04:14:45 +03:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PTH-specific stuff.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-08 05:44:06 +03:00
|
|
|
namespace {
|
2009-11-28 13:07:24 +03:00
|
|
|
class PTHEntry {
|
2009-09-09 19:08:12 +04:00
|
|
|
Offset TokenData, PPCondData;
|
2009-01-08 05:44:06 +03:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
public:
|
2009-02-13 22:13:46 +03:00
|
|
|
PTHEntry() {}
|
2009-01-08 05:44:06 +03:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
PTHEntry(Offset td, Offset ppcd)
|
2009-01-27 03:01:05 +03:00
|
|
|
: TokenData(td), PPCondData(ppcd) {}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
Offset getTokenOffset() const { return TokenData; }
|
2009-01-08 05:44:06 +03:00
|
|
|
Offset getPPCondTableOffset() const { return PPCondData; }
|
2009-01-27 03:01:05 +03:00
|
|
|
};
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
|
2009-11-28 13:07:24 +03:00
|
|
|
class PTHEntryKeyVariant {
|
2009-02-14 01:07:44 +03:00
|
|
|
union { const FileEntry* FE; const char* Path; };
|
2009-02-13 22:13:46 +03:00
|
|
|
enum { IsFE = 0x1, IsDE = 0x2, IsNoExist = 0x0 } Kind;
|
2009-02-14 01:07:44 +03:00
|
|
|
struct stat *StatBuf;
|
2009-02-11 01:16:22 +03:00
|
|
|
public:
|
2009-02-14 01:07:44 +03:00
|
|
|
PTHEntryKeyVariant(const FileEntry *fe)
|
|
|
|
: FE(fe), Kind(IsFE), StatBuf(0) {}
|
|
|
|
|
|
|
|
PTHEntryKeyVariant(struct stat* statbuf, const char* path)
|
|
|
|
: Path(path), Kind(IsDE), StatBuf(new struct stat(*statbuf)) {}
|
|
|
|
|
2010-03-07 14:21:46 +03:00
|
|
|
explicit PTHEntryKeyVariant(const char* path)
|
2009-02-14 01:07:44 +03:00
|
|
|
: Path(path), Kind(IsNoExist), StatBuf(0) {}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-14 01:07:44 +03:00
|
|
|
bool isFile() const { return Kind == IsFE; }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-10-18 00:43:58 +04:00
|
|
|
llvm::StringRef getString() const {
|
2009-02-14 01:07:44 +03:00
|
|
|
return Kind == IsFE ? FE->getName() : Path;
|
2009-02-13 22:13:46 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
unsigned getKind() const { return (unsigned) Kind; }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
void EmitData(llvm::raw_ostream& Out) {
|
|
|
|
switch (Kind) {
|
2010-01-20 05:03:14 +03:00
|
|
|
case IsFE:
|
|
|
|
// Emit stat information.
|
|
|
|
::Emit32(Out, FE->getInode());
|
|
|
|
::Emit32(Out, FE->getDevice());
|
|
|
|
::Emit16(Out, FE->getFileMode());
|
|
|
|
::Emit64(Out, FE->getModificationTime());
|
|
|
|
::Emit64(Out, FE->getSize());
|
|
|
|
break;
|
|
|
|
case IsDE:
|
|
|
|
// Emit stat information.
|
|
|
|
::Emit32(Out, (uint32_t) StatBuf->st_ino);
|
|
|
|
::Emit32(Out, (uint32_t) StatBuf->st_dev);
|
|
|
|
::Emit16(Out, (uint16_t) StatBuf->st_mode);
|
|
|
|
::Emit64(Out, (uint64_t) StatBuf->st_mtime);
|
|
|
|
::Emit64(Out, (uint64_t) StatBuf->st_size);
|
|
|
|
delete StatBuf;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-02-13 22:13:46 +03:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
unsigned getRepresentationLength() const {
|
2009-02-14 01:07:44 +03:00
|
|
|
return Kind == IsNoExist ? 0 : 4 + 4 + 2 + 8 + 8;
|
2009-02-13 22:13:46 +03:00
|
|
|
}
|
|
|
|
};
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-28 13:07:24 +03:00
|
|
|
class FileEntryPTHEntryInfo {
|
2009-02-13 22:13:46 +03:00
|
|
|
public:
|
|
|
|
typedef PTHEntryKeyVariant key_type;
|
2009-02-11 01:16:22 +03:00
|
|
|
typedef key_type key_type_ref;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
typedef PTHEntry data_type;
|
|
|
|
typedef const PTHEntry& data_type_ref;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
static unsigned ComputeHash(PTHEntryKeyVariant V) {
|
2009-10-18 00:43:58 +04:00
|
|
|
return llvm::HashString(V.getString());
|
2009-02-11 01:16:22 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
static std::pair<unsigned,unsigned>
|
2009-02-13 22:13:46 +03:00
|
|
|
EmitKeyDataLength(llvm::raw_ostream& Out, PTHEntryKeyVariant V,
|
|
|
|
const PTHEntry& E) {
|
2009-02-11 01:16:22 +03:00
|
|
|
|
2009-10-18 00:43:58 +04:00
|
|
|
unsigned n = V.getString().size() + 1 + 1;
|
2009-02-11 01:16:22 +03:00
|
|
|
::Emit16(Out, n);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-14 01:07:44 +03:00
|
|
|
unsigned m = V.getRepresentationLength() + (V.isFile() ? 4 + 4 : 0);
|
2009-02-13 22:13:46 +03:00
|
|
|
::Emit8(Out, m);
|
|
|
|
|
|
|
|
return std::make_pair(n, m);
|
2009-02-11 01:16:22 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
static void EmitKey(llvm::raw_ostream& Out, PTHEntryKeyVariant V, unsigned n){
|
|
|
|
// Emit the entry kind.
|
|
|
|
::Emit8(Out, (unsigned) V.getKind());
|
|
|
|
// Emit the string.
|
2009-10-18 00:43:58 +04:00
|
|
|
Out.write(V.getString().data(), n - 1);
|
2009-02-11 01:16:22 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
static void EmitData(llvm::raw_ostream& Out, PTHEntryKeyVariant V,
|
2009-02-13 22:13:46 +03:00
|
|
|
const PTHEntry& E, unsigned) {
|
|
|
|
|
|
|
|
|
|
|
|
// For file entries emit the offsets into the PTH file for token data
|
|
|
|
// and the preprocessor blocks table.
|
2009-02-14 01:07:44 +03:00
|
|
|
if (V.isFile()) {
|
2009-02-13 22:13:46 +03:00
|
|
|
::Emit32(Out, E.getTokenOffset());
|
|
|
|
::Emit32(Out, E.getPPCondTableOffset());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
// Emit any other data associated with the key (i.e., stat information).
|
|
|
|
V.EmitData(Out);
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2009-02-11 01:16:22 +03:00
|
|
|
};
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-01-27 03:01:05 +03:00
|
|
|
class OffsetOpt {
|
|
|
|
bool valid;
|
|
|
|
Offset off;
|
|
|
|
public:
|
|
|
|
OffsetOpt() : valid(false) {}
|
|
|
|
bool hasOffset() const { return valid; }
|
|
|
|
Offset getOffset() const { assert(valid); return off; }
|
|
|
|
void setOffset(Offset o) { off = o; valid = true; }
|
2009-01-08 05:44:06 +03:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
typedef OnDiskChainedHashTableGenerator<FileEntryPTHEntryInfo> PTHMap;
|
2008-10-21 04:54:44 +04:00
|
|
|
|
2009-01-08 04:17:37 +03:00
|
|
|
namespace {
|
2009-11-28 13:07:24 +03:00
|
|
|
class PTHWriter {
|
2010-03-18 10:45:30 +03:00
|
|
|
typedef llvm::DenseMap<const IdentifierInfo*,uint32_t> IDMap;
|
|
|
|
typedef llvm::StringMap<OffsetOpt, llvm::BumpPtrAllocator> CachedStrsTy;
|
|
|
|
|
2009-01-08 04:17:37 +03:00
|
|
|
IDMap IM;
|
|
|
|
llvm::raw_fd_ostream& Out;
|
|
|
|
Preprocessor& PP;
|
|
|
|
uint32_t idcount;
|
2009-02-13 22:13:46 +03:00
|
|
|
PTHMap PM;
|
2009-01-08 05:44:06 +03:00
|
|
|
CachedStrsTy CachedStrs;
|
2009-01-27 03:01:05 +03:00
|
|
|
Offset CurStrOffset;
|
|
|
|
std::vector<llvm::StringMapEntry<OffsetOpt>*> StrEntries;
|
2008-10-21 04:54:44 +04:00
|
|
|
|
2009-01-08 04:17:37 +03:00
|
|
|
//// Get the persistent id for the given IdentifierInfo*.
|
|
|
|
uint32_t ResolveID(const IdentifierInfo* II);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-01-08 04:17:37 +03:00
|
|
|
/// Emit a token to the PTH file.
|
|
|
|
void EmitToken(const Token& T);
|
2008-10-21 04:54:44 +04:00
|
|
|
|
2010-03-05 18:40:54 +03:00
|
|
|
void Emit8(uint32_t V) { ::Emit8(Out, V); }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-10 04:06:17 +03:00
|
|
|
void Emit16(uint32_t V) { ::Emit16(Out, V); }
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-03-02 20:41:26 +03:00
|
|
|
void Emit24(uint32_t V) { ::Emit24(Out, V); }
|
2008-12-23 21:41:34 +03:00
|
|
|
|
2009-02-10 04:06:17 +03:00
|
|
|
void Emit32(uint32_t V) { ::Emit32(Out, V); }
|
|
|
|
|
2009-03-28 03:16:20 +03:00
|
|
|
void EmitBuf(const char *Ptr, unsigned NumBytes) {
|
|
|
|
Out.write(Ptr, NumBytes);
|
2009-01-08 04:17:37 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-03-14 11:35:19 +03:00
|
|
|
void EmitString(llvm::StringRef V) {
|
|
|
|
::Emit16(Out, V.size());
|
|
|
|
EmitBuf(V.data(), V.size());
|
|
|
|
}
|
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
/// EmitIdentifierTable - Emits two tables to the PTH file. The first is
|
|
|
|
/// a hashtable mapping from identifier strings to persistent IDs.
|
|
|
|
/// The second is a straight table mapping from persistent IDs to string data
|
|
|
|
/// (the keys of the first table).
|
2009-02-11 19:06:55 +03:00
|
|
|
std::pair<Offset, Offset> EmitIdentifierTable();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-11 19:06:55 +03:00
|
|
|
/// EmitFileTable - Emit a table mapping from file name strings to PTH
|
|
|
|
/// token data.
|
|
|
|
Offset EmitFileTable() { return PM.Emit(Out); }
|
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
PTHEntry LexTokens(Lexer& L);
|
2009-01-27 03:01:05 +03:00
|
|
|
Offset EmitCachedSpellings();
|
2009-02-14 01:07:44 +03:00
|
|
|
|
2009-01-08 04:17:37 +03:00
|
|
|
public:
|
2009-09-09 19:08:12 +04:00
|
|
|
PTHWriter(llvm::raw_fd_ostream& out, Preprocessor& pp)
|
2009-01-27 03:01:05 +03:00
|
|
|
: Out(out), PP(pp), idcount(0), CurStrOffset(0) {}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:55:35 +03:00
|
|
|
PTHMap &getPM() { return PM; }
|
2010-03-14 10:38:15 +03:00
|
|
|
void GeneratePTH(const std::string &MainFile);
|
2009-01-08 04:17:37 +03:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
uint32_t PTHWriter::ResolveID(const IdentifierInfo* II) {
|
2008-12-02 22:44:08 +03:00
|
|
|
// Null IdentifierInfo's map to the persistent ID 0.
|
|
|
|
if (!II)
|
|
|
|
return 0;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-10-21 04:54:44 +04:00
|
|
|
IDMap::iterator I = IM.find(II);
|
2009-03-28 03:16:20 +03:00
|
|
|
if (I != IM.end())
|
|
|
|
return I->second; // We've already added 1.
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:16:20 +03:00
|
|
|
IM[II] = ++idcount; // Pre-increment since '0' is reserved for NULL.
|
|
|
|
return idcount;
|
2008-10-21 04:54:44 +04:00
|
|
|
}
|
|
|
|
|
2009-01-08 04:17:37 +03:00
|
|
|
void PTHWriter::EmitToken(const Token& T) {
|
2009-02-24 04:26:56 +03:00
|
|
|
// Emit the token kind, flags, and length.
|
|
|
|
Emit32(((uint32_t) T.getKind()) | ((((uint32_t) T.getFlags())) << 8)|
|
|
|
|
(((uint32_t) T.getLength()) << 16));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:16:20 +03:00
|
|
|
if (!T.isLiteral()) {
|
|
|
|
Emit32(ResolveID(T.getIdentifierInfo()));
|
|
|
|
} else {
|
2009-02-24 04:26:56 +03:00
|
|
|
// We cache *un-cleaned* spellings. This gives us 100% fidelity with the
|
|
|
|
// source code.
|
|
|
|
const char* s = T.getLiteralData();
|
|
|
|
unsigned len = T.getLength();
|
2009-02-24 03:30:21 +03:00
|
|
|
|
2009-01-26 22:29:26 +03:00
|
|
|
// Get the string entry.
|
2009-02-24 04:26:56 +03:00
|
|
|
llvm::StringMapEntry<OffsetOpt> *E = &CachedStrs.GetOrCreateValue(s, s+len);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-24 04:26:56 +03:00
|
|
|
// If this is a new string entry, bump the PTH offset.
|
2009-01-27 03:01:05 +03:00
|
|
|
if (!E->getValue().hasOffset()) {
|
|
|
|
E->getValue().setOffset(CurStrOffset);
|
|
|
|
StrEntries.push_back(E);
|
2009-02-24 04:26:56 +03:00
|
|
|
CurStrOffset += len + 1;
|
2009-01-27 03:01:05 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-24 03:30:21 +03:00
|
|
|
// Emit the relative offset into the PTH file for the spelling string.
|
2009-01-27 03:01:05 +03:00
|
|
|
Emit32(E->getValue().getOffset());
|
2009-01-08 04:17:37 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-24 03:30:21 +03:00
|
|
|
// Emit the offset into the original source file of this token so that we
|
|
|
|
// can reconstruct its SourceLocation.
|
2009-01-27 09:27:13 +03:00
|
|
|
Emit32(PP.getSourceManager().getFileOffset(T.getLocation()));
|
2008-10-21 04:54:44 +04:00
|
|
|
}
|
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
PTHEntry PTHWriter::LexTokens(Lexer& L) {
|
2009-01-20 02:13:15 +03:00
|
|
|
// Pad 0's so that we emit tokens to a 4-byte alignment.
|
|
|
|
// This speed up reading them back in.
|
2009-02-10 04:06:17 +03:00
|
|
|
Pad(Out, 4);
|
2010-03-18 10:18:10 +03:00
|
|
|
Offset TokenOff = (Offset) Out.tell();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-12-12 02:36:38 +03:00
|
|
|
// Keep track of matching '#if' ... '#endif'.
|
|
|
|
typedef std::vector<std::pair<Offset, unsigned> > PPCondTable;
|
|
|
|
PPCondTable PPCond;
|
2008-12-12 21:31:09 +03:00
|
|
|
std::vector<unsigned> PPStartCond;
|
2008-12-23 04:30:52 +03:00
|
|
|
bool ParsingPreprocessorDirective = false;
|
2008-11-26 06:36:26 +03:00
|
|
|
Token Tok;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-26 06:36:26 +03:00
|
|
|
do {
|
|
|
|
L.LexFromRawLexer(Tok);
|
2009-02-11 01:43:16 +03:00
|
|
|
NextToken:
|
|
|
|
|
2008-12-23 04:30:52 +03:00
|
|
|
if ((Tok.isAtStartOfLine() || Tok.is(tok::eof)) &&
|
|
|
|
ParsingPreprocessorDirective) {
|
|
|
|
// Insert an eom token into the token cache. It has the same
|
|
|
|
// position as the next token that is not on the same line as the
|
|
|
|
// preprocessor directive. Observe that we continue processing
|
|
|
|
// 'Tok' when we exit this branch.
|
|
|
|
Token Tmp = Tok;
|
|
|
|
Tmp.setKind(tok::eom);
|
|
|
|
Tmp.clearFlag(Token::StartOfLine);
|
|
|
|
Tmp.setIdentifierInfo(0);
|
2009-01-08 04:17:37 +03:00
|
|
|
EmitToken(Tmp);
|
2008-12-23 04:30:52 +03:00
|
|
|
ParsingPreprocessorDirective = false;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-26 06:36:26 +03:00
|
|
|
if (Tok.is(tok::identifier)) {
|
2010-03-13 11:53:33 +03:00
|
|
|
PP.LookUpIdentifierInfo(Tok);
|
2009-02-11 01:27:09 +03:00
|
|
|
EmitToken(Tok);
|
2008-12-23 04:30:52 +03:00
|
|
|
continue;
|
2008-11-26 06:36:26 +03:00
|
|
|
}
|
2008-12-23 04:30:52 +03:00
|
|
|
|
|
|
|
if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) {
|
2008-11-26 06:36:26 +03:00
|
|
|
// Special processing for #include. Store the '#' token and lex
|
|
|
|
// the next token.
|
2008-12-23 04:30:52 +03:00
|
|
|
assert(!ParsingPreprocessorDirective);
|
2008-12-12 02:36:38 +03:00
|
|
|
Offset HashOff = (Offset) Out.tell();
|
2009-01-08 04:17:37 +03:00
|
|
|
EmitToken(Tok);
|
2008-12-12 21:31:09 +03:00
|
|
|
|
|
|
|
// Get the next token.
|
2008-11-26 06:36:26 +03:00
|
|
|
L.LexFromRawLexer(Tok);
|
2009-04-19 11:25:40 +04:00
|
|
|
|
|
|
|
// If we see the start of line, then we had a null directive "#".
|
|
|
|
if (Tok.isAtStartOfLine())
|
|
|
|
goto NextToken;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-26 06:36:26 +03:00
|
|
|
// Did we see 'include'/'import'/'include_next'?
|
2009-04-19 11:15:51 +04:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
2009-02-11 01:27:09 +03:00
|
|
|
EmitToken(Tok);
|
2008-11-26 06:36:26 +03:00
|
|
|
continue;
|
2009-02-11 01:27:09 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-26 06:36:26 +03:00
|
|
|
IdentifierInfo* II = PP.LookUpIdentifierInfo(Tok);
|
|
|
|
tok::PPKeywordKind K = II->getPPKeywordID();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-12-23 04:30:52 +03:00
|
|
|
ParsingPreprocessorDirective = true;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-12-23 04:30:52 +03:00
|
|
|
switch (K) {
|
2009-04-19 11:32:03 +04:00
|
|
|
case tok::pp_not_keyword:
|
|
|
|
// Invalid directives "#foo" can occur in #if 0 blocks etc, just pass
|
|
|
|
// them through.
|
2008-12-23 04:30:52 +03:00
|
|
|
default:
|
|
|
|
break;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-12-23 04:30:52 +03:00
|
|
|
case tok::pp_include:
|
|
|
|
case tok::pp_import:
|
2009-09-09 19:08:12 +04:00
|
|
|
case tok::pp_include_next: {
|
2008-11-26 06:36:26 +03:00
|
|
|
// Save the 'include' token.
|
2009-01-08 04:17:37 +03:00
|
|
|
EmitToken(Tok);
|
2008-11-26 06:36:26 +03:00
|
|
|
// Lex the next token as an include string.
|
|
|
|
L.setParsingPreprocessorDirective(true);
|
2009-09-09 19:08:12 +04:00
|
|
|
L.LexIncludeFilename(Tok);
|
2008-11-26 06:36:26 +03:00
|
|
|
L.setParsingPreprocessorDirective(false);
|
2008-12-23 04:30:52 +03:00
|
|
|
assert(!Tok.isAtStartOfLine());
|
2008-11-26 06:36:26 +03:00
|
|
|
if (Tok.is(tok::identifier))
|
2010-03-13 11:53:33 +03:00
|
|
|
PP.LookUpIdentifierInfo(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-12-23 04:30:52 +03:00
|
|
|
break;
|
2008-11-26 06:36:26 +03:00
|
|
|
}
|
2008-12-23 04:30:52 +03:00
|
|
|
case tok::pp_if:
|
|
|
|
case tok::pp_ifdef:
|
|
|
|
case tok::pp_ifndef: {
|
2009-02-11 01:27:09 +03:00
|
|
|
// Add an entry for '#if' and friends. We initially set the target
|
|
|
|
// index to 0. This will get backpatched when we hit #endif.
|
2008-12-12 02:36:38 +03:00
|
|
|
PPStartCond.push_back(PPCond.size());
|
2008-12-12 21:31:09 +03:00
|
|
|
PPCond.push_back(std::make_pair(HashOff, 0U));
|
2008-12-23 04:30:52 +03:00
|
|
|
break;
|
2008-12-12 02:36:38 +03:00
|
|
|
}
|
2008-12-23 04:30:52 +03:00
|
|
|
case tok::pp_endif: {
|
2008-12-12 02:36:38 +03:00
|
|
|
// Add an entry for '#endif'. We set the target table index to itself.
|
2008-12-12 21:31:09 +03:00
|
|
|
// This will later be set to zero when emitting to the PTH file. We
|
|
|
|
// use 0 for uninitialized indices because that is easier to debug.
|
2008-12-12 02:36:38 +03:00
|
|
|
unsigned index = PPCond.size();
|
|
|
|
// Backpatch the opening '#if' entry.
|
2008-12-12 21:31:09 +03:00
|
|
|
assert(!PPStartCond.empty());
|
|
|
|
assert(PPCond.size() > PPStartCond.back());
|
2008-12-12 02:36:38 +03:00
|
|
|
assert(PPCond[PPStartCond.back()].second == 0);
|
|
|
|
PPCond[PPStartCond.back()].second = index;
|
2009-09-09 19:08:12 +04:00
|
|
|
PPStartCond.pop_back();
|
|
|
|
// Add the new entry to PPCond.
|
2008-12-12 21:31:09 +03:00
|
|
|
PPCond.push_back(std::make_pair(HashOff, index));
|
2009-02-11 01:43:16 +03:00
|
|
|
EmitToken(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-11 01:43:16 +03:00
|
|
|
// Some files have gibberish on the same line as '#endif'.
|
|
|
|
// Discard these tokens.
|
2009-04-19 11:15:51 +04:00
|
|
|
do
|
|
|
|
L.LexFromRawLexer(Tok);
|
|
|
|
while (Tok.isNot(tok::eof) && !Tok.isAtStartOfLine());
|
2009-02-11 01:43:16 +03:00
|
|
|
// We have the next token in hand.
|
|
|
|
// Don't immediately lex the next one.
|
2009-09-09 19:08:12 +04:00
|
|
|
goto NextToken;
|
2008-12-12 02:36:38 +03:00
|
|
|
}
|
2008-12-23 04:30:52 +03:00
|
|
|
case tok::pp_elif:
|
|
|
|
case tok::pp_else: {
|
|
|
|
// Add an entry for #elif or #else.
|
2008-12-12 21:31:09 +03:00
|
|
|
// This serves as both a closing and opening of a conditional block.
|
|
|
|
// This means that its entry will get backpatched later.
|
2008-12-12 02:36:38 +03:00
|
|
|
unsigned index = PPCond.size();
|
|
|
|
// Backpatch the previous '#if' entry.
|
2008-12-12 21:31:09 +03:00
|
|
|
assert(!PPStartCond.empty());
|
|
|
|
assert(PPCond.size() > PPStartCond.back());
|
2008-12-12 02:36:38 +03:00
|
|
|
assert(PPCond[PPStartCond.back()].second == 0);
|
|
|
|
PPCond[PPStartCond.back()].second = index;
|
|
|
|
PPStartCond.pop_back();
|
|
|
|
// Now add '#elif' as a new block opening.
|
2008-12-12 21:31:09 +03:00
|
|
|
PPCond.push_back(std::make_pair(HashOff, 0U));
|
|
|
|
PPStartCond.push_back(index);
|
2008-12-23 04:30:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-12 02:36:38 +03:00
|
|
|
}
|
2009-02-11 01:27:09 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-11 01:27:09 +03:00
|
|
|
EmitToken(Tok);
|
2008-11-26 06:36:26 +03:00
|
|
|
}
|
2009-02-11 01:27:09 +03:00
|
|
|
while (Tok.isNot(tok::eof));
|
2009-01-08 04:17:37 +03:00
|
|
|
|
2008-12-12 21:31:09 +03:00
|
|
|
assert(PPStartCond.empty() && "Error: imblanced preprocessor conditionals.");
|
2009-01-08 04:17:37 +03:00
|
|
|
|
2008-12-12 02:36:38 +03:00
|
|
|
// Next write out PPCond.
|
|
|
|
Offset PPCondOff = (Offset) Out.tell();
|
2008-12-12 21:31:09 +03:00
|
|
|
|
|
|
|
// Write out the size of PPCond so that clients can identifer empty tables.
|
2009-01-08 04:17:37 +03:00
|
|
|
Emit32(PPCond.size());
|
2008-12-02 22:44:08 +03:00
|
|
|
|
2008-12-12 21:31:09 +03:00
|
|
|
for (unsigned i = 0, e = PPCond.size(); i!=e; ++i) {
|
2010-03-18 10:18:10 +03:00
|
|
|
Emit32(PPCond[i].first - TokenOff);
|
2008-12-12 21:31:09 +03:00
|
|
|
uint32_t x = PPCond[i].second;
|
|
|
|
assert(x != 0 && "PPCond entry not backpatched.");
|
|
|
|
// Emit zero for #endifs. This allows us to do checking when
|
|
|
|
// we read the PTH file back in.
|
2009-01-08 04:17:37 +03:00
|
|
|
Emit32(x == i ? 0 : x);
|
2008-12-12 02:36:38 +03:00
|
|
|
}
|
|
|
|
|
2010-03-18 10:18:10 +03:00
|
|
|
return PTHEntry(TokenOff, PPCondOff);
|
2009-01-08 05:44:06 +03:00
|
|
|
}
|
|
|
|
|
2009-01-27 03:01:05 +03:00
|
|
|
Offset PTHWriter::EmitCachedSpellings() {
|
|
|
|
// Write each cached strings to the PTH file.
|
|
|
|
Offset SpellingsOff = Out.tell();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-01-27 03:01:05 +03:00
|
|
|
for (std::vector<llvm::StringMapEntry<OffsetOpt>*>::iterator
|
2009-03-28 03:16:20 +03:00
|
|
|
I = StrEntries.begin(), E = StrEntries.end(); I!=E; ++I)
|
|
|
|
EmitBuf((*I)->getKeyData(), (*I)->getKeyLength()+1 /*nul included*/);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-01-27 03:01:05 +03:00
|
|
|
return SpellingsOff;
|
2008-11-26 06:36:26 +03:00
|
|
|
}
|
2008-10-21 04:54:44 +04:00
|
|
|
|
2010-03-14 10:38:15 +03:00
|
|
|
void PTHWriter::GeneratePTH(const std::string &MainFile) {
|
2009-01-27 00:43:14 +03:00
|
|
|
// Generate the prologue.
|
|
|
|
Out << "cfe-pth";
|
2009-01-27 00:50:21 +03:00
|
|
|
Emit32(PTHManager::Version);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 02:34:32 +03:00
|
|
|
// Leave 4 words for the prologue.
|
|
|
|
Offset PrologueOffset = Out.tell();
|
2009-03-28 03:16:20 +03:00
|
|
|
for (unsigned i = 0; i < 4; ++i)
|
|
|
|
Emit32(0);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-20 01:10:38 +03:00
|
|
|
// Write the name of the MainFile.
|
2010-03-14 10:55:43 +03:00
|
|
|
if (!MainFile.empty()) {
|
2010-03-18 10:18:10 +03:00
|
|
|
EmitString(MainFile);
|
2009-03-28 03:16:20 +03:00
|
|
|
} else {
|
2009-03-20 01:10:38 +03:00
|
|
|
// String with 0 bytes.
|
|
|
|
Emit16(0);
|
|
|
|
}
|
|
|
|
Emit8(0);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-10-21 04:54:44 +04:00
|
|
|
// Iterate over all the files in SourceManager. Create a lexer
|
|
|
|
// for each file and cache the tokens.
|
2009-01-17 06:48:08 +03:00
|
|
|
SourceManager &SM = PP.getSourceManager();
|
|
|
|
const LangOptions &LOpts = PP.getLangOptions();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-01-17 06:48:08 +03:00
|
|
|
for (SourceManager::fileinfo_iterator I = SM.fileinfo_begin(),
|
|
|
|
E = SM.fileinfo_end(); I != E; ++I) {
|
2009-02-03 10:30:45 +03:00
|
|
|
const SrcMgr::ContentCache &C = *I->second;
|
2009-01-17 06:48:08 +03:00
|
|
|
const FileEntry *FE = C.Entry;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-12-02 22:44:08 +03:00
|
|
|
// FIXME: Handle files with non-absolute paths.
|
|
|
|
llvm::sys::Path P(FE->getName());
|
|
|
|
if (!P.isAbsolute())
|
|
|
|
continue;
|
2008-11-26 06:36:26 +03:00
|
|
|
|
2010-04-21 00:35:58 +04:00
|
|
|
const llvm::MemoryBuffer *B = C.getBuffer(PP.getDiagnostics(), SM);
|
2008-11-26 06:36:26 +03:00
|
|
|
if (!B) continue;
|
2008-12-12 02:36:38 +03:00
|
|
|
|
2009-01-17 09:22:33 +03:00
|
|
|
FileID FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User);
|
2009-11-30 07:18:44 +03:00
|
|
|
const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
|
|
|
|
Lexer L(FID, FromFile, SM, LOpts);
|
2009-02-11 01:16:22 +03:00
|
|
|
PM.insert(FE, LexTokens(L));
|
2008-11-26 05:18:33 +03:00
|
|
|
}
|
2008-11-26 06:36:26 +03:00
|
|
|
|
|
|
|
// Write out the identifier table.
|
2009-03-28 03:16:20 +03:00
|
|
|
const std::pair<Offset,Offset> &IdTableOff = EmitIdentifierTable();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-01-08 05:44:06 +03:00
|
|
|
// Write out the cached strings table.
|
2009-01-27 03:01:05 +03:00
|
|
|
Offset SpellingOff = EmitCachedSpellings();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-11-26 06:36:26 +03:00
|
|
|
// Write out the file table.
|
2009-09-09 19:08:12 +04:00
|
|
|
Offset FileTableOff = EmitFileTable();
|
|
|
|
|
2009-02-12 02:34:32 +03:00
|
|
|
// Finally, write the prologue.
|
|
|
|
Out.seek(PrologueOffset);
|
2009-01-08 04:17:37 +03:00
|
|
|
Emit32(IdTableOff.first);
|
2009-02-11 19:06:55 +03:00
|
|
|
Emit32(IdTableOff.second);
|
2009-01-08 04:17:37 +03:00
|
|
|
Emit32(FileTableOff);
|
2009-01-27 03:01:05 +03:00
|
|
|
Emit32(SpellingOff);
|
2009-01-08 04:17:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-28 03:55:35 +03:00
|
|
|
namespace {
|
|
|
|
/// StatListener - A simple "interpose" object used to monitor stat calls
|
|
|
|
/// invoked by FileManager while processing the original sources used
|
|
|
|
/// as input to PTH generation. StatListener populates the PTHWriter's
|
|
|
|
/// file map with stat information for directories as well as negative stats.
|
|
|
|
/// Stat information for files are populated elsewhere.
|
|
|
|
class StatListener : public StatSysCallCache {
|
|
|
|
PTHMap &PM;
|
|
|
|
public:
|
|
|
|
StatListener(PTHMap &pm) : PM(pm) {}
|
|
|
|
~StatListener() {}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:55:35 +03:00
|
|
|
int stat(const char *path, struct stat *buf) {
|
2009-10-16 22:18:30 +04:00
|
|
|
int result = StatSysCallCache::stat(path, buf);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:55:35 +03:00
|
|
|
if (result != 0) // Failed 'stat'.
|
2010-03-07 14:21:46 +03:00
|
|
|
PM.insert(PTHEntryKeyVariant(path), PTHEntry());
|
2009-03-28 03:55:35 +03:00
|
|
|
else if (S_ISDIR(buf->st_mode)) {
|
|
|
|
// Only cache directories with absolute paths.
|
|
|
|
if (!llvm::sys::Path(path).isAbsolute())
|
|
|
|
return result;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:55:35 +03:00
|
|
|
PM.insert(PTHEntryKeyVariant(buf, path), PTHEntry());
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-28 03:55:35 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
|
2009-05-19 05:02:07 +04:00
|
|
|
void clang::CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS) {
|
2009-03-20 01:10:38 +03:00
|
|
|
// Get the name of the main file.
|
|
|
|
const SourceManager &SrcMgr = PP.getSourceManager();
|
|
|
|
const FileEntry *MainFile = SrcMgr.getFileEntryForID(SrcMgr.getMainFileID());
|
|
|
|
llvm::sys::Path MainFilePath(MainFile->getName());
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-03-14 10:06:50 +03:00
|
|
|
MainFilePath.makeAbsolute();
|
2009-02-14 01:07:44 +03:00
|
|
|
|
|
|
|
// Create the PTHWriter.
|
2009-05-19 05:02:07 +04:00
|
|
|
PTHWriter PW(*OS, PP);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-14 01:07:44 +03:00
|
|
|
// Install the 'stat' system call listener in the FileManager.
|
2009-10-16 22:18:30 +04:00
|
|
|
StatListener *StatCache = new StatListener(PW.getPM());
|
|
|
|
PP.getFileManager().addStatCache(StatCache, /*AtBeginning=*/true);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-14 01:07:44 +03:00
|
|
|
// Lex through the entire file. This will populate SourceManager with
|
|
|
|
// all of the header information.
|
|
|
|
Token Tok;
|
2010-04-21 00:35:58 +04:00
|
|
|
PP.EnterMainSourceFile();
|
2009-02-14 01:07:44 +03:00
|
|
|
do { PP.Lex(Tok); } while (Tok.isNot(tok::eof));
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-14 01:07:44 +03:00
|
|
|
// Generate the PTH file.
|
2009-10-16 22:18:30 +04:00
|
|
|
PP.getFileManager().removeStatCache(StatCache);
|
2010-03-14 10:38:15 +03:00
|
|
|
PW.GeneratePTH(MainFilePath.str());
|
2008-10-21 04:54:44 +04:00
|
|
|
}
|
2009-02-10 04:06:17 +03:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-03-14 09:48:05 +03:00
|
|
|
namespace {
|
2009-03-28 03:16:20 +03:00
|
|
|
class PTHIdKey {
|
2009-02-12 00:29:16 +03:00
|
|
|
public:
|
|
|
|
const IdentifierInfo* II;
|
|
|
|
uint32_t FileOffset;
|
|
|
|
};
|
|
|
|
|
2009-11-28 13:07:24 +03:00
|
|
|
class PTHIdentifierTableTrait {
|
2009-02-12 00:29:16 +03:00
|
|
|
public:
|
2009-02-13 22:13:46 +03:00
|
|
|
typedef PTHIdKey* key_type;
|
2009-02-12 00:29:16 +03:00
|
|
|
typedef key_type key_type_ref;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
typedef uint32_t data_type;
|
|
|
|
typedef data_type data_type_ref;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
static unsigned ComputeHash(PTHIdKey* key) {
|
2009-10-19 01:17:35 +04:00
|
|
|
return llvm::HashString(key->II->getName());
|
2009-02-12 00:29:16 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
static std::pair<unsigned,unsigned>
|
|
|
|
EmitKeyDataLength(llvm::raw_ostream& Out, const PTHIdKey* key, uint32_t) {
|
2009-10-19 00:26:12 +04:00
|
|
|
unsigned n = key->II->getLength() + 1;
|
2009-02-12 00:29:16 +03:00
|
|
|
::Emit16(Out, n);
|
|
|
|
return std::make_pair(n, sizeof(uint32_t));
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-04-20 11:36:26 +04:00
|
|
|
static void EmitKey(llvm::raw_ostream& Out, PTHIdKey* key, unsigned n) {
|
2009-02-12 00:29:16 +03:00
|
|
|
// Record the location of the key data. This is used when generating
|
|
|
|
// the mapping from persistent IDs to strings.
|
|
|
|
key->FileOffset = Out.tell();
|
2009-10-19 00:26:12 +04:00
|
|
|
Out.write(key->II->getNameStart(), n);
|
2009-02-12 00:29:16 +03:00
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-13 22:13:46 +03:00
|
|
|
static void EmitData(llvm::raw_ostream& Out, PTHIdKey*, uint32_t pID,
|
2009-02-12 06:26:59 +03:00
|
|
|
unsigned) {
|
2009-02-12 00:29:16 +03:00
|
|
|
::Emit32(Out, pID);
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2009-02-12 00:29:16 +03:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// EmitIdentifierTable - Emits two tables to the PTH file. The first is
|
|
|
|
/// a hashtable mapping from identifier strings to persistent IDs. The second
|
|
|
|
/// is a straight table mapping from persistent IDs to string data (the
|
|
|
|
/// keys of the first table).
|
|
|
|
///
|
|
|
|
std::pair<Offset,Offset> PTHWriter::EmitIdentifierTable() {
|
|
|
|
// Build two maps:
|
|
|
|
// (1) an inverse map from persistent IDs -> (IdentifierInfo*,Offset)
|
|
|
|
// (2) a map from (IdentifierInfo*, Offset)* -> persistent IDs
|
|
|
|
|
|
|
|
// Note that we use 'calloc', so all the bytes are 0.
|
2009-03-28 03:16:20 +03:00
|
|
|
PTHIdKey *IIDMap = (PTHIdKey*)calloc(idcount, sizeof(PTHIdKey));
|
2009-02-12 00:29:16 +03:00
|
|
|
|
|
|
|
// Create the hashtable.
|
2009-02-13 22:13:46 +03:00
|
|
|
OnDiskChainedHashTableGenerator<PTHIdentifierTableTrait> IIOffMap;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
// Generate mapping from persistent IDs -> IdentifierInfo*.
|
2009-03-28 03:16:20 +03:00
|
|
|
for (IDMap::iterator I = IM.begin(), E = IM.end(); I != E; ++I) {
|
2009-02-12 00:29:16 +03:00
|
|
|
// Decrement by 1 because we are using a vector for the lookup and
|
|
|
|
// 0 is reserved for NULL.
|
|
|
|
assert(I->second > 0);
|
|
|
|
assert(I->second-1 < idcount);
|
|
|
|
unsigned idx = I->second-1;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
// Store the mapping from persistent ID to IdentifierInfo*
|
|
|
|
IIDMap[idx].II = I->first;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
// Store the reverse mapping in a hashtable.
|
|
|
|
IIOffMap.insert(&IIDMap[idx], I->second);
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
// Write out the inverse map first. This causes the PCIDKey entries to
|
|
|
|
// record PTH file offsets for the string data. This is used to write
|
|
|
|
// the second table.
|
|
|
|
Offset StringTableOffset = IIOffMap.Emit(Out);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
// Now emit the table mapping from persistent IDs to PTH file offsets.
|
2009-02-12 00:29:16 +03:00
|
|
|
Offset IDOff = Out.tell();
|
|
|
|
Emit32(idcount); // Emit the number of identifiers.
|
2009-03-28 03:16:20 +03:00
|
|
|
for (unsigned i = 0 ; i < idcount; ++i)
|
|
|
|
Emit32(IIDMap[i].FileOffset);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
// Finally, release the inverse map.
|
|
|
|
free(IIDMap);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-12 00:29:16 +03:00
|
|
|
return std::make_pair(IDOff, StringTableOffset);
|
|
|
|
}
|