[llvm] r184095 - Don't use PathV1.h in LTOCodeGenerator.cpp

Rafael Espindola rafael.espindola at gmail.com
Mon Jun 17 11:05:35 PDT 2013


Author: rafael
Date: Mon Jun 17 13:05:35 2013
New Revision: 184095

URL: http://llvm.org/viewvc/llvm-project?rev=184095&view=rev
Log:
Don't use PathV1.h in LTOCodeGenerator.cpp

This patch also adds a simpler version of sys::fs::remove and a tool_output_file
constructor for when we already have an open file.

Modified:
    llvm/trunk/include/llvm/Support/FileSystem.h
    llvm/trunk/include/llvm/Support/ToolOutputFile.h
    llvm/trunk/lib/Support/ToolOutputFile.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.cpp

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=184095&r1=184094&r2=184095&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Mon Jun 17 13:05:35 2013
@@ -292,6 +292,13 @@ error_code current_path(SmallVectorImpl<
 ///          successfully set, otherwise a platform specific error_code.
 error_code remove(const Twine &path, bool &existed);
 
+/// @brief Convenience function for clients that don't need to know if the file
+///        existed or not.
+inline error_code remove(const Twine &Path) {
+  bool Existed;
+  return remove(Path, Existed);
+}
+
 /// @brief Recursively remove all files below \a path, then \a path. Files are
 ///        removed as if by POSIX remove().
 ///

Modified: llvm/trunk/include/llvm/Support/ToolOutputFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ToolOutputFile.h?rev=184095&r1=184094&r2=184095&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ToolOutputFile.h (original)
+++ llvm/trunk/include/llvm/Support/ToolOutputFile.h Mon Jun 17 13:05:35 2013
@@ -49,6 +49,8 @@ public:
   tool_output_file(const char *filename, std::string &ErrorInfo,
                    unsigned Flags = 0);
 
+  tool_output_file(const char *Filename, int FD);
+
   /// os - Return the contained raw_fd_ostream.
   raw_fd_ostream &os() { return OS; }
 

Modified: llvm/trunk/lib/Support/ToolOutputFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ToolOutputFile.cpp?rev=184095&r1=184094&r2=184095&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ToolOutputFile.cpp (original)
+++ llvm/trunk/lib/Support/ToolOutputFile.cpp Mon Jun 17 13:05:35 2013
@@ -44,3 +44,7 @@ tool_output_file::tool_output_file(const
   if (!ErrorInfo.empty())
     Installer.Keep = true;
 }
+
+tool_output_file::tool_output_file(const char *Filename, int FD)
+    : Installer(Filename), OS(FD, true) {
+}

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=184095&r1=184094&r2=184095&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Mon Jun 17 13:05:35 2013
@@ -30,10 +30,10 @@
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/PassManager.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/PathV1.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -160,36 +160,33 @@ bool LTOCodeGenerator::writeMergedModule
 
 bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
   // make unique temp .o file to put generated object file
-  sys::PathWithStatus uniqueObjPath("lto-llvm.o");
-  if (uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg)) {
-    uniqueObjPath.eraseFromDisk();
+  SmallString<128> Filename;
+  int FD;
+  error_code EC = sys::fs::unique_file("lto-llvm-%%%%%%%.o",
+                                       FD, Filename);
+  if (EC) {
+    errMsg = EC.message();
     return true;
   }
-  sys::RemoveFileOnSignal(uniqueObjPath.str());
 
   // generate object file
-  bool genResult = false;
-  tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
-  if (!errMsg.empty()) {
-    uniqueObjPath.eraseFromDisk();
-    return true;
-  }
+  tool_output_file objFile(Filename.c_str(), FD);
 
-  genResult = this->generateObjectFile(objFile.os(), errMsg);
+  bool genResult = generateObjectFile(objFile.os(), errMsg);
   objFile.os().close();
   if (objFile.os().has_error()) {
     objFile.os().clear_error();
-    uniqueObjPath.eraseFromDisk();
+    sys::fs::remove(Twine(Filename));
     return true;
   }
 
   objFile.keep();
   if (genResult) {
-    uniqueObjPath.eraseFromDisk();
+    sys::fs::remove(Twine(Filename));
     return true;
   }
 
-  _nativeObjectPath = uniqueObjPath.str();
+  _nativeObjectPath = Filename.c_str();
   *name = _nativeObjectPath.c_str();
   return false;
 }
@@ -206,13 +203,13 @@ const void* LTOCodeGenerator::compile(si
   OwningPtr<MemoryBuffer> BuffPtr;
   if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) {
     errMsg = ec.message();
-    sys::Path(_nativeObjectPath).eraseFromDisk();
+    sys::fs::remove(_nativeObjectPath);
     return NULL;
   }
   _nativeObjectFile = BuffPtr.take();
 
   // remove temp files
-  sys::Path(_nativeObjectPath).eraseFromDisk();
+  sys::fs::remove(_nativeObjectPath);
 
   // return buffer, unless error
   if (_nativeObjectFile == NULL)





More information about the llvm-commits mailing list