aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-19 18:37:59 +0000
committerChris Lattner <sabre@nondot.org>2008-12-19 18:37:59 +0000
commit38e77214558f3a5f917896df575de1c01ee60f47 (patch)
tree0d8470304fd57475a18758d369abd3f96f83b422 /lib/Bitcode
parent018a34c5763dadc990af74cd15d97c7fdb560f3c (diff)
downloadexternal_llvm-38e77214558f3a5f917896df575de1c01ee60f47.zip
external_llvm-38e77214558f3a5f917896df575de1c01ee60f47.tar.gz
external_llvm-38e77214558f3a5f917896df575de1c01ee60f47.tar.bz2
Add support for writing LLVM IR to a specified BitstreamWriter.
Patch by Lukasz Janyst! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61251 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index adf49a5..b98dab7 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/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());
}