[cfe-commits] r67393 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/pth.c

Daniel Dunbar daniel at zuster.org
Fri Mar 20 12:38:58 PDT 2009


Author: ddunbar
Date: Fri Mar 20 14:38:56 2009
New Revision: 67393

URL: http://llvm.org/viewvc/llvm-project?rev=67393&view=rev
Log:
Driver: Switch to using -include-pth.

Added:
    cfe/trunk/test/Driver/pth.c
Modified:
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=67393&r1=67392&r2=67393&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Mar 20 14:38:56 2009
@@ -45,28 +45,6 @@
     // No special option needed, driven by -x.
     //
     // FIXME: Don't drive this by -x, that is gross.
-
-    // FIXME: This is a total hack. Copy the input header file
-    // to the output, so that it can be -include'd by clang.
-    assert(Inputs.size() == 1 && "Cannot make PCH with multiple inputs.");
-    assert(Output.isFilename() && "Unexpected output");
-    assert(!Inputs[0].isPipe() && "Unexpected pipe");
-    assert(Inputs[0].isFilename() && "Unexpected input");
-    const char *InputPath = Inputs[0].getFilename();
-    llvm::sys::Path OutputPath(Output.getFilename());
-    OutputPath.eraseComponent();
-    if (OutputPath.empty())
-      OutputPath = llvm::sys::Path(InputPath).getLast();
-    else
-      OutputPath.appendComponent(llvm::sys::Path(InputPath).getLast());
-    if (!OutputPath.exists()) {
-      ArgStringList CpArgs;
-      CpArgs.push_back(InputPath);
-      CpArgs.push_back(Args.MakeArgString(OutputPath.c_str()));
-      const char *Exec = 
-        Args.MakeArgString(getToolChain().GetProgramPath(C, "cp").c_str());
-      C.getJobs().addJob(new Command(Exec, CpArgs));
-    }
   } else {
     assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool.");
   
@@ -262,32 +240,42 @@
   Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
 
   // FIXME: Clang isn't going to accept just anything here.
-  Args.AddAllArgs(CmdArgs, options::OPT_i_Group);
+  // FIXME: Use iterator.
 
-  // Automatically load .pth or .gch files which match -include
-  // options. It's wonky, but we include looking for .gch so we can
-  // support seamless replacement into a build system already set up
-  // to be generating .gch files.
-
-  // FIXME: Need to use an iterator for this to be efficient.
+  // Add -i* options, and automatically translate to -include-pth for
+  // transparent PCH support. It's wonky, but we include looking for
+  // .gch so we can support seamless replacement into a build system
+  // already set up to be generating .gch files.
   for (ArgList::const_iterator 
          it = Args.begin(), ie = Args.end(); it != ie; ++it) {
     const Arg *A = *it;
+    if (!A->getOption().matches(options::OPT_i_Group)) 
+      continue;
+
     if (A->getOption().matches(options::OPT_include)) {
+      bool FoundPTH = false;
       llvm::sys::Path P(A->getValue(Args));
       P.appendSuffix("pth");
       if (P.exists()) {
-        CmdArgs.push_back("-token-cache");
-        CmdArgs.push_back(Args.MakeArgString(P.c_str()));
+        FoundPTH = true;
       } else {
         P.eraseSuffix();
         P.appendSuffix("gch");
-        if (P.exists()) {
-          CmdArgs.push_back("-token-cache");
-          CmdArgs.push_back(Args.MakeArgString(P.c_str()));
-        }
+        if (P.exists())
+          FoundPTH = true;
+      }
+
+      if (FoundPTH) {
+        A->claim();
+        CmdArgs.push_back("-include-pth");
+        CmdArgs.push_back(Args.MakeArgString(P.c_str()));
+        continue;
       }
     }
+
+    // Not translated, render as usual.
+    A->claim();
+    A->render(Args, CmdArgs);
   }
 
   // Manually translate -O to -O1; let clang reject others.

Added: cfe/trunk/test/Driver/pth.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pth.c?rev=67393&view=auto

==============================================================================
--- cfe/trunk/test/Driver/pth.c (added)
+++ cfe/trunk/test/Driver/pth.c Fri Mar 20 14:38:56 2009
@@ -0,0 +1,8 @@
+// Test transparent PTH support.
+
+// RUN: clang-driver -x c-header %s -o %t.h.pch -### &> %t.log &&
+// RUN: grep '".*/clang" .* "-o" ".*\.h\.pch" "-x" "c-header" ".*pth\.c"' %t.log &&
+
+// RUN: touch %t.h.pth &&
+// RUN: clang-driver -E -include %t.h %s -### &> %t.log &&
+// RUN: grep '".*/clang" .*"-include-pth" ".*\.h\.pth" .*"-x" "c" ".*pth\.c"' %t.log





More information about the cfe-commits mailing list