[cfe-commits] r68027 - in /cfe/trunk: include/clang/Driver/ToolChain.h include/clang/Driver/Types.def lib/Driver/Driver.cpp lib/Driver/Tools.cpp test/Frontend/dependency-gen.c tools/clang-cc/DependencyFile.cpp

Daniel Dunbar daniel at zuster.org
Sun Mar 29 23:36:42 PDT 2009


Author: ddunbar
Date: Mon Mar 30 01:36:42 2009
New Revision: 68027

URL: http://llvm.org/viewvc/llvm-project?rev=68027&view=rev
Log:
Driver: Support -M and -MM.
 - Not particularly elegant, but my hand is forced by gcc.

Also, tweak -ccc-print-bindings output.

Modified:
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/include/clang/Driver/Types.def
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Frontend/dependency-gen.c
    cfe/trunk/tools/clang-cc/DependencyFile.cpp

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=68027&r1=68026&r2=68027&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Mon Mar 30 01:36:42 2009
@@ -54,6 +54,10 @@
   const std::string &getPlatform() const { return Platform; }
   const std::string &getOS() const { return OS; }
 
+  const std::string getTripleString() const {
+    return getArchName() + "-" + getPlatform() + "-" + getOS();
+  }
+
   path_list &getFilePaths() { return FilePaths; }
   const path_list &getFilePaths() const { return FilePaths; }
 

Modified: cfe/trunk/include/clang/Driver/Types.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.def?rev=68027&r1=68026&r2=68027&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Types.def (original)
+++ cfe/trunk/include/clang/Driver/Types.def Mon Mar 30 01:36:42 2009
@@ -74,4 +74,5 @@
 TYPE("object",                   Object,       INVALID,         "o",     "")
 TYPE("treelang",                 Treelang,     INVALID,         0,       "u")
 TYPE("image",                    Image,        INVALID,         "out",   "")
+TYPE("dependencies",             Dependencies, INVALID,         "d",     "")
 TYPE("none",                     Nothing,      INVALID,         0,       "u")

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Mar 30 01:36:42 2009
@@ -245,8 +245,7 @@
   llvm::errs() << "clang version 1.0 (" << vers << " " << revision << ")" << "\n";
 
   const ToolChain &TC = C.getDefaultToolChain();
-  llvm::errs() << "Target: " << TC.getArchName() << '-' 
-               << TC.getPlatform() << '-' << TC.getOS() << '\n';
+  llvm::errs() << "Target: " << TC.getTripleString() << '\n';
 }
 
 bool Driver::HandleImmediateArgs(const Compilation &C) {
@@ -379,9 +378,6 @@
   if (Archs.size() > 1) {
     // No recovery needed, the point of this is just to prevent
     // overwriting the same files.
-    if (const Arg *A = Args.getLastArg(options::OPT_M_Group))
-      Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
-        << A->getAsString(Args);
     if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
       Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
         << A->getAsString(Args);
@@ -618,9 +614,15 @@
   switch (Phase) {
   case phases::Link: assert(0 && "link action invalid here.");
   case phases::Preprocess: {
-    types::ID OutputTy = types::getPreprocessedType(Input->getType());
-    assert(OutputTy != types::TY_INVALID &&
-           "Cannot preprocess this input type!");
+    types::ID OutputTy;
+    // -{M, MM} alter the output type.
+    if (Args.hasArg(options::OPT_M) || Args.hasArg(options::OPT_MM)) {
+      OutputTy = types::TY_Dependencies;
+    } else {
+      OutputTy = types::getPreprocessedType(Input->getType());
+      assert(OutputTy != types::TY_INVALID &&
+             "Cannot preprocess this input type!");
+    }
     return new PreprocessJobAction(Input, OutputTy);
   }
   case phases::Precompile:
@@ -848,7 +850,8 @@
   }
 
   if (CCCPrintBindings) {
-    llvm::errs() << "bind - \"" << T.getName() << "\", inputs: [";
+    llvm::errs() << "# \"" << T.getToolChain().getTripleString() << '"'
+                 << " - \"" << T.getName() << "\", inputs: [";
     for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) {
       llvm::errs() << InputInfos[i].getAsString();
       if (i + 1 != e)

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Mar 30 01:36:42 2009
@@ -43,7 +43,10 @@
     assert(JA.getType() == types::TY_Plist && "Invalid output type.");
     CmdArgs.push_back("-analyze");
   } else if (isa<PreprocessJobAction>(JA)) {
-    CmdArgs.push_back("-E");
+    if (Output.getType() == types::TY_Dependencies)
+      CmdArgs.push_back("-Eonly");
+    else
+      CmdArgs.push_back("-E");
   } else if (isa<PrecompileJobAction>(JA)) {
     // No special option needed, driven by -x.
     //
@@ -218,7 +221,12 @@
         (A = Args.getLastArg(options::OPT_MMD))) {
       // Determine the output location.
       const char *DepFile;
-      if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+      if (Output.getType() == types::TY_Dependencies) {
+        if (Output.isPipe())
+          DepFile = "-";
+        else
+          DepFile = Output.getFilename();
+      } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
         DepFile = MF->getValue(Args);
       } else if (A->getOption().getId() == options::OPT_M ||
                  A->getOption().getId() == options::OPT_MM) {
@@ -234,8 +242,10 @@
       if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) {
         const char *DepTarget;
 
-        // If user provided -o, that is the dependency target.
-        if (Arg *A = Args.getLastArg(options::OPT_o)) {
+        // If user provided -o, that is the dependency target, except
+        // when we are only generating a dependency file.
+        Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+        if (OutputOpt && Output.getType() != types::TY_Dependencies) {
           DepTarget = A->getValue(Args); 
         } else {
           // Otherwise derive from the base input.
@@ -260,14 +270,9 @@
     Args.AddLastArg(CmdArgs, options::OPT_MP);
     Args.AddAllArgs(CmdArgs, options::OPT_MT);
 
-    Arg *Unsupported = Args.getLastArg(options::OPT_M);
-     if (!Unsupported) 
-      Unsupported = Args.getLastArg(options::OPT_MM);
-    if (!Unsupported) 
-      Unsupported = Args.getLastArg(options::OPT_MG);
-    if (!Unsupported) 
-      Unsupported = Args.getLastArg(options::OPT_MQ);
-    if (Unsupported) {
+    Arg *Unsupported;
+    if ((Unsupported = Args.getLastArg(options::OPT_MG)) ||
+        (Unsupported = Args.getLastArg(options::OPT_MQ))) {
       const Driver &D = getToolChain().getHost().getDriver();
       D.Diag(clang::diag::err_drv_unsupported_opt) 
         << Unsupported->getOption().getName();
@@ -371,9 +376,8 @@
   CmdArgs.push_back("-arch");
   CmdArgs.push_back(getToolChain().getArchName().c_str());
 
-  // FIXME: We should have a separate type for this.
-  if (Args.hasArg(options::OPT_M) || Args.hasArg(options::OPT_MM)) {
-    CmdArgs.push_back("-M");
+  if (Output.getType() == types::TY_Dependencies) {
+    // Handled with other dependency code.
   } else if (Output.isPipe()) {
     CmdArgs.push_back("-o");
     CmdArgs.push_back("-");

Modified: cfe/trunk/test/Frontend/dependency-gen.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen.c?rev=68027&r1=68026&r2=68027&view=diff

==============================================================================
--- cfe/trunk/test/Frontend/dependency-gen.c (original)
+++ cfe/trunk/test/Frontend/dependency-gen.c Mon Mar 30 01:36:42 2009
@@ -1,5 +1,7 @@
 // rdar://6533411
 // RUN: clang -MD -MF %t.d -c -x c -o %t.o /dev/null && 
-
 // RUN: grep '.*dependency-gen.c.out.tmp.o:' %t.d
-// RUN: grep '/dev/null' %t.d
+// RUN: grep '/dev/null' %t.d &&
+
+// RUN: clang -M -x c /dev/null -o %t.deps &&
+// RUN: grep 'null.o: /dev/null' %t.deps

Modified: cfe/trunk/tools/clang-cc/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/DependencyFile.cpp?rev=68027&r1=68026&r2=68027&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/DependencyFile.cpp (original)
+++ cfe/trunk/tools/clang-cc/DependencyFile.cpp Mon Mar 30 01:36:42 2009
@@ -91,11 +91,15 @@
   }
 
   std::string ErrMsg;
-  llvm::raw_ostream *OS =
-    new llvm::raw_fd_ostream(DependencyFile.c_str(), false, ErrStr);
-  if (!ErrMsg.empty()) {
-    ErrStr = "unable to open dependency file: " + ErrMsg;
-    return false;
+  llvm::raw_ostream *OS;
+  if (DependencyFile == "-") {
+    OS = new llvm::raw_stdout_ostream();
+  } else {
+    OS = new llvm::raw_fd_ostream(DependencyFile.c_str(), false, ErrStr);
+    if (!ErrMsg.empty()) {
+      ErrStr = "unable to open dependency file: " + ErrMsg;
+      return false;
+    }
   }
 
   DependencyFileCallback *PPDep = 





More information about the cfe-commits mailing list