diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-13 08:21:10 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-13 08:21:10 +0000 |
commit | 0f800391ffbfe3820e1c60246a09a97e5f065179 (patch) | |
tree | 3720c2f1b8868c1b62dd3f61c39794e1a28dbaa8 /lib/Frontend/CompilerInstance.cpp | |
parent | 704e48ae75111072eecaa20a365dff46fb49d2be (diff) |
Add CompilerInstance::createPCHExternalASTSource.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87097 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 0829ce32cc..e7c3611f0f 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -17,6 +17,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PTHManager.h" #include "clang/Frontend/ChainedDiagnosticClient.h" +#include "clang/Frontend/PCHReader.h" #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" @@ -164,3 +165,40 @@ void CompilerInstance::createASTContext() { /*FreeMemory=*/ !getFrontendOpts().DisableFree, /*size_reserve=*/ 0)); } + +// ExternalASTSource + +void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path) { + llvm::OwningPtr<ExternalASTSource> Source; + Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot, + getPreprocessor(), getASTContext())); + getASTContext().setExternalSource(Source); +} + +ExternalASTSource * +CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path, + const std::string &Sysroot, + Preprocessor &PP, + ASTContext &Context) { + llvm::OwningPtr<PCHReader> Reader; + Reader.reset(new PCHReader(PP, &Context, + Sysroot.empty() ? 0 : Sysroot.c_str())); + + switch (Reader->ReadPCH(Path)) { + case PCHReader::Success: + // Set the predefines buffer as suggested by the PCH reader. Typically, the + // predefines buffer will be empty. + PP.setPredefines(Reader->getSuggestedPredefines()); + return Reader.take(); + + case PCHReader::Failure: + // Unrecoverable failure: don't even try to process the input file. + break; + + case PCHReader::IgnorePCH: + // No suitable PCH file could be found. Return an error. + break; + } + + return 0; +} |