From: Daniel Dunbar Date: Thu, 12 Nov 2009 02:53:59 +0000 (+0000) Subject: Move TokenCache option to PreprocessorOptions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3cb98ee35b4707c59d7f6d1a6ee2eee95cb7eb5;p=clang Move TokenCache option to PreprocessorOptions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86940 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h index b918a744a2..6ae6843ee6 100644 --- a/include/clang/Frontend/PreprocessorOptions.h +++ b/include/clang/Frontend/PreprocessorOptions.h @@ -37,6 +37,9 @@ class PreprocessorOptions { /// empty. std::string ImplicitPTHInclude; + /// If given, a PTH cache file to use for speeding up header parsing. + std::string TokenCache; + public: PreprocessorOptions() : UsePredefines(true) {} @@ -63,6 +66,13 @@ public: ImplicitPTHInclude = Value; } + const std::string &getTokenCache() const { + return TokenCache; + } + void setTokenCache(llvm::StringRef Value) { + TokenCache = Value; + } + void addMacroDef(llvm::StringRef Name) { Macros.push_back(std::make_pair(Name, false)); } diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 2428d3ab8f..e2b493148b 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -491,6 +491,10 @@ static llvm::cl::opt ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"), llvm::cl::desc("Include file before parsing")); +static llvm::cl::opt +TokenCache("token-cache", llvm::cl::value_desc("path"), + llvm::cl::desc("Use specified token cache file")); + static llvm::cl::list U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix, llvm::cl::desc("Undefine the specified macro")); @@ -776,6 +780,19 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { Opts.setImplicitPCHInclude(ImplicitIncludePCH); 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? Opts.setUsePredefines(!UndefMacros); diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 5803b12910..a40dcee2b3 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -254,10 +254,6 @@ TimeReport("ftime-report", llvm::cl::desc("Print the amount of time each " "phase of compilation takes")); -static llvm::cl::opt -TokenCache("token-cache", llvm::cl::value_desc("path"), - llvm::cl::desc("Use specified token cache file")); - static llvm::cl::opt VerifyDiagnostics("verify", llvm::cl::desc("Verify emitted diagnostics and warnings")); @@ -381,20 +377,12 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo, const DependencyOutputOptions &DepOpts, TargetInfo &Target, SourceManager &SourceMgr, FileManager &FileMgr) { + // Create a PTH manager if we are using some form of a token cache. PTHManager *PTHMgr = 0; - if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().empty()) { - fprintf(stderr, "error: cannot use both -token-cache and -include-pth " - "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); - } + if (!PPOpts.getTokenCache().empty()) + PTHMgr = PTHManager::Create(PPOpts.getTokenCache(), Diags); + // FIXME: Don't fail like this. if (Diags.hasErrorOccurred()) exit(1);