summaryrefslogtreecommitdiffstats
path: root/llvm/tools/bugpoint/OptimizerDriver.cpp
diff options
context:
space:
mode:
authorJeff Cohen <jeffc@jolt-lang.org>2005-01-22 17:36:17 +0000
committerJeff Cohen <jeffc@jolt-lang.org>2005-01-22 17:36:17 +0000
commitc8f1f4bc8e569a71f0067b8825f3bdb77dcd56fd (patch)
tree55b1d008e1cf3c87f4bd6accbe2299dacdb7e907 /llvm/tools/bugpoint/OptimizerDriver.cpp
parente90b0c546976065cb6e09b29081e27e263159fef (diff)
downloadbcm5719-llvm-c8f1f4bc8e569a71f0067b8825f3bdb77dcd56fd.tar.gz
bcm5719-llvm-c8f1f4bc8e569a71f0067b8825f3bdb77dcd56fd.zip
Use binary mode for reading/writing bytecode files
llvm-svn: 19751
Diffstat (limited to 'llvm/tools/bugpoint/OptimizerDriver.cpp')
-rw-r--r--llvm/tools/bugpoint/OptimizerDriver.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp
index 709eff37e46..e97815f8a7e 100644
--- a/llvm/tools/bugpoint/OptimizerDriver.cpp
+++ b/llvm/tools/bugpoint/OptimizerDriver.cpp
@@ -15,6 +15,12 @@
//
//===----------------------------------------------------------------------===//
+// Note: as a short term hack, the old Unix-specific code and platform-
+// independent code co-exist via conditional compilation until it is verified
+// that the new code works correctly on Unix.
+
+#define PLATFORMINDEPENDENT
+
#include "BugDriver.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
@@ -24,9 +30,11 @@
#include "llvm/Support/FileUtilities.h"
#include "llvm/System/Path.h"
#include <fstream>
+#ifndef PLATFORMINDEPENDENT
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#endif
using namespace llvm;
/// writeProgramToFile - This writes the current "Program" to the named bytecode
@@ -34,7 +42,9 @@ using namespace llvm;
///
bool BugDriver::writeProgramToFile(const std::string &Filename,
Module *M) const {
- std::ofstream Out(Filename.c_str());
+ std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
+ std::ios::binary;
+ std::ofstream Out(Filename.c_str(), io_mode);
if (!Out.good()) return true;
WriteBytecodeToFile(M ? M : Program, Out, /*compression=*/true);
return false;
@@ -76,7 +86,9 @@ void BugDriver::EmitProgressBytecode(const std::string &ID, bool NoFlyer) {
static void RunChild(Module *Program,const std::vector<const PassInfo*> &Passes,
const std::string &OutFilename) {
- std::ofstream OutFile(OutFilename.c_str());
+ std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
+ std::ios::binary;
+ std::ofstream OutFile(OutFilename.c_str(), io_mode);
if (!OutFile.good()) {
std::cerr << "Error opening bytecode file: " << OutFilename << "\n";
exit(1);
@@ -119,6 +131,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
uniqueFilename.makeUnique();
OutputFilename = uniqueFilename.toString();
+#ifndef PLATFORMINDEPENDENT
pid_t child_pid;
switch (child_pid = fork()) {
case -1: // Error occurred
@@ -139,12 +152,16 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
}
bool ExitedOK = WIFEXITED(Status) && WEXITSTATUS(Status) == 0;
+#else
+ bool ExitedOK = false;
+#endif
// If we are supposed to delete the bytecode file or if the passes crashed,
// remove it now. This may fail if the file was never created, but that's ok.
if (DeleteOutput || !ExitedOK)
sys::Path(OutputFilename).destroyFile();
-
+
+#ifndef PLATFORMINDEPENDENT
if (!Quiet) {
if (ExitedOK)
std::cout << "Success!\n";
@@ -159,6 +176,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
else
std::cout << "Failed for unknown reason!\n";
}
+#endif
// Was the child successful?
return !ExitedOK;
OpenPOWER on IntegriCloud