llvm.org GIT mirror llvm / 68c0efa
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184095 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
4 changed file(s) with 33 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
291291 /// successfully set, otherwise a platform specific error_code.
292292 error_code remove(const Twine &path, bool &existed);
293293
294 /// @brief Convenience function for clients that don't need to know if the file
295 /// existed or not.
296 inline error_code remove(const Twine &Path) {
297 bool Existed;
298 return remove(Path, Existed);
299 }
300
294301 /// @brief Recursively remove all files below \a path, then \a path. Files are
295302 /// removed as if by POSIX remove().
296303 ///
4848 tool_output_file(const char *filename, std::string &ErrorInfo,
4949 unsigned Flags = 0);
5050
51 tool_output_file(const char *Filename, int FD);
52
5153 /// os - Return the contained raw_fd_ostream.
5254 raw_fd_ostream &os() { return OS; }
5355
4343 if (!ErrorInfo.empty())
4444 Installer.Keep = true;
4545 }
46
47 tool_output_file::tool_output_file(const char *Filename, int FD)
48 : Installer(Filename), OS(FD, true) {
49 }
2929 #include "llvm/MC/SubtargetFeature.h"
3030 #include "llvm/PassManager.h"
3131 #include "llvm/Support/CommandLine.h"
32 #include "llvm/Support/FileSystem.h"
3233 #include "llvm/Support/FormattedStream.h"
3334 #include "llvm/Support/Host.h"
3435 #include "llvm/Support/MemoryBuffer.h"
35 #include "llvm/Support/PathV1.h"
3636 #include "llvm/Support/Signals.h"
3737 #include "llvm/Support/TargetRegistry.h"
3838 #include "llvm/Support/TargetSelect.h"
159159
160160 bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
161161 // make unique temp .o file to put generated object file
162 sys::PathWithStatus uniqueObjPath("lto-llvm.o");
163 if (uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg)) {
164 uniqueObjPath.eraseFromDisk();
165 return true;
166 }
167 sys::RemoveFileOnSignal(uniqueObjPath.str());
162 SmallString<128> Filename;
163 int FD;
164 error_code EC = sys::fs::unique_file("lto-llvm-%%%%%%%.o",
165 FD, Filename);
166 if (EC) {
167 errMsg = EC.message();
168 return true;
169 }
168170
169171 // generate object file
170 bool genResult = false;
171 tool_output_file objFile(uniqueObjPath.c_str(), errMsg);
172 if (!errMsg.empty()) {
173 uniqueObjPath.eraseFromDisk();
174 return true;
175 }
176
177 genResult = this->generateObjectFile(objFile.os(), errMsg);
172 tool_output_file objFile(Filename.c_str(), FD);
173
174 bool genResult = generateObjectFile(objFile.os(), errMsg);
178175 objFile.os().close();
179176 if (objFile.os().has_error()) {
180177 objFile.os().clear_error();
181 uniqueObjPath.eraseFromDisk();
178 sys::fs::remove(Twine(Filename));
182179 return true;
183180 }
184181
185182 objFile.keep();
186183 if (genResult) {
187 uniqueObjPath.eraseFromDisk();
188 return true;
189 }
190
191 _nativeObjectPath = uniqueObjPath.str();
184 sys::fs::remove(Twine(Filename));
185 return true;
186 }
187
188 _nativeObjectPath = Filename.c_str();
192189 *name = _nativeObjectPath.c_str();
193190 return false;
194191 }
205202 OwningPtr BuffPtr;
206203 if (error_code ec = MemoryBuffer::getFile(name, BuffPtr, -1, false)) {
207204 errMsg = ec.message();
208 sys::Path(_nativeObjectPath).eraseFromDisk();
205 sys::fs::remove(_nativeObjectPath);
209206 return NULL;
210207 }
211208 _nativeObjectFile = BuffPtr.take();
212209
213210 // remove temp files
214 sys::Path(_nativeObjectPath).eraseFromDisk();
211 sys::fs::remove(_nativeObjectPath);
215212
216213 // return buffer, unless error
217214 if (_nativeObjectFile == NULL)