Bitcode: Don't expose WriteBitcodeToStream to clients.

llvm-svn: 151747
This commit is contained in:
Daniel Dunbar 2012-02-29 20:30:56 +00:00
parent ff3f99bf0a
commit 5fa5ecf852
3 changed files with 8 additions and 13 deletions

View File

@ -63,10 +63,6 @@ namespace llvm {
/// should be in "binary" mode. /// should be in "binary" mode.
void WriteBitcodeToFile(const Module *M, raw_ostream &Out); 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 /// createBitcodeWriterPass - Create and return a pass that writes the module
/// to the specified ostream. /// to the specified ostream.
ModulePass *createBitcodeWriterPass(raw_ostream &Str); ModulePass *createBitcodeWriterPass(raw_ostream &Str);

View 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 /// WriteBitcodeToFile - Write the specified module to the specified output
/// stream. /// stream.
@ -1838,9 +1839,7 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
Out.write((char*)&Buffer.front(), Buffer.size()); Out.write((char*)&Buffer.front(), Buffer.size());
} }
/// WriteBitcodeToStream - Write the specified module to the specified output static void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) {
/// stream.
void llvm::WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) {
// If this is darwin or another generic macho target, emit a file header and // If this is darwin or another generic macho target, emit a file header and
// trailer if needed. // trailer if needed.
Triple TT(M->getTargetTriple()); Triple TT(M->getTargetTriple());

View File

@ -7,6 +7,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/ADT/SmallString.h"
#include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Verifier.h"
#include "llvm/Bitcode/BitstreamWriter.h" #include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/ReaderWriter.h"
@ -43,17 +44,16 @@ static Module *makeLLVMModule() {
return Mod; return Mod;
} }
static void writeModuleToBuffer(std::vector<unsigned char> &Buffer) { static void writeModuleToBuffer(SmallVectorImpl<char> &Buffer) {
Module *Mod = makeLLVMModule(); Module *Mod = makeLLVMModule();
BitstreamWriter Stream(Buffer); raw_svector_ostream OS(Buffer);
WriteBitcodeToStream(Mod, Stream); WriteBitcodeToFile(Mod, OS);
} }
TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677 TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
std::vector<unsigned char> Mem; SmallString<1024> Mem;
writeModuleToBuffer(Mem); writeModuleToBuffer(Mem);
StringRef Data((const char*)&Mem[0], Mem.size()); MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false);
std::string errMsg; std::string errMsg;
Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg); Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);
PassManager passes; PassManager passes;