summaryrefslogtreecommitdiffstats
path: root/llvm
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
commitaf4c0bf44f76f0902e90ebf36a7072754f0b414f (patch)
treee4e833a9a6079eb7aceaa46f193c278533346798 /llvm
parentb289d4163b3421bc6d28ebf3b5b8c03256d7a347 (diff)
downloadbcm5719-llvm-af4c0bf44f76f0902e90ebf36a7072754f0b414f.tar.gz
bcm5719-llvm-af4c0bf44f76f0902e90ebf36a7072754f0b414f.zip
Add support for writing LLVM IR to a specified BitstreamWriter.
Patch by Lukasz Janyst! llvm-svn: 61251
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Bitcode/BitstreamWriter.h3
-rw-r--r--llvm/include/llvm/Bitcode/ReaderWriter.h5
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp29
3 files changed, 25 insertions, 12 deletions
diff --git a/llvm/include/llvm/Bitcode/BitstreamWriter.h b/llvm/include/llvm/Bitcode/BitstreamWriter.h
index f76bb88dee8..7fd23fe4166 100644
--- a/llvm/include/llvm/Bitcode/BitstreamWriter.h
+++ b/llvm/include/llvm/Bitcode/BitstreamWriter.h
@@ -76,6 +76,9 @@ public:
BlockInfoRecords.pop_back();
}
}
+
+ std::vector<unsigned char> &getBuffer() { return Out; }
+
//===--------------------------------------------------------------------===//
// Basic Primitives for emitting bits to the stream.
//===--------------------------------------------------------------------===//
diff --git a/llvm/include/llvm/Bitcode/ReaderWriter.h b/llvm/include/llvm/Bitcode/ReaderWriter.h
index f18b4fc090f..7b1e06f6553 100644
--- a/llvm/include/llvm/Bitcode/ReaderWriter.h
+++ b/llvm/include/llvm/Bitcode/ReaderWriter.h
@@ -22,6 +22,7 @@ namespace llvm {
class ModuleProvider;
class MemoryBuffer;
class ModulePass;
+ class BitstreamWriter;
class raw_ostream;
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
@@ -45,6 +46,10 @@ namespace llvm {
/// 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);
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());
}
OpenPOWER on IntegriCloud