[cfe-commits] r67088 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Tue Mar 17 10:53:55 PDT 2009


Author: ddunbar
Date: Tue Mar 17 12:53:55 2009
New Revision: 67088

URL: http://llvm.org/viewvc/llvm-project?rev=67088&view=rev
Log:
Driver: Add logic for computing where to put job outputs (pipe,
temporary file, user provided name, derived name).

Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Tue Mar 17 12:53:55 2009
@@ -28,6 +28,7 @@
   class Compilation;
   class HostInfo;
   class InputInfo;
+  class JobAction;
   class OptTable;
   class PipedJob;
   class ToolChain;
@@ -203,6 +204,20 @@
                           const char *LinkingOutput,
                           InputInfo &Result) const;
 
+  /// GetNamedOutputPath - Return the name to use for the output of
+  /// the action \arg JA. The result is appended to the compilation's
+  /// list of temporary or result files, as appropriate.
+  ///
+  /// \param C - The compilation.
+  /// \param JA - The action of interest.
+  /// \param BaseInput - The original input file that this action was
+  /// triggered by.
+  /// \param AtTopLevel - Whether this is a "top-level" action.
+  const char *GetNamedOutputPath(Compilation &C, 
+                                 const JobAction &JA,
+                                 const char *BaseInput,
+                                 bool AtTopLevel) const;
+
   /// GetHostInfo - Construct a new host info object for the given
   /// host triple.
   static HostInfo *GetHostInfo(const char *HostTriple);

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 17 12:53:55 2009
@@ -717,18 +717,89 @@
   // Figure out where to put the job (pipes).
   Job *Dest = &C.getJobs();
   if (InputInfos[0].isPipe()) {
+    assert(TryToUsePipeInput && "Unrequested pipe!");
     assert(InputInfos.size() == 1 && "Unexpected pipe with multiple inputs.");
     Dest = &InputInfos[0].getPipe();
   }
 
   // Always use the first input as the base input.
   const char *BaseInput = InputInfos[0].getBaseInput();
-  const char *Output = "foo";
+
+  // Determine the place to write output to (nothing, pipe, or
+  // filename) and where to put the new job.
+  PipedJob *OutputJob = 0;
+  const char *Output = 0;
+  if (JA->getType() == types::TY_Nothing) {
+    ;
+  } else if (OutputToPipe) {
+    // Append to current piped job or create a new one as appropriate.
+    if (PipedJob *PJ = dyn_cast<PipedJob>(Dest)) {
+      OutputJob = PJ;
+      Dest = OutputJob;
+    } else {
+      OutputJob = new PipedJob();
+      cast<JobList>(Dest)->addJob(OutputJob);
+      Dest = OutputJob;
+    }
+  } else {
+    Output = GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel);
+  }
+
   // FIXME: Make the job.
 
   Result = InputInfo(Output, A->getType(), BaseInput);
 }
 
+const char *Driver::GetNamedOutputPath(Compilation &C, 
+                                       const JobAction &JA,
+                                       const char *BaseInput,
+                                       bool AtTopLevel) const {
+  // Output to a user requested destination?
+  if (AtTopLevel) {
+    if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+      return C.addResultFile(FinalOutput->getValue(C.getArgs()));
+  }
+
+  // Output to a temporary file?
+  if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) {
+    // FIXME: Get temporary name.
+    std::string Name("/tmp/foo");
+    Name += '.';
+    Name += types::getTypeTempSuffix(JA.getType());
+    return C.addTempFile(C.getArgs().MakeArgString(Name.c_str()));
+  }
+
+  llvm::sys::Path BasePath(BaseInput);
+  std::string BaseName(BasePath.getBasename());
+
+  // Determine what the derived output name should be.
+  const char *NamedOutput;
+  if (JA.getType() == types::TY_Image) {
+    NamedOutput = DefaultImageName.c_str();
+  } else {
+    const char *Suffix = types::getTypeTempSuffix(JA.getType());
+    assert(Suffix && "All types used for output should have a suffix.");
+
+    std::string::size_type End = std::string::npos;
+    if (!types::appendSuffixForType(JA.getType()))
+      End = BaseName.rfind('.');
+    std::string Suffixed(BaseName.substr(0, End));
+    Suffixed += '.';
+    Suffixed += Suffix;
+    NamedOutput = C.getArgs().MakeArgString(Suffixed.c_str());
+  }
+
+  // As an annoying special case, PCH generation doesn't strip the
+  // pathname.
+  if (JA.getType() == types::TY_PCH) {
+    BasePath.eraseComponent();
+    BasePath.appendComponent(NamedOutput);
+    return C.addResultFile(C.getArgs().MakeArgString(BasePath.c_str()));
+  } else {
+    return C.addResultFile(NamedOutput);
+  }
+}
+
 llvm::sys::Path Driver::GetFilePath(const char *Name,
                                     const ToolChain *TC) const {
   // FIXME: Implement.





More information about the cfe-commits mailing list