]> granicus.if.org Git - clang/commitdiff
Move TokenCache option to PreprocessorOptions.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 12 Nov 2009 02:53:59 +0000 (02:53 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 12 Nov 2009 02:53:59 +0000 (02:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86940 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PreprocessorOptions.h
tools/clang-cc/Options.cpp
tools/clang-cc/clang-cc.cpp

index b918a744a2ab6598daa0436eb130a2b150e92afc..6ae6843ee65a70f3ab604fcad43b9fa702ffc2fb 100644 (file)
@@ -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));
   }
index 2428d3ab8faa5466d428f6155c0c286b0bd07752..e2b493148bcdd10a0fa40386236bd55b97e13194 100644 (file)
@@ -491,6 +491,10 @@ static llvm::cl::opt<std::string>
 ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
                    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>
 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);
 
index 5803b1291077dc3f7ecb7490ea446f2b03c04a09..a40dcee2b3afdcd424e324cb94a232135607efee 100644 (file)
@@ -254,10 +254,6 @@ TimeReport("ftime-report",
            llvm::cl::desc("Print the amount of time each "
                           "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>
 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);