Move TokenCache option to PreprocessorOptions.

llvm-svn: 86940
This commit is contained in:
Daniel Dunbar 2009-11-12 02:53:59 +00:00
parent 1a54e3fbb9
commit 2940303363
3 changed files with 31 additions and 16 deletions

View File

@ -37,6 +37,9 @@ class PreprocessorOptions {
/// empty. /// empty.
std::string ImplicitPTHInclude; std::string ImplicitPTHInclude;
/// If given, a PTH cache file to use for speeding up header parsing.
std::string TokenCache;
public: public:
PreprocessorOptions() : UsePredefines(true) {} PreprocessorOptions() : UsePredefines(true) {}
@ -63,6 +66,13 @@ public:
ImplicitPTHInclude = Value; ImplicitPTHInclude = Value;
} }
const std::string &getTokenCache() const {
return TokenCache;
}
void setTokenCache(llvm::StringRef Value) {
TokenCache = Value;
}
void addMacroDef(llvm::StringRef Name) { void addMacroDef(llvm::StringRef Name) {
Macros.push_back(std::make_pair(Name, false)); Macros.push_back(std::make_pair(Name, false));
} }

View File

@ -491,6 +491,10 @@ static llvm::cl::opt<std::string>
ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"), ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
llvm::cl::desc("Include file before parsing")); llvm::cl::desc("Include file before parsing"));
static llvm::cl::opt<std::string>
TokenCache("token-cache", llvm::cl::value_desc("path"),
llvm::cl::desc("Use specified token cache file"));
static llvm::cl::list<std::string> static llvm::cl::list<std::string>
U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix, U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
llvm::cl::desc("Undefine the specified macro")); llvm::cl::desc("Undefine the specified macro"));
@ -776,6 +780,19 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
Opts.setImplicitPCHInclude(ImplicitIncludePCH); Opts.setImplicitPCHInclude(ImplicitIncludePCH);
Opts.setImplicitPTHInclude(ImplicitIncludePTH); Opts.setImplicitPTHInclude(ImplicitIncludePTH);
// Select the token cache file, we don't support more than one currently so we
// can't have both an implicit-pth and a token cache file.
if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
// FIXME: Don't fail like this.
fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
"options\n");
exit(1);
}
if (TokenCache.getPosition())
Opts.setTokenCache(TokenCache);
else
Opts.setTokenCache(ImplicitIncludePTH);
// Use predefines? // Use predefines?
Opts.setUsePredefines(!UndefMacros); Opts.setUsePredefines(!UndefMacros);

View File

@ -254,10 +254,6 @@ TimeReport("ftime-report",
llvm::cl::desc("Print the amount of time each " llvm::cl::desc("Print the amount of time each "
"phase of compilation takes")); "phase of compilation takes"));
static llvm::cl::opt<std::string>
TokenCache("token-cache", llvm::cl::value_desc("path"),
llvm::cl::desc("Use specified token cache file"));
static llvm::cl::opt<bool> static llvm::cl::opt<bool>
VerifyDiagnostics("verify", VerifyDiagnostics("verify",
llvm::cl::desc("Verify emitted diagnostics and warnings")); llvm::cl::desc("Verify emitted diagnostics and warnings"));
@ -381,20 +377,12 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo,
const DependencyOutputOptions &DepOpts, const DependencyOutputOptions &DepOpts,
TargetInfo &Target, SourceManager &SourceMgr, TargetInfo &Target, SourceManager &SourceMgr,
FileManager &FileMgr) { FileManager &FileMgr) {
// Create a PTH manager if we are using some form of a token cache.
PTHManager *PTHMgr = 0; PTHManager *PTHMgr = 0;
if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().empty()) { if (!PPOpts.getTokenCache().empty())
fprintf(stderr, "error: cannot use both -token-cache and -include-pth " PTHMgr = PTHManager::Create(PPOpts.getTokenCache(), Diags);
"options\n");
exit(1);
}
// Use PTH?
if (!TokenCache.empty() || !PPOpts.getImplicitPTHInclude().empty()) {
const std::string& x = TokenCache.empty() ?
PPOpts.getImplicitPTHInclude() : TokenCache;
PTHMgr = PTHManager::Create(x, Diags);
}
// FIXME: Don't fail like this.
if (Diags.hasErrorOccurred()) if (Diags.hasErrorOccurred())
exit(1); exit(1);