diff options
author | Dan Gohman <gohman@apple.com> | 2010-05-27 20:06:51 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-05-27 20:06:51 +0000 |
commit | d928fb670fb3b0818fc23738e9c2418980bb141e (patch) | |
tree | 68719880eae13bc8ff7e27b0953370bbbbc2a562 | |
parent | 57041b6f3337f733eff945ca0c43434eb20c8410 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104878 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Bitcode/ReaderWriter.h | 3 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 4 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 8 |
3 files changed, 8 insertions, 7 deletions
diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h index 45eb801a8c..a186964743 100644 --- a/include/llvm/Bitcode/ReaderWriter.h +++ b/include/llvm/Bitcode/ReaderWriter.h @@ -40,7 +40,8 @@ namespace llvm { 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 diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 9bda6dca3d..884485dec9 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1662,10 +1662,6 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { 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()); diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index d094ed11de..cf520de7fc 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -377,12 +377,16 @@ int main(int argc, char **argv) { } // 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" |