Driver: ConstructJob also needs to know the destination (where to put
its commands).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67179 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/Job.h b/include/clang/Driver/Job.h
index d873739..f60f514 100644
--- a/include/clang/Driver/Job.h
+++ b/include/clang/Driver/Job.h
@@ -22,6 +22,7 @@
 
 namespace clang {
 namespace driver {
+  class Command;
 
 class Job {
 public:
@@ -41,6 +42,10 @@
 
   JobClass getKind() const { return Kind; }
 
+  /// addCommand - Append a command to the current job, which must be
+  /// either a piped job or a job list.
+  void addCommand(Command *C);
+
   static bool classof(const Job *) { return true; }      
 };
 
diff --git a/include/clang/Driver/Tool.h b/include/clang/Driver/Tool.h
index 070a162..d8b37e9 100644
--- a/include/clang/Driver/Tool.h
+++ b/include/clang/Driver/Tool.h
@@ -19,6 +19,7 @@
   class ArgList;
   class Compilation;
   class InputInfo;
+  class Job;
   class JobAction;
   class ToolChain;
   
@@ -49,11 +50,13 @@
   /// ConstructJob - Construct jobs to perform the action \arg JA,
   /// writing to \arg Output and with \arg Inputs.
   ///
+  /// \param Dest - Where to put the resulting commands.
   /// \param TCArgs - The argument list for this toolchain, with any
   /// tool chain specific translations applied.
   /// \param LinkingOutput - If this output will eventually feed the
   /// linker, then this is the final output name of the linked image.
   virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                            Job &Dest,
                             const InputInfo &Output, 
                             const InputInfoList &Inputs, 
                             const ArgList &TCArgs, 
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 1e4cd7f..f06166e 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -751,6 +751,7 @@
     if (!PJ) {
       PJ = new PipedJob();
       cast<JobList>(Dest)->addJob(PJ);
+      Dest = PJ;
     }
     Result = InputInfo(PJ, A->getType(), BaseInput);
   } else {
@@ -768,7 +769,7 @@
     llvm::errs() << "], output: " << Result.getAsString() << "\n";
   } else {
     const ArgList &TCArgs = C.getArgsForToolChain(TC);
-    T.ConstructJob(C, *JA, Result, InputInfos, TCArgs, LinkingOutput);
+    T.ConstructJob(C, *JA, *Dest, Result, InputInfos, TCArgs, LinkingOutput);
   }
 }
 
diff --git a/lib/Driver/InputInfo.h b/lib/Driver/InputInfo.h
index 6cef821..617e703 100644
--- a/lib/Driver/InputInfo.h
+++ b/lib/Driver/InputInfo.h
@@ -10,6 +10,8 @@
 #ifndef CLANG_LIB_DRIVER_INPUTINFO_H_
 #define CLANG_LIB_DRIVER_INPUTINFO_H_
 
+#include "clang/Driver/Types.h"
+
 #include <cassert>
 #include <string>
 
diff --git a/lib/Driver/Job.cpp b/lib/Driver/Job.cpp
index 1efc38a..222cf15 100644
--- a/lib/Driver/Job.cpp
+++ b/lib/Driver/Job.cpp
@@ -21,3 +21,11 @@
 PipedJob::PipedJob() : Job(PipedJobClass) {}
 
 JobList::JobList() : Job(JobListClass) {}
+
+void Job::addCommand(Command *C) {
+  if (PipedJob *PJ = dyn_cast<PipedJob>(this))
+    PJ->addCommand(C);
+  else
+    cast<JobList>(this)->addJob(C);
+}
+    
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 25023c1..20c3074 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -9,18 +9,29 @@
 
 #include "Tools.h"
 
+#include "clang/Driver/Arg.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Job.h"
+#include "clang/Driver/Util.h"
+
+#include "llvm/ADT/SmallVector.h"
+
+#include "InputInfo.h"
+
 using namespace clang::driver;
 using namespace clang::driver::tools;
 
 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
-                         const InputInfo &Output, 
+                         Job &Dest,
+                         const InputInfo &Output,
                          const InputInfoList &Inputs,
                          const ArgList &TCArgs,
                          const char *LinkingOutput) const {
 }
 
 void gcc::Preprocess::ConstructJob(Compilation &C, const JobAction &JA,
-                                   const InputInfo &Output, 
+                                   Job &Dest,
+                                   const InputInfo &Output,
                                    const InputInfoList &Inputs,
                                    const ArgList &TCArgs,
                                    const char *LinkingOutput) const {
@@ -28,7 +39,8 @@
 }
 
 void gcc::Precompile::ConstructJob(Compilation &C, const JobAction &JA,
-                                   const InputInfo &Output, 
+                                   Job &Dest,
+                                   const InputInfo &Output,
                                    const InputInfoList &Inputs,
                                    const ArgList &TCArgs,
                                    const char *LinkingOutput) const {
@@ -36,7 +48,8 @@
 }
 
 void gcc::Compile::ConstructJob(Compilation &C, const JobAction &JA,
-                                const InputInfo &Output, 
+                                Job &Dest,
+                                const InputInfo &Output,
                                 const InputInfoList &Inputs,
                                 const ArgList &TCArgs,
                                 const char *LinkingOutput) const {
@@ -44,7 +57,8 @@
 }
 
 void gcc::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
-                                 const InputInfo &Output, 
+                                 Job &Dest,
+                                 const InputInfo &Output,
                                  const InputInfoList &Inputs,
                                  const ArgList &TCArgs,
                                  const char *LinkingOutput) const {
@@ -52,7 +66,8 @@
 }
 
 void gcc::Link::ConstructJob(Compilation &C, const JobAction &JA,
-                             const InputInfo &Output, 
+                             Job &Dest,
+                             const InputInfo &Output,
                              const InputInfoList &Inputs,
                              const ArgList &TCArgs,
                              const char *LinkingOutput) const {
diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h
index d774e02..83dab06 100644
--- a/lib/Driver/Tools.h
+++ b/lib/Driver/Tools.h
@@ -27,6 +27,7 @@
     virtual bool hasIntegratedCPP() const { return true; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                              Job &Dest,
                               const InputInfo &Output, 
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs, 
@@ -44,6 +45,7 @@
     virtual bool hasIntegratedCPP() const { return false; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                              Job &Dest,
                               const InputInfo &Output, 
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs, 
@@ -59,6 +61,7 @@
     virtual bool hasIntegratedCPP() const { return true; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                              Job &Dest,
                               const InputInfo &Output, 
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs, 
@@ -74,6 +77,7 @@
     virtual bool hasIntegratedCPP() const { return true; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                              Job &Dest,
                               const InputInfo &Output, 
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs, 
@@ -89,6 +93,7 @@
     virtual bool hasIntegratedCPP() const { return false; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                              Job &Dest,
                               const InputInfo &Output, 
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs, 
@@ -104,6 +109,7 @@
     virtual bool hasIntegratedCPP() const { return false; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
+                              Job &Dest,
                               const InputInfo &Output, 
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs,