From af4c0bf44f76f0902e90ebf36a7072754f0b414f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 19 Dec 2008 18:37:59 +0000 Subject: Add support for writing LLVM IR to a specified BitstreamWriter. Patch by Lukasz Janyst! llvm-svn: 61251 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'llvm/lib/Bitcode/Writer') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index adf49a524a3..b98dab70924 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1355,7 +1355,23 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { BitstreamWriter Stream(Buffer); Buffer.reserve(256*1024); + + 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()); + // Make sure it hits disk now. + Out.flush(); +} + +/// WriteBitcodeToStream - Write the specified module to the specified output +/// stream. +void llvm::WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) { // If this is darwin, emit a file header and trailer if needed. bool isDarwin = M->getTargetTriple().find("-darwin") != std::string::npos; if (isDarwin) @@ -1373,16 +1389,5 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { WriteModule(M, Stream); if (isDarwin) - EmitDarwinBCTrailer(Stream, Buffer.size()); - - - // 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()); - - // Make sure it hits disk now. - Out.flush(); + EmitDarwinBCTrailer(Stream, Stream.getBuffer().size()); } -- cgit v1.2.3