[cfe-commits] r108551 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Jul 16 13:41:52 PDT 2010
Author: cornedbee
Date: Fri Jul 16 15:41:52 2010
New Revision: 108551
URL: http://llvm.org/viewvc/llvm-project?rev=108551&view=rev
Log:
Separate out the initial loading of a PCH so that loading chained PCHs can reuse it.
Modified:
cfe/trunk/include/clang/Frontend/PCHReader.h
cfe/trunk/lib/Frontend/PCHReader.cpp
Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=108551&r1=108550&r2=108551&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Fri Jul 16 15:41:52 2010
@@ -531,7 +531,9 @@
void MaybeAddSystemRootToFilename(std::string &Filename);
- PCHReadResult ReadPCHBlock();
+ PCHReadResult OpenPCH(llvm::StringRef FileName);
+ PCHReadResult ReadChainedPCH(llvm::StringRef FileName);
+ PCHReadResult ReadPCHBlock(PerFileData &F);
bool CheckPredefinesBuffers();
bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record);
PCHReadResult ReadSourceManagerBlock();
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=108551&r1=108550&r2=108551&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Jul 16 15:41:52 2010
@@ -1368,8 +1368,7 @@
}
PCHReader::PCHReadResult
-PCHReader::ReadPCHBlock() {
- PerFileData &F = *Chain[0];
+PCHReader::ReadPCHBlock(PerFileData &F) {
llvm::BitstreamCursor &Stream = F.Stream;
if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) {
@@ -1659,36 +1658,13 @@
}
PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
- Chain.push_back(new PerFileData());
- PerFileData &F = *Chain.back();
-
- // Set the PCH file name.
- F.FileName = FileName;
-
- // Open the PCH file.
- //
- // FIXME: This shouldn't be here, we should just take a raw_ostream.
- std::string ErrStr;
- F.Buffer.reset(llvm::MemoryBuffer::getFileOrSTDIN(FileName, &ErrStr));
- if (!F.Buffer) {
- Error(ErrStr.c_str());
- return IgnorePCH;
+ switch(OpenPCH(FileName)) {
+ case Failure: return Failure;
+ case IgnorePCH: return IgnorePCH;
+ case Success: break;
}
-
- // Initialize the stream
- F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(),
- (const unsigned char *)F.Buffer->getBufferEnd());
+ PerFileData &F = *Chain.back();
llvm::BitstreamCursor &Stream = F.Stream;
- Stream.init(F.StreamFile);
-
- // Sniff for the signature.
- if (Stream.Read(8) != 'C' ||
- Stream.Read(8) != 'P' ||
- Stream.Read(8) != 'C' ||
- Stream.Read(8) != 'H') {
- Diag(diag::err_not_a_pch_file) << FileName;
- return Failure;
- }
while (!Stream.AtEndOfStream()) {
unsigned Code = Stream.ReadCode();
@@ -1709,7 +1685,7 @@
}
break;
case pch::PCH_BLOCK_ID:
- switch (ReadPCHBlock()) {
+ switch (ReadPCHBlock(F)) {
case Success:
break;
@@ -1741,7 +1717,7 @@
}
}
- // Check the predefines buffer.
+ // Check the predefines buffers.
if (CheckPredefinesBuffers())
return IgnorePCH;
@@ -1786,6 +1762,49 @@
return Success;
}
+PCHReader::PCHReadResult PCHReader::OpenPCH(llvm::StringRef FileName) {
+ Chain.push_back(new PerFileData());
+ PerFileData &F = *Chain.back();
+
+ // Set the PCH file name.
+ F.FileName = FileName;
+
+ // Open the PCH file.
+ //
+ // FIXME: This shouldn't be here, we should just take a raw_ostream.
+ std::string ErrStr;
+ F.Buffer.reset(llvm::MemoryBuffer::getFileOrSTDIN(FileName, &ErrStr));
+ if (!F.Buffer) {
+ Error(ErrStr.c_str());
+ return IgnorePCH;
+ }
+
+ // Initialize the stream
+ F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(),
+ (const unsigned char *)F.Buffer->getBufferEnd());
+ llvm::BitstreamCursor &Stream = F.Stream;
+ Stream.init(F.StreamFile);
+
+ // Sniff for the signature.
+ if (Stream.Read(8) != 'C' ||
+ Stream.Read(8) != 'P' ||
+ Stream.Read(8) != 'C' ||
+ Stream.Read(8) != 'H') {
+ Diag(diag::err_not_a_pch_file) << FileName;
+ return Failure;
+ }
+ return Success;
+}
+
+PCHReader::PCHReadResult PCHReader::ReadChainedPCH(llvm::StringRef FileName) {
+ switch(OpenPCH(FileName)) {
+ case Failure: return Failure;
+ case IgnorePCH: return IgnorePCH;
+ case Success: break;
+ }
+ return Success;
+}
+
void PCHReader::setPreprocessor(Preprocessor &pp) {
PP = &pp;
More information about the cfe-commits
mailing list