[cfe-commits] r67340 - /cfe/trunk/Driver/CacheTokens.cpp
Ted Kremenek
kremenek at apple.com
Thu Mar 19 15:10:39 PDT 2009
Author: kremenek
Date: Thu Mar 19 17:10:38 2009
New Revision: 67340
URL: http://llvm.org/viewvc/llvm-project?rev=67340&view=rev
Log:
Store the name of the original file used to generate the PTH file in the PTH
file itself.
Modified:
cfe/trunk/Driver/CacheTokens.cpp
Modified: cfe/trunk/Driver/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/CacheTokens.cpp?rev=67340&r1=67339&r2=67340&view=diff
==============================================================================
--- cfe/trunk/Driver/CacheTokens.cpp (original)
+++ cfe/trunk/Driver/CacheTokens.cpp Thu Mar 19 17:10:38 2009
@@ -406,7 +406,7 @@
PTHWriter(llvm::raw_fd_ostream& out, Preprocessor& pp)
: Out(out), PP(pp), idcount(0), CurStrOffset(0) {}
- void GeneratePTH();
+ void GeneratePTH(const std::string *MainFile = 0);
StatSysCallCache *createStatListener() {
return new StatListener(PM);
@@ -632,7 +632,7 @@
return SpellingsOff;
}
-void PTHWriter::GeneratePTH() {
+void PTHWriter::GeneratePTH(const std::string *MainFile) {
// Generate the prologue.
Out << "cfe-pth";
Emit32(PTHManager::Version);
@@ -640,6 +640,17 @@
// Leave 4 words for the prologue.
Offset PrologueOffset = Out.tell();
for (unsigned i = 0; i < 4 * sizeof(uint32_t); ++i) Emit8(0);
+
+ // Write the name of the MainFile.
+ if (MainFile && MainFile->length() > 0) {
+ Emit16(MainFile->length());
+ EmitBuf(&((*MainFile)[0]), &((*MainFile)[0]) + MainFile->length());
+ }
+ else {
+ // String with 0 bytes.
+ Emit16(0);
+ }
+ Emit8(0);
// Iterate over all the files in SourceManager. Create a lexer
// for each file and cache the tokens.
@@ -690,6 +701,21 @@
llvm::errs() << "PTH error: " << ErrMsg << "\n";
return;
}
+
+ // 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());
+ std::string MainFileName;
+
+ if (!MainFilePath.isAbsolute()) {
+ llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory();
+ P.appendComponent(MainFilePath.toString());
+ MainFileName = P.toString();
+ }
+ else {
+ MainFileName = MainFilePath.toString();
+ }
// Create the PTHWriter.
PTHWriter PW(Out, PP);
@@ -703,11 +729,9 @@
PP.EnterMainSourceFile();
do { PP.Lex(Tok); } while (Tok.isNot(tok::eof));
-
-
// Generate the PTH file.
PP.getFileManager().setStatCache(0);
- PW.GeneratePTH();
+ PW.GeneratePTH(&MainFileName);
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list