summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-11-13 05:01:07 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-11-13 05:01:07 +0000
commited90e701f07158b5e042f01c6f59d27f5325c37e (patch)
treea29c0c59e49b7db8bf7565eb92cbb49d88cb18c7
parent9aa657663a7ad13787674d131d759b73c6ae2dd3 (diff)
downloadbcm5719-llvm-ed90e701f07158b5e042f01c6f59d27f5325c37e.tar.gz
bcm5719-llvm-ed90e701f07158b5e042f01c6f59d27f5325c37e.zip
Add Binary flag to raw_fd_ostream constructor.
Document raw_fd_ostream's treatment of "-". llvm-svn: 59219
-rw-r--r--llvm/include/llvm/Support/raw_ostream.h7
-rw-r--r--llvm/lib/Support/raw_ostream.cpp15
-rw-r--r--llvm/tools/llc/llc.cpp7
-rw-r--r--llvm/tools/lto/LTOCodeGenerator.cpp2
4 files changed, 25 insertions, 6 deletions
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 9b307dbf956..709a063e2ae 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -156,7 +156,12 @@ public:
/// error occurs, information about the error is put into ErrorInfo,
/// and the stream should be immediately destroyed; the string will
/// be empty if no error occurred.
- raw_fd_ostream(const char *Filename, std::string &ErrorInfo);
+ ///
+ /// \param Filename - The file to open. If this is "-" then the
+ /// stream will use stdout instead.
+ /// \param Binary - The file should be opened in binary mode on
+ /// platforms that support this distinction.
+ raw_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo);
/// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
/// ShouldClose is true, this closes the file when
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 8c704cb4714..a8e6c782bc9 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -13,6 +13,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Format.h"
+#include "llvm/System/Program.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Config/config.h"
#include <ostream>
@@ -200,17 +201,27 @@ void format_object_base::home() {
/// occurs, information about the error is put into ErrorInfo, and the
/// stream should be immediately destroyed; the string will be empty
/// if no error occurred.
-raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo) {
+raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary,
+ std::string &ErrorInfo) {
ErrorInfo.clear();
// Handle "-" as stdout.
if (Filename[0] == '-' && Filename[1] == 0) {
FD = STDOUT_FILENO;
+ // If user requested binary then put stdout into binary mode if
+ // possible.
+ if (Binary)
+ sys::Program::ChangeStdoutToBinary();
ShouldClose = false;
return;
}
- FD = open(Filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ int Flags = O_WRONLY|O_CREAT|O_TRUNC;
+#ifdef O_BINARY
+ if (Binary)
+ Flags |= O_BINARY;
+#endif
+ FD = open(Filename, Flags, 0644);
if (FD < 0) {
ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
ShouldClose = false;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index f185490725a..bd915ae7d6f 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -125,7 +125,7 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
std::string error;
- raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), error);
+ raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), true, error);
if (!error.empty()) {
std::cerr << error << '\n';
delete Out;
@@ -142,6 +142,7 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
OutputFilename = GetFileNameRoot(InputFilename);
+ bool Binary = false;
switch (FileType) {
case TargetMachine::AssemblyFile:
if (MArch->Name[0] == 'c') {
@@ -156,9 +157,11 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
break;
case TargetMachine::ObjectFile:
OutputFilename += ".o";
+ Binary = true;
break;
case TargetMachine::DynamicLibrary:
OutputFilename += LTDL_SHLIB_EXT;
+ Binary = true;
break;
}
@@ -175,7 +178,7 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
std::string error;
- raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), error);
+ raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), Binary, error);
if (!error.empty()) {
std::cerr << error << '\n';
delete Out;
diff --git a/llvm/tools/lto/LTOCodeGenerator.cpp b/llvm/tools/lto/LTOCodeGenerator.cpp
index 0474a88839f..e0e1f52b330 100644
--- a/llvm/tools/lto/LTOCodeGenerator.cpp
+++ b/llvm/tools/lto/LTOCodeGenerator.cpp
@@ -165,7 +165,7 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
// generate assembly code
bool genResult = false;
{
- raw_fd_ostream asmFile(uniqueAsmPath.c_str(), errMsg);
+ raw_fd_ostream asmFile(uniqueAsmPath.c_str(), false, errMsg);
if (!errMsg.empty())
return NULL;
genResult = this->generateAssemblyCode(asmFile, errMsg);
OpenPOWER on IntegriCloud