summaryrefslogtreecommitdiffstats
path: root/lib/Frontend/ChainedIncludesSource.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2015-06-20 18:53:08 +0000
committerAdrian Prantl <aprantl@apple.com>2015-06-20 18:53:08 +0000
commit5f4be954a1f0162dccc9c82b8001930d5de7607c (patch)
tree0394829859368d49675b58e95c0fbf3dff550938 /lib/Frontend/ChainedIncludesSource.cpp
parentada17a23cb8ebb6a83ef6d264ce70aad582e7d0e (diff)
Introduce a PCHContainerOperations interface (NFC).
A PCHContainerOperations abstract interface provides operations for creating and unwrapping containers for serialized ASTs (precompiled headers and clang modules). The default implementation is RawPCHContainerOperations, which uses a flat file for the output. The main application for this interface will be an ObjectFilePCHContainerOperations implementation that uses LLVM to wrap the module in an ELF/Mach-O/COFF container to store debug info alongside the AST. rdar://problem/20091852 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240225 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ChainedIncludesSource.cpp')
-rw-r--r--lib/Frontend/ChainedIncludesSource.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/Frontend/ChainedIncludesSource.cpp b/lib/Frontend/ChainedIncludesSource.cpp
index f3677f8000..be30d43a84 100644
--- a/lib/Frontend/ChainedIncludesSource.cpp
+++ b/lib/Frontend/ChainedIncludesSource.cpp
@@ -80,8 +80,9 @@ createASTReader(CompilerInstance &CI, StringRef pchFile,
ASTDeserializationListener *deserialListener = nullptr) {
Preprocessor &PP = CI.getPreprocessor();
std::unique_ptr<ASTReader> Reader;
- Reader.reset(new ASTReader(PP, CI.getASTContext(), /*isysroot=*/"",
- /*DisableValidation=*/true));
+ Reader.reset(new ASTReader(PP, CI.getASTContext(),
+ *CI.getPCHContainerOperations(),
+ /*isysroot=*/"", /*DisableValidation=*/true));
for (unsigned ti = 0; ti < bufNames.size(); ++ti) {
StringRef sr(bufNames[ti]);
Reader->addInMemoryBuffer(sr, std::move(MemBufs[ti]));
@@ -145,7 +146,8 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient));
- std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
+ std::unique_ptr<CompilerInstance> Clang(
+ new CompilerInstance(CI.getPCHContainerOperations()));
Clang->setInvocation(CInvok.release());
Clang->setDiagnostics(Diags.get());
Clang->setTarget(TargetInfo::CreateTargetInfo(
@@ -157,11 +159,9 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
&Clang->getPreprocessor());
Clang->createASTContext();
- SmallVector<char, 256> serialAST;
- llvm::raw_svector_ostream OS(serialAST);
- auto consumer =
- llvm::make_unique<PCHGenerator>(Clang->getPreprocessor(), "-", nullptr,
- /*isysroot=*/"", &OS);
+ auto Buffer = std::make_shared<PCHBuffer>();
+ auto consumer = llvm::make_unique<PCHGenerator>(
+ Clang->getPreprocessor(), "-", nullptr, /*isysroot=*/"", Buffer);
Clang->getASTContext().setASTMutationListener(
consumer->GetASTMutationListener());
Clang->setASTConsumer(std::move(consumer));
@@ -198,7 +198,11 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
ParseAST(Clang->getSema());
Clang->getDiagnosticClient().EndSourceFile();
- SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(OS.str()));
+ assert(Buffer->IsComplete && "serialization did not complete");
+ auto &serialAST = Buffer->Data;
+ SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
+ StringRef(serialAST.data(), serialAST.size())));
+ serialAST.clear();
source->CIs.push_back(Clang.release());
}