[cfe-commits] r86936 - /cfe/trunk/tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Wed Nov 11 18:53:20 PST 2009
Author: ddunbar
Date: Wed Nov 11 20:53:20 2009
New Revision: 86936
URL: http://llvm.org/viewvc/llvm-project?rev=86936&view=rev
Log:
clang-cc: Factor ReadPCHFile out of ProcessInputFile.
Modified:
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86936&r1=86935&r2=86936&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 20:53:20 2009
@@ -631,6 +631,41 @@
}
}
+/// ReadPCHFile - Load a PCH file from disk, and initialize the preprocessor for
+/// reading from the PCH file.
+///
+/// \return The AST source, or null on failure.
+static ExternalASTSource *ReadPCHFile(llvm::StringRef Path,
+ const CompilerInvocation &CompOpts,
+ Preprocessor &PP,
+ ASTContext &Context) {
+ // If the user specified -isysroot, it will be used for relocatable PCH files.
+ const char *isysrootPCH = CompOpts.getHeaderSearchOpts().Sysroot.c_str();
+ if (isysrootPCH[0] == '\0')
+ isysrootPCH = 0;
+
+ llvm::OwningPtr<PCHReader> Reader;
+ Reader.reset(new PCHReader(PP, &Context, isysrootPCH));
+
+ 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;
+}
+
/// ProcessInputFile - Process a single input file with the specified state.
///
static void ProcessInputFile(const CompilerInvocation &CompOpts,
@@ -731,40 +766,13 @@
/* FreeMemory = */ !DisableFree,
/* size_reserve = */0));
if (Consumer && !ImplicitPCHInclude.empty()) {
- // If the user specified -isysroot, it will be used for relocatable PCH
- // files.
- const char *isysrootPCH = CompOpts.getHeaderSearchOpts().Sysroot.c_str();
- if (isysrootPCH[0] == '\0')
- isysrootPCH = 0;
-
- llvm::OwningPtr<PCHReader> Reader;
- Reader.reset(new PCHReader(PP, ContextOwner.get(), isysrootPCH));
-
- // The user has asked us to include a precompiled header. Load
- // the precompiled header into the AST context.
- switch (Reader->ReadPCH(ImplicitPCHInclude)) {
- case PCHReader::Success: {
- // Set the predefines buffer as suggested by the PCH
- // reader. Typically, the predefines buffer will be empty.
- PP.setPredefines(Reader->getSuggestedPredefines());
-
- // Attach the PCH reader to the AST context as an external AST
- // source, so that declarations will be deserialized from the
- // PCH file as needed.
- Source.reset(Reader.take());
- ContextOwner->setExternalSource(Source);
- break;
- }
-
- case PCHReader::Failure:
- // Unrecoverable failure: don't even try to process the input
- // file.
+ Source.reset(ReadPCHFile(ImplicitPCHInclude, CompOpts, PP, *ContextOwner));
+ if (!Source)
return;
- case PCHReader::IgnorePCH:
- // No suitable PCH file could be found. Return an error.
- return;
- }
+ // Attach the PCH reader to the AST context as an external AST source, so
+ // that declarations will be deserialized from the PCH file as needed.
+ ContextOwner->setExternalSource(Source);
}
// Initialize the main file entry. This needs to be delayed until after PCH
More information about the cfe-commits
mailing list