1 //===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===// 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/BitcodeWriterPass.h" 15 #include "llvm/Bitcode/ReaderWriter.h" 16 #include "llvm/IR/Module.h" 17 #include "llvm/IR/PassManager.h" 18 #include "llvm/Pass.h" 19 using namespace llvm; 20 21 PreservedAnalyses BitcodeWriterPass::run(Module *M) { 22 WriteBitcodeToFile(M, OS); 23 return PreservedAnalyses::all(); 24 } 25 26 namespace { 27 class WriteBitcodePass : public ModulePass { 28 raw_ostream &OS; // raw_ostream to print on 29 public: 30 static char ID; // Pass identification, replacement for typeid 31 explicit WriteBitcodePass(raw_ostream &o) 32 : ModulePass(ID), OS(o) {} 33 34 const char *getPassName() const override { return "Bitcode Writer"; } 35 36 bool runOnModule(Module &M) override { 37 WriteBitcodeToFile(&M, OS); 38 return false; 39 } 40 }; 41 } 42 43 char WriteBitcodePass::ID = 0; 44 45 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) { 46 return new WriteBitcodePass(Str); 47 } 48