[llvm-commits] [llvm] r104878 - in /llvm/trunk: include/llvm/Bitcode/ReaderWriter.h lib/Bitcode/Writer/BitcodeWriter.cpp tools/opt/opt.cpp
Dan Gohman
gohman at apple.com
Thu May 27 13:06:51 PDT 2010
Author: djg
Date: Thu May 27 15:06:51 2010
New Revision: 104878
URL: http://llvm.org/viewvc/llvm-project?rev=104878&view=rev
Log:
Don't special-case stdout in llvm::WriteBitcodeToFile; just consider
it to be the caller's responsibility to provide a stream in binary
mode. This fixes a layering violation and avoids an outs() call.
Modified:
llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/ReaderWriter.h?rev=104878&r1=104877&r2=104878&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/ReaderWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/ReaderWriter.h Thu May 27 15:06:51 2010
@@ -40,7 +40,8 @@
std::string *ErrMsg = 0);
/// WriteBitcodeToFile - Write the specified module to the specified
- /// raw output stream.
+ /// raw output stream. For streams where it matters, the given stream
+ /// should be in "binary" mode.
void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
/// WriteBitcodeToStream - Write the specified module to the specified
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=104878&r1=104877&r2=104878&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu May 27 15:06:51 2010
@@ -1662,10 +1662,6 @@
WriteBitcodeToStream( M, Stream );
- // If writing to stdout, set binary mode.
- if (&llvm::outs() == &Out)
- sys::Program::ChangeStdoutToBinary();
-
// Write the generated bitstream to "Out".
Out.write((char*)&Buffer.front(), Buffer.size());
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=104878&r1=104877&r2=104878&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Thu May 27 15:06:51 2010
@@ -377,12 +377,16 @@
}
// Figure out what stream we are supposed to write to...
- // FIXME: outs() is not binary!
raw_ostream *Out = 0;
bool DeleteStream = false;
if (!NoOutput && !AnalyzeOnly) {
if (OutputFilename == "-") {
- Out = &outs(); // Default to printing to stdout...
+ // Print to stdout.
+ Out = &outs();
+ // If we're printing a bitcode file, switch stdout to binary mode.
+ // FIXME: This switches outs() globally, not just for the bitcode output.
+ if (!OutputAssembly)
+ sys::Program::ChangeStdoutToBinary();
} else {
if (NoOutput || AnalyzeOnly) {
errs() << "WARNING: The -o (output filename) option is ignored when\n"
More information about the llvm-commits
mailing list