llvm.org GIT mirror llvm / c9c08fb
Switch FileRemover from PathV1 to V2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128630 91177308-0d34-0410-b5e6-96231b3b80d8 Michael J. Spencer 9 years ago
6 changed file(s) with 30 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1414 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
1515 #define LLVM_SUPPORT_FILEUTILITIES_H
1616
17 #include "llvm/Support/FileSystem.h"
1718 #include "llvm/Support/Path.h"
1819
1920 namespace llvm {
3637 /// specified (if deleteIt is true).
3738 ///
3839 class FileRemover {
39 sys::Path Filename;
40 SmallString<128> Filename;
4041 bool DeleteIt;
4142 public:
4243 FileRemover() : DeleteIt(false) {}
4344
44 explicit FileRemover(const sys::Path &filename, bool deleteIt = true)
45 : Filename(filename), DeleteIt(deleteIt) {}
45 explicit FileRemover(const Twine& filename, bool deleteIt = true)
46 : DeleteIt(deleteIt) {
47 filename.toVector(Filename);
48 }
4649
4750 ~FileRemover() {
4851 if (DeleteIt) {
4952 // Ignore problems deleting the file.
50 Filename.eraseFromDisk();
53 bool existed;
54 sys::fs::remove(Filename.str(), existed);
5155 }
5256 }
5357
5458 /// setFile - Give ownership of the file to the FileRemover so it will
5559 /// be removed when the object is destroyed. If the FileRemover already
5660 /// had ownership of a file, remove it first.
57 void setFile(const sys::Path &filename, bool deleteIt = true) {
58 if (DeleteIt)
59 Filename.eraseFromDisk();
61 void setFile(const Twine& filename, bool deleteIt = true) {
62 if (DeleteIt) {
63 // Ignore problems deleting the file.
64 bool existed;
65 sys::fs::remove(Filename.str(), existed);
66 }
6067
61 Filename = filename;
68 Filename.clear();
69 filename.toVector(Filename);
6270 DeleteIt = deleteIt;
6371 }
6472
193193 // Make sure the reference output file gets deleted on exit from this
194194 // function, if appropriate.
195195 sys::Path ROF(ReferenceOutputFile);
196 FileRemover RemoverInstance(ROF, CreatedOutput && !SaveTemps);
196 FileRemover RemoverInstance(ROF.str(), CreatedOutput && !SaveTemps);
197197
198198 // Diff the output of the raw program against the reference output. If it
199199 // matches, then we assume there is a miscompilation bug and try to
322322 }
323323
324324 // Remove the temporary bitcode file when we are done.
325 FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
325 FileRemover BitcodeFileRemover(BitcodeFile.str(), !SaveTemps);
326326
327327 // Actually compile the program!
328328 Interpreter->compileProgram(BitcodeFile.str(), Error, Timeout, MemoryLimit);
363363
364364 // Remove the temporary bitcode file when we are done.
365365 sys::Path BitcodePath(BitcodeFile);
366 FileRemover BitcodeFileRemover(BitcodePath, CreatedBitcode && !SaveTemps);
366 FileRemover BitcodeFileRemover(BitcodePath.str(),
367 CreatedBitcode && !SaveTemps);
367368
368369 if (OutputFile.empty()) OutputFile = OutputPrefix + "-execution-output";
369370
942942 }
943943 delete Test;
944944
945 FileRemover TestModuleBCRemover(TestModuleBC, !SaveTemps);
945 FileRemover TestModuleBCRemover(TestModuleBC.str(), !SaveTemps);
946946
947947 // Make the shared library
948948 sys::Path SafeModuleBC("bugpoint.safe.bc");
958958 exit(1);
959959 }
960960
961 FileRemover SafeModuleBCRemover(SafeModuleBC, !SaveTemps);
961 FileRemover SafeModuleBCRemover(SafeModuleBC.str(), !SaveTemps);
962962
963963 std::string SharedObject = BD.compileSharedObject(SafeModuleBC.str(), Error);
964964 if (!Error.empty())
965965 return false;
966966 delete Safe;
967967
968 FileRemover SharedObjectRemover(sys::Path(SharedObject), !SaveTemps);
968 FileRemover SharedObjectRemover(SharedObject, !SaveTemps);
969969
970970 // Run the code generator on the `Test' code, loading the shared library.
971971 // The function returns whether or not the new output differs from reference.
502502 sys::Path OutputAsmFile;
503503 GCC::FileType FileKind = OutputCode(Bitcode, OutputAsmFile, *Error, Timeout,
504504 MemoryLimit);
505 FileRemover OutFileRemover(OutputAsmFile, !SaveTemps);
505 FileRemover OutFileRemover(OutputAsmFile.str(), !SaveTemps);
506506
507507 std::vector GCCArgs(ArgsForGCC);
508508 GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
674674 sys::Path OutputCFile;
675675 OutputCode(Bitcode, OutputCFile, *Error, Timeout, MemoryLimit);
676676
677 FileRemover CFileRemove(OutputCFile, !SaveTemps);
677 FileRemover CFileRemove(OutputCFile.str(), !SaveTemps);
678678
679679 std::vector GCCArgs(ArgsForGCC);
680680 GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
850850 errs() << "\n";
851851 );
852852
853 FileRemover OutputBinaryRemover(OutputBinary, !SaveTemps);
853 FileRemover OutputBinaryRemover(OutputBinary.str(), !SaveTemps);
854854
855855 if (RemoteClientPath.isEmpty()) {
856856 DEBUG(errs() << "");
551551 }
552552
553553 // Arrange for the bitcode output file to be deleted on any errors.
554 BitcodeOutputRemover.setFile(sys::Path(BitcodeOutputFilename));
554 BitcodeOutputRemover.setFile(BitcodeOutputFilename);
555555 sys::RemoveFileOnSignal(sys::Path(BitcodeOutputFilename));
556556
557557 // Arrange for the output file to be deleted on any errors.
558558 if (!LinkAsLibrary) {
559 OutputRemover.setFile(sys::Path(OutputFilename));
559 OutputRemover.setFile(OutputFilename);
560560 sys::RemoveFileOnSignal(sys::Path(OutputFilename));
561561 }
562562
656656 AssemblyFile.appendSuffix("s");
657657
658658 // Mark the output files for removal.
659 FileRemover AssemblyFileRemover(AssemblyFile);
659 FileRemover AssemblyFileRemover(AssemblyFile.str());
660660 sys::RemoveFileOnSignal(AssemblyFile);
661661
662662 // Determine the locations of the llc and gcc programs.
683683 CFile.appendSuffix("cbe.c");
684684
685685 // Mark the output files for removal.
686 FileRemover CFileRemover(CFile);
686 FileRemover CFileRemover(CFile.str());
687687 sys::RemoveFileOnSignal(CFile);
688688
689689 // Determine the locations of the llc and gcc programs.