From: Sebastian Redl Date: Fri, 16 Jul 2010 20:41:52 +0000 (+0000) Subject: Separate out the initial loading of a PCH so that loading chained PCHs can reuse it. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cdf3b83617a3e2471d592795622561506af9109e;p=clang Separate out the initial loading of a PCH so that loading chained PCHs can reuse it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108551 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index 654f4a6e4f..bef9dd6bd9 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -531,7 +531,9 @@ private: 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 &Record); PCHReadResult ReadSourceManagerBlock(); diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 08db039882..7b95b8909a 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -1368,8 +1368,7 @@ void PCHReader::MaybeAddSystemRootToFilename(std::string &Filename) { } 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::ReadPCHBlock() { } 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 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { } break; case pch::PCH_BLOCK_ID: - switch (ReadPCHBlock()) { + switch (ReadPCHBlock(F)) { case Success: break; @@ -1741,7 +1717,7 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { } } - // Check the predefines buffer. + // Check the predefines buffers. if (CheckPredefinesBuffers()) return IgnorePCH; @@ -1786,6 +1762,49 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { 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;