Bitcode: Don't expose WriteBitcodeToStream to clients.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 29 Feb 2012 20:30:56 +0000 (20:30 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 29 Feb 2012 20:30:56 +0000 (20:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151747 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/ReaderWriter.h
lib/Bitcode/Writer/BitcodeWriter.cpp
unittests/Bitcode/BitReaderTest.cpp

index ce975cdb8bfe0fe2d10359e9e26a30512446fac4..cc2b473f2c5780a7f47aaff54b12be6361850e47 100644 (file)
@@ -63,10 +63,6 @@ namespace llvm {
   /// should be in "binary" mode.
   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(raw_ostream &Str);
index 0e8d3acfd81b3c93838e42dd7305a965673b8d3f..7078169c4c5d9eed5de05284e2fe2cc34e31e1cc 100644 (file)
@@ -1823,6 +1823,7 @@ static void EmitDarwinBCTrailer(BitstreamWriter &Stream, unsigned BufferSize) {
   }
 }
 
+static void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream);
 
 /// WriteBitcodeToFile - Write the specified module to the specified output
 /// stream.
@@ -1838,9 +1839,7 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
   Out.write((char*)&Buffer.front(), Buffer.size());
 }
 
-/// WriteBitcodeToStream - Write the specified module to the specified output
-/// stream.
-void llvm::WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) {
+static void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) {
   // If this is darwin or another generic macho target, emit a file header and
   // trailer if needed.
   Triple TT(M->getTargetTriple());
index 91e6c15155807ae3208fc92923ea0e6ecf392f80..68cfe2836a29c4b19444ad396ec0b684d6b2cd46 100644 (file)
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -43,17 +44,16 @@ static Module *makeLLVMModule() {
   return Mod;
 }
 
-static void writeModuleToBuffer(std::vector<unsigned char> &Buffer) {
+static void writeModuleToBuffer(SmallVectorImpl<char> &Buffer) {
   Module *Mod = makeLLVMModule();
-  BitstreamWriter Stream(Buffer);
-  WriteBitcodeToStream(Mod, Stream);
+  raw_svector_ostream OS(Buffer);
+  WriteBitcodeToFile(Mod, OS);
 }
 
 TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
-  std::vector<unsigned char> Mem;
+  SmallString<1024> Mem;
   writeModuleToBuffer(Mem);
-  StringRef Data((const char*)&Mem[0], Mem.size());
-  MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false);
+  MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
   std::string errMsg;
   Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);
   PassManager passes;