1 //===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // BitcodeWriterPass implementation. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/Bitcode/ReaderWriter.h" 15 #include "llvm/Pass.h" 16 using namespace llvm; 17 18 namespace { 19 class WriteBitcodePass : public ModulePass { 20 // FIXME: Kill off std::ostream 21 std::ostream *Out; 22 raw_ostream *RawOut; // raw_ostream to print on 23 public: 24 static char ID; // Pass identification, replacement for typeid 25 explicit WriteBitcodePass(std::ostream &o) 26 : ModulePass(&ID), Out(&o), RawOut(0) {} 27 explicit WriteBitcodePass(raw_ostream &o) 28 : ModulePass(&ID), Out(0), RawOut(&o) {} 29 30 const char *getPassName() const { return "Bitcode Writer"; } 31 32 bool runOnModule(Module &M) { 33 if (Out) { 34 WriteBitcodeToFile(&M, *Out); 35 } else { 36 WriteBitcodeToFile(&M, *RawOut); 37 } 38 return false; 39 } 40 }; 41 } 42 43 char WriteBitcodePass::ID = 0; 44 45 /// CreateBitcodeWriterPass - Create and return a pass that writes the module 46 /// to the specified ostream. 47 ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) { 48 return new WriteBitcodePass(Str); 49 } 50 51 52 /// createBitcodeWriterPass - Create and return a pass that writes the module 53 /// to the specified ostream. 54 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) { 55 return new WriteBitcodePass(Str); 56 } 57