[cfe-commits] r67223 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.def include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Driver.h lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Wed Mar 18 12:34:39 PDT 2009


Author: ddunbar
Date: Wed Mar 18 14:34:39 2009
New Revision: 67223

URL: http://llvm.org/viewvc/llvm-project?rev=67223&view=rev
Log:
Driver: Construct temporary file names.
 - This is still suboptimal, but should at least be workable.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def?rev=67223&r1=67222&r2=67223&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def Wed Mar 18 14:34:39 2009
@@ -30,6 +30,8 @@
      "unsupported use of internal gcc -Z option '%0'")
 DIAG(err_drv_output_argument_with_multiple_files, ERROR,
      "cannot specify -o when generating multiple output files")
+DIAG(err_drv_unable_to_make_temp, ERROR,
+     "unable to make temporary file: %0")
 
 DIAG(warn_drv_input_file_unused, WARNING,
      "%0: '%1' input file unused when '%2' is present")

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=67223&r1=67222&r2=67223&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Mar 18 14:34:39 2009
@@ -23,6 +23,8 @@
   "unsupported use of internal gcc -Z option '%0'">;
 def err_drv_output_argument_with_multiple_files : Error<
   "cannot specify -o when generating multiple output files">;
+def err_drv_unable_to_make_temp : Error<
+  "unable to make temporary file: %0">;
 
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input file unused when '%2' is present">;

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Wed Mar 18 14:34:39 2009
@@ -215,6 +215,12 @@
                                  const char *BaseInput,
                                  bool AtTopLevel) const;
 
+  /// GetTemporaryPath - Return the pathname of a temporary file to
+  /// use as part of compilation; the file will have the given suffix.
+  ///
+  /// GCC goes to extra lengths here to be a bit more robust.
+  std::string GetTemporaryPath(const char *Suffix) const;
+                        
   /// GetHostInfo - Construct a new host info object for the given
   /// host triple.
   const HostInfo *GetHostInfo(const char *HostTriple) const;

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Mar 18 14:34:39 2009
@@ -808,11 +808,9 @@
 
   // 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()));
+    std::string TmpName = 
+      GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+    return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
   }
 
   llvm::sys::Path BasePath(BaseInput);
@@ -861,6 +859,20 @@
   return llvm::sys::Path(Name);
 }
 
+std::string Driver::GetTemporaryPath(const char *Suffix) const {
+  // FIXME: This is lame; sys::Path should provide this function (in
+  // particular, it should know how to find the temporary files dir).
+  std::string Error;
+  llvm::sys::Path P("/tmp/cc");
+  if (P.makeUnique(false, &Error)) {
+    Diag(clang::diag::err_drv_unable_to_make_temp) << Error;
+    return "";
+  }
+
+  P.appendSuffix(Suffix);
+  return P.toString();
+}
+
 const HostInfo *Driver::GetHostInfo(const char *Triple) const {
   llvm::PrettyStackTraceString CrashInfo("Constructing host");
   // Dice into arch, platform, and OS. This matches 





More information about the cfe-commits mailing list