[llvm-commits] [llvm] r61251 - in /llvm/trunk: include/llvm/Bitcode/BitstreamWriter.h include/llvm/Bitcode/ReaderWriter.h lib/Bitcode/Writer/BitcodeWriter.cpp
Chris Lattner
sabre at nondot.org
Fri Dec 19 10:38:02 PST 2008
Author: lattner
Date: Fri Dec 19 12:37:59 2008
New Revision: 61251
URL: http://llvm.org/viewvc/llvm-project?rev=61251&view=rev
Log:
Add support for writing LLVM IR to a specified BitstreamWriter.
Patch by Lukasz Janyst!
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h?rev=61251&r1=61250&r2=61251&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h Fri Dec 19 12:37:59 2008
@@ -76,6 +76,9 @@
BlockInfoRecords.pop_back();
}
}
+
+ std::vector<unsigned char> &getBuffer() { return Out; }
+
//===--------------------------------------------------------------------===//
// Basic Primitives for emitting bits to the stream.
//===--------------------------------------------------------------------===//
Modified: llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/ReaderWriter.h?rev=61251&r1=61250&r2=61251&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/ReaderWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/ReaderWriter.h Fri Dec 19 12:37:59 2008
@@ -22,6 +22,7 @@
class ModuleProvider;
class MemoryBuffer;
class ModulePass;
+ class BitstreamWriter;
class raw_ostream;
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
@@ -45,6 +46,10 @@
/// raw output stream.
void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
+ /// WriteBitcodeToStream - Write the specified module to the specified
+ /// raw output stream.
+ void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream);
+
/// CreateBitcodeWriterPass - Create and return a pass that writes the module
/// to the specified ostream.
ModulePass *CreateBitcodeWriterPass(std::ostream &Str);
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=61251&r1=61250&r2=61251&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Fri Dec 19 12:37:59 2008
@@ -1355,7 +1355,23 @@
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 @@
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());
}
More information about the llvm-commits
mailing list