Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 1 | //===--- CacheTokens.cpp - Caching of lexer tokens for PCH 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 PCH support for Clang that is |
| 11 | // based on caching lexed tokens and identifiers. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang.h" |
| 16 | #include "clang/Basic/FileManager.h" |
| 17 | #include "clang/Basic/SourceManager.h" |
| 18 | #include "clang/Basic/IdentifierTable.h" |
| 19 | #include "clang/Basic/Diagnostic.h" |
| 20 | #include "clang/Lex/Lexer.h" |
| 21 | #include "clang/Lex/Preprocessor.h" |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringMap.h" |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryBuffer.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 25 | #include "llvm/System/Path.h" |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Streams.h" |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace clang; |
| 30 | |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 31 | typedef uint32_t Offset; |
| 32 | |
Ted Kremenek | e0ea5dc | 2009-02-10 01:06:17 +0000 | [diff] [blame] | 33 | static void Emit8(llvm::raw_ostream& Out, uint32_t V) { |
| 34 | Out << (unsigned char)(V); |
| 35 | } |
| 36 | |
| 37 | static void Emit16(llvm::raw_ostream& Out, uint32_t V) { |
| 38 | Out << (unsigned char)(V); |
| 39 | Out << (unsigned char)(V >> 8); |
| 40 | assert((V >> 16) == 0); |
| 41 | } |
| 42 | |
| 43 | static void Emit32(llvm::raw_ostream& Out, uint32_t V) { |
| 44 | Out << (unsigned char)(V); |
| 45 | Out << (unsigned char)(V >> 8); |
| 46 | Out << (unsigned char)(V >> 16); |
| 47 | Out << (unsigned char)(V >> 24); |
| 48 | } |
| 49 | |
| 50 | static void Pad(llvm::raw_fd_ostream& Out, unsigned Alignment) { |
| 51 | Offset off = (Offset) Out.tell(); |
| 52 | for (unsigned Pad = off % Alignment ; Pad != 0 ; --Pad, ++off) Emit8(Out, 0); |
| 53 | } |
| 54 | |
Ted Kremenek | f0e1f79 | 2009-02-10 01:14:45 +0000 | [diff] [blame^] | 55 | //===----------------------------------------------------------------------===// |
| 56 | // On Disk Hashtable Logic. This will eventually get refactored and put |
| 57 | // elsewhere. |
| 58 | //===----------------------------------------------------------------------===// |
| 59 | |
| 60 | template<typename Info> |
| 61 | class OnDiskChainedHashTableGenerator { |
| 62 | unsigned NumBuckets; |
| 63 | unsigned NumEntries; |
| 64 | llvm::BumpPtrAllocator BA; |
| 65 | |
| 66 | class Item { |
| 67 | public: |
| 68 | typename Info::KeyT key; |
| 69 | typename Info::DataT data; |
| 70 | Item *next; |
| 71 | const uint32_t hash; |
| 72 | |
| 73 | Item(typename Info::KeyT_ref k, typename Info::DataT_ref d) |
| 74 | : key(k), data(d), next(0), hash(Info::getHash(k)) {} |
| 75 | }; |
| 76 | |
| 77 | class Bucket { |
| 78 | public: |
| 79 | Offset off; |
| 80 | Item* head; |
| 81 | unsigned length; |
| 82 | |
| 83 | Bucket() {} |
| 84 | }; |
| 85 | |
| 86 | Bucket* Buckets; |
| 87 | |
| 88 | private: |
| 89 | void insert(Item** b, size_t size, Item* E) { |
| 90 | unsigned idx = E->hash & (size - 1); |
| 91 | Bucket& B = b[idx]; |
| 92 | E->next = B.head; |
| 93 | ++B.length; |
| 94 | B.head = E; |
| 95 | } |
| 96 | |
| 97 | void resize(size_t newsize) { |
| 98 | Bucket* newBuckets = calloc(newsize, sizeof(Bucket)); |
| 99 | |
| 100 | for (unsigned i = 0; i < NumBuckets; ++i) |
| 101 | for (Item* E = Buckets[i]; E ; ) { |
| 102 | Item* N = E->next; |
| 103 | E->Next = 0; |
| 104 | insert(newBuckets, newsize, E); |
| 105 | E = N; |
| 106 | } |
| 107 | |
| 108 | free(Buckets); |
| 109 | NumBuckets = newsize; |
| 110 | Buckets = newBuckets; |
| 111 | } |
| 112 | |
| 113 | public: |
| 114 | |
| 115 | void insert(typename Info::Key_ref key, typename Info::DataT_ref data) { |
| 116 | ++NumEntries; |
| 117 | if (4*NumEntries >= 3*NumBuckets) resize(NumBuckets*2); |
| 118 | insert(Buckets, NumBuckets, new (BA.Allocate<Item>()) Item(key, data)); |
| 119 | } |
| 120 | |
| 121 | Offset Emit(llvm::raw_fd_ostream& out) { |
| 122 | // Emit the payload of the table. |
| 123 | for (unsigned i = 0; i < NumBuckets; ++i) { |
| 124 | Bucket& B = Buckets[i]; |
| 125 | if (!B.head) continue; |
| 126 | |
| 127 | // Store the offset for the data of this bucket. |
| 128 | Pad(out, 4); // 4-byte alignment. |
| 129 | B.off = out.tell(); |
| 130 | |
| 131 | // Write out the number of items in the bucket. We just write out |
| 132 | // 4 bytes to keep things 4-byte aligned. |
| 133 | Emit32(out, B.length); |
| 134 | |
| 135 | // Write out the entries in the bucket. |
| 136 | for (Item *I = B.head; I ; I = I->next) { |
| 137 | Emit32(out, I->hash); |
| 138 | Info::EmitKey(out, I->key); |
| 139 | Info::EmitData(out, I->data); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // Emit the hashtable itself. |
| 144 | Pad(out, 4); |
| 145 | Offset TableOff = out.tell(); |
| 146 | Emit32(out, NumBuckets); |
| 147 | for (unsigned i = 0; i < NumBuckets; ++i) Emit32(out, Buckets[i].off); |
| 148 | |
| 149 | return TableOff; |
| 150 | } |
| 151 | |
| 152 | OnDiskChainedHashTableGenerator() { |
| 153 | NumEntries = 0; |
| 154 | NumBuckets = 64; |
| 155 | Buckets = calloc(NumBuckets, sizeof(Bucket)); |
| 156 | } |
| 157 | |
| 158 | ~OnDiskChainedHashTableGenerator() { |
| 159 | free(Buckets); |
| 160 | } |
| 161 | }; |
| 162 | |
| 163 | //===----------------------------------------------------------------------===// |
| 164 | // PTH-specific stuff. |
| 165 | //===----------------------------------------------------------------------===// |
| 166 | |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 167 | namespace { |
| 168 | class VISIBILITY_HIDDEN PCHEntry { |
| 169 | Offset TokenData, PPCondData; |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 170 | |
| 171 | public: |
| 172 | PCHEntry() {} |
| 173 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 174 | PCHEntry(Offset td, Offset ppcd) |
| 175 | : TokenData(td), PPCondData(ppcd) {} |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 176 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 177 | Offset getTokenOffset() const { return TokenData; } |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 178 | Offset getPPCondTableOffset() const { return PPCondData; } |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 179 | }; |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 180 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 181 | class OffsetOpt { |
| 182 | bool valid; |
| 183 | Offset off; |
| 184 | public: |
| 185 | OffsetOpt() : valid(false) {} |
| 186 | bool hasOffset() const { return valid; } |
| 187 | Offset getOffset() const { assert(valid); return off; } |
| 188 | void setOffset(Offset o) { off = o; valid = true; } |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 189 | }; |
| 190 | } // end anonymous namespace |
| 191 | |
| 192 | typedef llvm::DenseMap<const FileEntry*, PCHEntry> PCHMap; |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 193 | typedef llvm::DenseMap<const IdentifierInfo*,uint32_t> IDMap; |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 194 | typedef llvm::StringMap<OffsetOpt, llvm::BumpPtrAllocator> CachedStrsTy; |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 195 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 196 | namespace { |
| 197 | class VISIBILITY_HIDDEN PTHWriter { |
| 198 | IDMap IM; |
| 199 | llvm::raw_fd_ostream& Out; |
| 200 | Preprocessor& PP; |
| 201 | uint32_t idcount; |
| 202 | PCHMap PM; |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 203 | CachedStrsTy CachedStrs; |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 204 | Offset CurStrOffset; |
| 205 | std::vector<llvm::StringMapEntry<OffsetOpt>*> StrEntries; |
Ted Kremenek | 8f174e1 | 2008-12-23 02:52:12 +0000 | [diff] [blame] | 206 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 207 | //// Get the persistent id for the given IdentifierInfo*. |
| 208 | uint32_t ResolveID(const IdentifierInfo* II); |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 209 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 210 | /// Emit a token to the PTH file. |
| 211 | void EmitToken(const Token& T); |
| 212 | |
| 213 | void Emit8(uint32_t V) { |
| 214 | Out << (unsigned char)(V); |
| 215 | } |
| 216 | |
Ted Kremenek | e0ea5dc | 2009-02-10 01:06:17 +0000 | [diff] [blame] | 217 | void Emit16(uint32_t V) { ::Emit16(Out, V); } |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 218 | |
| 219 | void Emit24(uint32_t V) { |
| 220 | Out << (unsigned char)(V); |
| 221 | Out << (unsigned char)(V >> 8); |
| 222 | Out << (unsigned char)(V >> 16); |
| 223 | assert((V >> 24) == 0); |
| 224 | } |
| 225 | |
Ted Kremenek | e0ea5dc | 2009-02-10 01:06:17 +0000 | [diff] [blame] | 226 | void Emit32(uint32_t V) { ::Emit32(Out, V); } |
| 227 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 228 | void EmitBuf(const char* I, const char* E) { |
| 229 | for ( ; I != E ; ++I) Out << *I; |
| 230 | } |
| 231 | |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 232 | std::pair<Offset,std::pair<Offset, Offset> > EmitIdentifierTable(); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 233 | Offset EmitFileTable(); |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 234 | PCHEntry LexTokens(Lexer& L); |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 235 | Offset EmitCachedSpellings(); |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 236 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 237 | public: |
| 238 | PTHWriter(llvm::raw_fd_ostream& out, Preprocessor& pp) |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 239 | : Out(out), PP(pp), idcount(0), CurStrOffset(0) {} |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 240 | |
| 241 | void GeneratePTH(); |
| 242 | }; |
| 243 | } // end anonymous namespace |
| 244 | |
| 245 | uint32_t PTHWriter::ResolveID(const IdentifierInfo* II) { |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 246 | // Null IdentifierInfo's map to the persistent ID 0. |
| 247 | if (!II) |
| 248 | return 0; |
| 249 | |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 250 | IDMap::iterator I = IM.find(II); |
| 251 | |
| 252 | if (I == IM.end()) { |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 253 | IM[II] = ++idcount; // Pre-increment since '0' is reserved for NULL. |
| 254 | return idcount; |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 257 | return I->second; // We've already added 1. |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 260 | void PTHWriter::EmitToken(const Token& T) { |
Ted Kremenek | 7b78b7c | 2009-01-19 23:13:15 +0000 | [diff] [blame] | 261 | Emit32(((uint32_t) T.getKind()) | |
| 262 | (((uint32_t) T.getFlags()) << 8) | |
| 263 | (((uint32_t) T.getLength()) << 16)); |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 47246be | 2009-01-26 19:29:26 +0000 | [diff] [blame] | 265 | // Literals (strings, numbers, characters) get cached spellings. |
| 266 | if (T.isLiteral()) { |
| 267 | // FIXME: This uses the slow getSpelling(). Perhaps we do better |
| 268 | // in the future? This only slows down PTH generation. |
| 269 | const std::string &spelling = PP.getSpelling(T); |
| 270 | const char* s = spelling.c_str(); |
| 271 | |
| 272 | // Get the string entry. |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 273 | llvm::StringMapEntry<OffsetOpt> *E = |
| 274 | &CachedStrs.GetOrCreateValue(s, s+spelling.size()); |
| 275 | |
| 276 | if (!E->getValue().hasOffset()) { |
| 277 | E->getValue().setOffset(CurStrOffset); |
| 278 | StrEntries.push_back(E); |
| 279 | CurStrOffset += spelling.size() + 1; |
| 280 | } |
| 281 | |
| 282 | Emit32(E->getValue().getOffset()); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 283 | } |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 284 | else |
| 285 | Emit32(ResolveID(T.getIdentifierInfo())); |
| 286 | |
Chris Lattner | 52c2908 | 2009-01-27 06:27:13 +0000 | [diff] [blame] | 287 | Emit32(PP.getSourceManager().getFileOffset(T.getLocation())); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 290 | namespace { |
| 291 | struct VISIBILITY_HIDDEN IDData { |
Ted Kremenek | fa59aad | 2008-11-26 23:58:26 +0000 | [diff] [blame] | 292 | const IdentifierInfo* II; |
| 293 | uint32_t FileOffset; |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | class VISIBILITY_HIDDEN CompareIDDataIndex { |
| 297 | IDData* Table; |
| 298 | public: |
| 299 | CompareIDDataIndex(IDData* table) : Table(table) {} |
| 300 | |
| 301 | bool operator()(unsigned i, unsigned j) const { |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 302 | const IdentifierInfo* II_i = Table[i].II; |
| 303 | const IdentifierInfo* II_j = Table[j].II; |
| 304 | |
| 305 | unsigned i_len = II_i->getLength(); |
| 306 | unsigned j_len = II_j->getLength(); |
| 307 | |
| 308 | if (i_len > j_len) |
| 309 | return false; |
| 310 | |
| 311 | if (i_len < j_len) |
| 312 | return true; |
| 313 | |
| 314 | // Otherwise, compare the strings themselves! |
| 315 | return strncmp(II_i->getName(), II_j->getName(), i_len) < 0; |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 316 | } |
Ted Kremenek | fa59aad | 2008-11-26 23:58:26 +0000 | [diff] [blame] | 317 | }; |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 318 | } |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 319 | |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 320 | std::pair<Offset,std::pair<Offset,Offset> > |
| 321 | PTHWriter::EmitIdentifierTable() { |
| 322 | llvm::BumpPtrAllocator Alloc; |
Ted Kremenek | fa59aad | 2008-11-26 23:58:26 +0000 | [diff] [blame] | 323 | |
| 324 | // Build an inverse map from persistent IDs -> IdentifierInfo*. |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 325 | IDData* IIDMap = Alloc.Allocate<IDData>(idcount); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 326 | |
Ted Kremenek | fa59aad | 2008-11-26 23:58:26 +0000 | [diff] [blame] | 327 | // Generate mapping from persistent IDs -> IdentifierInfo*. |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 328 | for (IDMap::iterator I=IM.begin(), E=IM.end(); I!=E; ++I) { |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 329 | // Decrement by 1 because we are using a vector for the lookup and |
| 330 | // 0 is reserved for NULL. |
| 331 | assert(I->second > 0); |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 332 | assert(I->second-1 < idcount); |
| 333 | unsigned idx = I->second-1; |
| 334 | IIDMap[idx].II = I->first; |
| 335 | } |
Ted Kremenek | fa59aad | 2008-11-26 23:58:26 +0000 | [diff] [blame] | 336 | |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 337 | // We want to write out the strings in lexical order to support binary |
| 338 | // search of strings to identifiers. Create such a table. |
| 339 | unsigned *LexicalOrder = Alloc.Allocate<unsigned>(idcount); |
| 340 | for (unsigned i = 0; i < idcount ; ++i ) LexicalOrder[i] = i; |
| 341 | std::sort(LexicalOrder, LexicalOrder+idcount, CompareIDDataIndex(IIDMap)); |
| 342 | |
| 343 | // Write out the lexically-sorted table of persistent ids. |
| 344 | Offset LexicalOff = Out.tell(); |
| 345 | for (unsigned i = 0; i < idcount ; ++i) Emit32(LexicalOrder[i]); |
| 346 | |
| 347 | // Write out the string data itself. |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 348 | Offset DataOff = Out.tell(); |
Ted Kremenek | 6183e48 | 2008-12-03 01:16:39 +0000 | [diff] [blame] | 349 | |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 350 | for (unsigned i = 0; i < idcount; ++i) { |
| 351 | IDData& d = IIDMap[i]; |
| 352 | d.FileOffset = Out.tell(); // Record the location for this data. |
| 353 | unsigned len = d.II->getLength(); // Write out the string length. |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 354 | Emit32(len); |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 355 | const char* buf = d.II->getName(); // Write out the string data. |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 356 | EmitBuf(buf, buf+len); |
| 357 | // Emit a null character for those clients expecting that IdentifierInfo |
| 358 | // strings are null terminated. |
| 359 | Emit8('\0'); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 360 | } |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 361 | |
Ted Kremenek | fa59aad | 2008-11-26 23:58:26 +0000 | [diff] [blame] | 362 | // Now emit the table mapping from persistent IDs to PTH file offsets. |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 363 | Offset IDOff = Out.tell(); |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 364 | Emit32(idcount); // Emit the number of identifiers. |
| 365 | for (unsigned i = 0 ; i < idcount; ++i) Emit32(IIDMap[i].FileOffset); |
Ted Kremenek | 6183e48 | 2008-12-03 01:16:39 +0000 | [diff] [blame] | 366 | |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 367 | return std::make_pair(DataOff, std::make_pair(IDOff, LexicalOff)); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 370 | |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 371 | PCHEntry PTHWriter::LexTokens(Lexer& L) { |
Ted Kremenek | 7b78b7c | 2009-01-19 23:13:15 +0000 | [diff] [blame] | 372 | // Pad 0's so that we emit tokens to a 4-byte alignment. |
| 373 | // This speed up reading them back in. |
Ted Kremenek | e0ea5dc | 2009-02-10 01:06:17 +0000 | [diff] [blame] | 374 | Pad(Out, 4); |
| 375 | Offset off = (Offset) Out.tell(); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 376 | |
| 377 | // Keep track of matching '#if' ... '#endif'. |
| 378 | typedef std::vector<std::pair<Offset, unsigned> > PPCondTable; |
| 379 | PPCondTable PPCond; |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 380 | std::vector<unsigned> PPStartCond; |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 381 | bool ParsingPreprocessorDirective = false; |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 382 | Token Tok; |
| 383 | |
| 384 | do { |
| 385 | L.LexFromRawLexer(Tok); |
| 386 | |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 387 | if ((Tok.isAtStartOfLine() || Tok.is(tok::eof)) && |
| 388 | ParsingPreprocessorDirective) { |
| 389 | // Insert an eom token into the token cache. It has the same |
| 390 | // position as the next token that is not on the same line as the |
| 391 | // preprocessor directive. Observe that we continue processing |
| 392 | // 'Tok' when we exit this branch. |
| 393 | Token Tmp = Tok; |
| 394 | Tmp.setKind(tok::eom); |
| 395 | Tmp.clearFlag(Token::StartOfLine); |
| 396 | Tmp.setIdentifierInfo(0); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 397 | EmitToken(Tmp); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 398 | ParsingPreprocessorDirective = false; |
| 399 | } |
| 400 | |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 401 | if (Tok.is(tok::identifier)) { |
| 402 | Tok.setIdentifierInfo(PP.LookUpIdentifierInfo(Tok)); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 403 | continue; |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 404 | } |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 405 | |
| 406 | if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 407 | // Special processing for #include. Store the '#' token and lex |
| 408 | // the next token. |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 409 | assert(!ParsingPreprocessorDirective); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 410 | Offset HashOff = (Offset) Out.tell(); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 411 | EmitToken(Tok); |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 412 | |
| 413 | // Get the next token. |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 414 | L.LexFromRawLexer(Tok); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 415 | |
| 416 | assert(!Tok.isAtStartOfLine()); |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 417 | |
| 418 | // Did we see 'include'/'import'/'include_next'? |
| 419 | if (!Tok.is(tok::identifier)) |
| 420 | continue; |
| 421 | |
| 422 | IdentifierInfo* II = PP.LookUpIdentifierInfo(Tok); |
| 423 | Tok.setIdentifierInfo(II); |
| 424 | tok::PPKeywordKind K = II->getPPKeywordID(); |
| 425 | |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 426 | assert(K != tok::pp_not_keyword); |
| 427 | ParsingPreprocessorDirective = true; |
| 428 | |
| 429 | switch (K) { |
| 430 | default: |
| 431 | break; |
| 432 | case tok::pp_include: |
| 433 | case tok::pp_import: |
| 434 | case tok::pp_include_next: { |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 435 | // Save the 'include' token. |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 436 | EmitToken(Tok); |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 437 | // Lex the next token as an include string. |
| 438 | L.setParsingPreprocessorDirective(true); |
| 439 | L.LexIncludeFilename(Tok); |
| 440 | L.setParsingPreprocessorDirective(false); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 441 | assert(!Tok.isAtStartOfLine()); |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 442 | if (Tok.is(tok::identifier)) |
| 443 | Tok.setIdentifierInfo(PP.LookUpIdentifierInfo(Tok)); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 444 | |
| 445 | break; |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 446 | } |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 447 | case tok::pp_if: |
| 448 | case tok::pp_ifdef: |
| 449 | case tok::pp_ifndef: { |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 450 | // Ad an entry for '#if' and friends. We initially set the target index |
| 451 | // to 0. This will get backpatched when we hit #endif. |
| 452 | PPStartCond.push_back(PPCond.size()); |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 453 | PPCond.push_back(std::make_pair(HashOff, 0U)); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 454 | break; |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 455 | } |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 456 | case tok::pp_endif: { |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 457 | // Add an entry for '#endif'. We set the target table index to itself. |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 458 | // This will later be set to zero when emitting to the PTH file. We |
| 459 | // use 0 for uninitialized indices because that is easier to debug. |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 460 | unsigned index = PPCond.size(); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 461 | // Backpatch the opening '#if' entry. |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 462 | assert(!PPStartCond.empty()); |
| 463 | assert(PPCond.size() > PPStartCond.back()); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 464 | assert(PPCond[PPStartCond.back()].second == 0); |
| 465 | PPCond[PPStartCond.back()].second = index; |
| 466 | PPStartCond.pop_back(); |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 467 | // Add the new entry to PPCond. |
| 468 | PPCond.push_back(std::make_pair(HashOff, index)); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 469 | break; |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 470 | } |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 471 | case tok::pp_elif: |
| 472 | case tok::pp_else: { |
| 473 | // Add an entry for #elif or #else. |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 474 | // This serves as both a closing and opening of a conditional block. |
| 475 | // This means that its entry will get backpatched later. |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 476 | unsigned index = PPCond.size(); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 477 | // Backpatch the previous '#if' entry. |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 478 | assert(!PPStartCond.empty()); |
| 479 | assert(PPCond.size() > PPStartCond.back()); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 480 | assert(PPCond[PPStartCond.back()].second == 0); |
| 481 | PPCond[PPStartCond.back()].second = index; |
| 482 | PPStartCond.pop_back(); |
| 483 | // Now add '#elif' as a new block opening. |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 484 | PPCond.push_back(std::make_pair(HashOff, 0U)); |
| 485 | PPStartCond.push_back(index); |
Ted Kremenek | e5680f3 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 486 | break; |
| 487 | } |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 488 | } |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 491 | while (EmitToken(Tok), Tok.isNot(tok::eof)); |
| 492 | |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 493 | assert(PPStartCond.empty() && "Error: imblanced preprocessor conditionals."); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 494 | |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 495 | // Next write out PPCond. |
| 496 | Offset PPCondOff = (Offset) Out.tell(); |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 497 | |
| 498 | // Write out the size of PPCond so that clients can identifer empty tables. |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 499 | Emit32(PPCond.size()); |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 500 | |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 501 | for (unsigned i = 0, e = PPCond.size(); i!=e; ++i) { |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 502 | Emit32(PPCond[i].first - off); |
Ted Kremenek | dad7b34 | 2008-12-12 18:31:09 +0000 | [diff] [blame] | 503 | uint32_t x = PPCond[i].second; |
| 504 | assert(x != 0 && "PPCond entry not backpatched."); |
| 505 | // Emit zero for #endifs. This allows us to do checking when |
| 506 | // we read the PTH file back in. |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 507 | Emit32(x == i ? 0 : x); |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 510 | return PCHEntry(off, PPCondOff); |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 513 | Offset PTHWriter::EmitCachedSpellings() { |
| 514 | // Write each cached strings to the PTH file. |
| 515 | Offset SpellingsOff = Out.tell(); |
| 516 | |
| 517 | for (std::vector<llvm::StringMapEntry<OffsetOpt>*>::iterator |
| 518 | I = StrEntries.begin(), E = StrEntries.end(); I!=E; ++I) { |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 519 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 520 | const char* data = (*I)->getKeyData(); |
| 521 | EmitBuf(data, data + (*I)->getKeyLength()); |
| 522 | Emit8('\0'); |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 525 | return SpellingsOff; |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 526 | } |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 527 | |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 528 | void PTHWriter::GeneratePTH() { |
Ted Kremenek | e1b6498 | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 529 | // Generate the prologue. |
| 530 | Out << "cfe-pth"; |
Ted Kremenek | 67d1505 | 2009-01-26 21:50:21 +0000 | [diff] [blame] | 531 | Emit32(PTHManager::Version); |
Ted Kremenek | e1b6498 | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 532 | Offset JumpOffset = Out.tell(); |
| 533 | Emit32(0); |
| 534 | |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 535 | // Iterate over all the files in SourceManager. Create a lexer |
| 536 | // for each file and cache the tokens. |
Chris Lattner | c6fe32a | 2009-01-17 03:48:08 +0000 | [diff] [blame] | 537 | SourceManager &SM = PP.getSourceManager(); |
| 538 | const LangOptions &LOpts = PP.getLangOptions(); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 539 | |
Chris Lattner | c6fe32a | 2009-01-17 03:48:08 +0000 | [diff] [blame] | 540 | for (SourceManager::fileinfo_iterator I = SM.fileinfo_begin(), |
| 541 | E = SM.fileinfo_end(); I != E; ++I) { |
Chris Lattner | 0d0bf8c | 2009-02-03 07:30:45 +0000 | [diff] [blame] | 542 | const SrcMgr::ContentCache &C = *I->second; |
Chris Lattner | c6fe32a | 2009-01-17 03:48:08 +0000 | [diff] [blame] | 543 | const FileEntry *FE = C.Entry; |
Ted Kremenek | fc7e2ea | 2008-12-02 19:44:08 +0000 | [diff] [blame] | 544 | |
| 545 | // FIXME: Handle files with non-absolute paths. |
| 546 | llvm::sys::Path P(FE->getName()); |
| 547 | if (!P.isAbsolute()) |
| 548 | continue; |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 549 | |
Chris Lattner | 5c26385 | 2009-01-17 03:49:48 +0000 | [diff] [blame] | 550 | assert(!PM.count(FE) && "fileinfo's are not uniqued on FileEntry?"); |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 551 | |
Chris Lattner | c6fe32a | 2009-01-17 03:48:08 +0000 | [diff] [blame] | 552 | const llvm::MemoryBuffer *B = C.getBuffer(); |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 553 | if (!B) continue; |
Ted Kremenek | fb645b6 | 2008-12-11 23:36:38 +0000 | [diff] [blame] | 554 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 555 | FileID FID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User); |
Chris Lattner | 025c3a6 | 2009-01-17 07:35:14 +0000 | [diff] [blame] | 556 | Lexer L(FID, SM, LOpts); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 557 | PM[FE] = LexTokens(L); |
Daniel Dunbar | 31309ab | 2008-11-26 02:18:33 +0000 | [diff] [blame] | 558 | } |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 559 | |
| 560 | // Write out the identifier table. |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 561 | const std::pair<Offset, std::pair<Offset,Offset> >& IdTableOff |
| 562 | = EmitIdentifierTable(); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 563 | |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 564 | // Write out the cached strings table. |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 565 | Offset SpellingOff = EmitCachedSpellings(); |
Ted Kremenek | be29533 | 2009-01-08 02:44:06 +0000 | [diff] [blame] | 566 | |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 567 | // Write out the file table. |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 568 | Offset FileTableOff = EmitFileTable(); |
Ted Kremenek | a3d764c | 2008-11-26 03:36:26 +0000 | [diff] [blame] | 569 | |
| 570 | // Finally, write out the offset table at the end. |
Ted Kremenek | e1b6498 | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 571 | Offset JumpTargetOffset = Out.tell(); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 572 | Emit32(IdTableOff.first); |
Ted Kremenek | 293b4af | 2009-01-15 01:26:25 +0000 | [diff] [blame] | 573 | Emit32(IdTableOff.second.first); |
| 574 | Emit32(IdTableOff.second.second); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 575 | Emit32(FileTableOff); |
Ted Kremenek | 277faca | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 576 | Emit32(SpellingOff); |
Ted Kremenek | e1b6498 | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 577 | |
| 578 | // Now write the offset in the prologue. |
| 579 | Out.seek(JumpOffset); |
| 580 | Emit32(JumpTargetOffset); |
Ted Kremenek | b978c66 | 2009-01-08 01:17:37 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | void clang::CacheTokens(Preprocessor& PP, const std::string& OutFile) { |
| 584 | // Lex through the entire file. This will populate SourceManager with |
| 585 | // all of the header information. |
| 586 | Token Tok; |
| 587 | PP.EnterMainSourceFile(); |
| 588 | do { PP.Lex(Tok); } while (Tok.isNot(tok::eof)); |
| 589 | |
| 590 | // Open up the PTH file. |
| 591 | std::string ErrMsg; |
| 592 | llvm::raw_fd_ostream Out(OutFile.c_str(), true, ErrMsg); |
| 593 | |
| 594 | if (!ErrMsg.empty()) { |
| 595 | llvm::errs() << "PTH error: " << ErrMsg << "\n"; |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | // Create the PTHWriter and generate the PTH file. |
| 600 | PTHWriter PW(Out, PP); |
| 601 | PW.GeneratePTH(); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 602 | } |
Ted Kremenek | e0ea5dc | 2009-02-10 01:06:17 +0000 | [diff] [blame] | 603 | |
Ted Kremenek | e0ea5dc | 2009-02-10 01:06:17 +0000 | [diff] [blame] | 604 | |
| 605 | //===----------------------------------------------------------------------===// |
| 606 | // Client code of on-disk hashtable logic. |
| 607 | //===----------------------------------------------------------------------===// |
| 608 | |
| 609 | Offset PTHWriter::EmitFileTable() { |
| 610 | // Determine the offset where this table appears in the PTH file. |
| 611 | Offset off = (Offset) Out.tell(); |
| 612 | |
| 613 | // Output the size of the table. |
| 614 | Emit32(PM.size()); |
| 615 | |
| 616 | for (PCHMap::iterator I=PM.begin(), E=PM.end(); I!=E; ++I) { |
| 617 | const FileEntry* FE = I->first; |
| 618 | const char* Name = FE->getName(); |
| 619 | unsigned size = strlen(Name); |
| 620 | Emit32(size); |
| 621 | EmitBuf(Name, Name+size); |
| 622 | Emit32(I->second.getTokenOffset()); |
| 623 | Emit32(I->second.getPPCondTableOffset()); |
| 624 | } |
| 625 | |
| 626 | return off; |
| 627 | } |
| 628 | |