Remove use of PathV1.h from ExecutionDriver.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184202 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-06-18 16:14:09 +00:00
parent 5cb84896bc
commit 9a23039e42

View File

@ -17,11 +17,16 @@
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/FileUtilities.h" #include "llvm/Support/FileUtilities.h"
#include "llvm/Support/PathV1.h"
#include "llvm/Support/SystemUtils.h" #include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <fstream> #include <fstream>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
#else
#include <io.h>
#endif
using namespace llvm; using namespace llvm;
namespace { namespace {
@ -266,16 +271,18 @@ bool BugDriver::initializeExecutionEnvironment() {
/// ///
void BugDriver::compileProgram(Module *M, std::string *Error) const { void BugDriver::compileProgram(Module *M, std::string *Error) const {
// Emit the program to a bitcode file... // Emit the program to a bitcode file...
sys::Path BitcodeFile (OutputPrefix + "-test-program.bc"); SmallString<128> BitcodeFile;
std::string ErrMsg; int BitcodeFD;
if (BitcodeFile.makeUnique(true, &ErrMsg)) { error_code EC = sys::fs::unique_file(
errs() << ToolName << ": Error making unique filename: " << ErrMsg OutputPrefix + "-test-program-%%%%%%%.bc", BitcodeFD, BitcodeFile);
if (EC) {
errs() << ToolName << ": Error making unique filename: " << EC.message()
<< "\n"; << "\n";
exit(1); exit(1);
} }
if (writeProgramToFile(BitcodeFile.str(), M)) { if (writeProgramToFile(BitcodeFile.str(), BitcodeFD, M)) {
errs() << ToolName << ": Error emitting bitcode to file '" errs() << ToolName << ": Error emitting bitcode to file '" << BitcodeFile
<< BitcodeFile.str() << "'!\n"; << "'!\n";
exit(1); exit(1);
} }
@ -303,15 +310,18 @@ std::string BugDriver::executeProgram(const Module *Program,
std::string ErrMsg; std::string ErrMsg;
if (BitcodeFile.empty()) { if (BitcodeFile.empty()) {
// Emit the program to a bitcode file... // Emit the program to a bitcode file...
sys::Path uniqueFilename(OutputPrefix + "-test-program.bc"); SmallString<128> UniqueFilename;
if (uniqueFilename.makeUnique(true, &ErrMsg)) { int UniqueFD;
error_code EC = sys::fs::unique_file(
OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename);
if (EC) {
errs() << ToolName << ": Error making unique filename: " errs() << ToolName << ": Error making unique filename: "
<< ErrMsg << "!\n"; << EC.message() << "!\n";
exit(1); exit(1);
} }
BitcodeFile = uniqueFilename.str(); BitcodeFile = UniqueFilename.str();
if (writeProgramToFile(BitcodeFile, Program)) { if (writeProgramToFile(BitcodeFile, UniqueFD, Program)) {
errs() << ToolName << ": Error emitting bitcode to file '" errs() << ToolName << ": Error emitting bitcode to file '"
<< BitcodeFile << "'!\n"; << BitcodeFile << "'!\n";
exit(1); exit(1);
@ -320,20 +330,23 @@ std::string BugDriver::executeProgram(const Module *Program,
} }
// Remove the temporary bitcode file when we are done. // Remove the temporary bitcode file when we are done.
sys::Path BitcodePath(BitcodeFile); std::string BitcodePath(BitcodeFile);
FileRemover BitcodeFileRemover(BitcodePath.str(), FileRemover BitcodeFileRemover(BitcodePath,
CreatedBitcode && !SaveTemps); CreatedBitcode && !SaveTemps);
if (OutputFile.empty()) OutputFile = OutputPrefix + "-execution-output"; if (OutputFile.empty()) OutputFile = OutputPrefix + "-execution-output";
// Check to see if this is a valid output filename... // Check to see if this is a valid output filename...
sys::Path uniqueFile(OutputFile); SmallString<128> UniqueFile;
if (uniqueFile.makeUnique(true, &ErrMsg)) { int UniqueFD;
error_code EC = sys::fs::unique_file(OutputFile, UniqueFD, UniqueFile);
if (EC) {
errs() << ToolName << ": Error making unique filename: " errs() << ToolName << ": Error making unique filename: "
<< ErrMsg << "\n"; << EC.message() << "\n";
exit(1); exit(1);
} }
OutputFile = uniqueFile.str(); OutputFile = UniqueFile.str();
close(UniqueFD);
// Figure out which shared objects to run, if any. // Figure out which shared objects to run, if any.
std::vector<std::string> SharedObjs(AdditionalSOs); std::vector<std::string> SharedObjs(AdditionalSOs);
@ -440,15 +453,15 @@ bool BugDriver::diffProgram(const Module *Program,
bool RemoveBitcode, bool RemoveBitcode,
std::string *ErrMsg) const { std::string *ErrMsg) const {
// Execute the program, generating an output file... // Execute the program, generating an output file...
sys::Path Output(executeProgram(Program, "", BitcodeFile, SharedObject, 0, std::string Output(
ErrMsg)); executeProgram(Program, "", BitcodeFile, SharedObject, 0, ErrMsg));
if (!ErrMsg->empty()) if (!ErrMsg->empty())
return false; return false;
std::string Error; std::string Error;
bool FilesDifferent = false; bool FilesDifferent = false;
if (int Diff = DiffFilesWithTolerance(ReferenceOutputFile, if (int Diff = DiffFilesWithTolerance(ReferenceOutputFile,
Output.str(), Output,
AbsTolerance, RelTolerance, &Error)) { AbsTolerance, RelTolerance, &Error)) {
if (Diff == 2) { if (Diff == 2) {
errs() << "While diffing output: " << Error << '\n'; errs() << "While diffing output: " << Error << '\n';
@ -458,12 +471,12 @@ bool BugDriver::diffProgram(const Module *Program,
} }
else { else {
// Remove the generated output if there are no differences. // Remove the generated output if there are no differences.
Output.eraseFromDisk(); sys::fs::remove(Output);
} }
// Remove the bitcode file if we are supposed to. // Remove the bitcode file if we are supposed to.
if (RemoveBitcode) if (RemoveBitcode)
sys::Path(BitcodeFile).eraseFromDisk(); sys::fs::remove(BitcodeFile);
return FilesDifferent; return FilesDifferent;
} }