[cfe-commits] r87097 - in /cfe/trunk: include/clang/Frontend/CompilerInstance.h lib/Frontend/CompilerInstance.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Fri Nov 13 00:21:10 PST 2009
Author: ddunbar
Date: Fri Nov 13 02:21:10 2009
New Revision: 87097
URL: http://llvm.org/viewvc/llvm-project?rev=87097&view=rev
Log:
Add CompilerInstance::createPCHExternalASTSource.
Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=87097&r1=87096&r2=87097&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Fri Nov 13 02:21:10 2009
@@ -11,6 +11,7 @@
#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
#include "clang/Frontend/CompilerInvocation.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/OwningPtr.h"
#include <cassert>
@@ -22,8 +23,10 @@
class ASTContext;
class Diagnostic;
class DiagnosticClient;
-class Preprocessor;
+class ExternalASTSource;
class FileManager;
+class Preprocessor;
+class Source;
class SourceManager;
class TargetInfo;
@@ -349,6 +352,17 @@
/// Create the AST context.
void createASTContext();
+ /// Create an external AST source to read a PCH file and attach it to the AST
+ /// context.
+ void createPCHExternalASTSource(llvm::StringRef Path);
+
+ /// Create an external AST source to read a PCH file.
+ ///
+ /// \return - The new object on success, or null on failure.
+ static ExternalASTSource *
+ createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
+ Preprocessor &PP, ASTContext &Context);
+
/// }
};
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=87097&r1=87096&r2=87097&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Nov 13 02:21:10 2009
@@ -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 @@
/*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;
+}
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=87097&r1=87096&r2=87097&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Fri Nov 13 02:21:10 2009
@@ -33,7 +33,6 @@
#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Frontend/FixItRewriter.h"
#include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/PCHReader.h"
#include "clang/Frontend/PathDiagnosticClients.h"
#include "clang/Frontend/PreprocessorOptions.h"
#include "clang/Frontend/PreprocessorOutputOptions.h"
@@ -388,41 +387,6 @@
}
}
-/// 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 std::string Sysroot,
- Preprocessor &PP,
- ASTContext &Context) {
- // If the user specified -isysroot, it will be used for relocatable PCH files.
- const char *isysrootPCH = 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(CompilerInstance &CI, const std::string &InFile,
ProgActions PA) {
@@ -509,7 +473,6 @@
}
}
- llvm::OwningPtr<ExternalASTSource> Source;
const std::string &ImplicitPCHInclude =
CI.getPreprocessorOpts().getImplicitPCHInclude();
if (Consumer) {
@@ -517,15 +480,9 @@
CI.createASTContext();
if (!ImplicitPCHInclude.empty()) {
- Source.reset(ReadPCHFile(ImplicitPCHInclude,
- CI.getHeaderSearchOpts().Sysroot, PP,
- CI.getASTContext()));
- if (!Source)
+ CI.createPCHExternalASTSource(ImplicitPCHInclude);
+ if (!CI.getASTContext().getExternalSource())
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.
- CI.getASTContext().setExternalSource(Source);
} else {
// Initialize builtin info when not using PCH.
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
More information about the cfe-commits
mailing list