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 b918a74..6ae6843 100644
--- a/include/clang/Frontend/PreprocessorOptions.h
+++ b/include/clang/Frontend/PreprocessorOptions.h
@@ -37,6 +37,9 @@
   /// 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 @@
     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 2428d3a..e2b4931 100644
--- a/tools/clang-cc/Options.cpp
+++ b/tools/clang-cc/Options.cpp
@@ -491,6 +491,10 @@
 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 @@
   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 5803b12..a40dcee 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -254,10 +254,6 @@
            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 @@
                    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);
-  }
+  if (!PPOpts.getTokenCache().empty())
+    PTHMgr = PTHManager::Create(PPOpts.getTokenCache(), Diags);
 
-  // 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())
     exit(1);