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