[llvm-commits] CVS: llvm/tools/bugpoint/OptimizerDriver.cpp
Jeff Cohen
jeffc at jolt-lang.org
Sat Jan 22 09:36:31 PST 2005
Changes in directory llvm/tools/bugpoint:
OptimizerDriver.cpp updated: 1.26 -> 1.27
---
Log message:
Use binary mode for reading/writing bytecode files
---
Diffs of the changes: (+21 -3)
OptimizerDriver.cpp | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
Index: llvm/tools/bugpoint/OptimizerDriver.cpp
diff -u llvm/tools/bugpoint/OptimizerDriver.cpp:1.26 llvm/tools/bugpoint/OptimizerDriver.cpp:1.27
--- llvm/tools/bugpoint/OptimizerDriver.cpp:1.26 Thu Dec 16 17:04:20 2004
+++ llvm/tools/bugpoint/OptimizerDriver.cpp Sat Jan 22 11:36:16 2005
@@ -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 @@
///
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 @@
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 @@
uniqueFilename.makeUnique();
OutputFilename = uniqueFilename.toString();
+#ifndef PLATFORMINDEPENDENT
pid_t child_pid;
switch (child_pid = fork()) {
case -1: // Error occurred
@@ -139,12 +152,16 @@
}
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 @@
else
std::cout << "Failed for unknown reason!\n";
}
+#endif
// Was the child successful?
return !ExitedOK;
More information about the llvm-commits
mailing list