LLVM API Documentation
00001 //===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // BitcodeWriterPass implementation. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Bitcode/BitcodeWriterPass.h" 00015 #include "llvm/Bitcode/ReaderWriter.h" 00016 #include "llvm/IR/Module.h" 00017 #include "llvm/IR/PassManager.h" 00018 #include "llvm/Pass.h" 00019 using namespace llvm; 00020 00021 PreservedAnalyses BitcodeWriterPass::run(Module *M) { 00022 WriteBitcodeToFile(M, OS); 00023 return PreservedAnalyses::all(); 00024 } 00025 00026 namespace { 00027 class WriteBitcodePass : public ModulePass { 00028 raw_ostream &OS; // raw_ostream to print on 00029 public: 00030 static char ID; // Pass identification, replacement for typeid 00031 explicit WriteBitcodePass(raw_ostream &o) 00032 : ModulePass(ID), OS(o) {} 00033 00034 const char *getPassName() const override { return "Bitcode Writer"; } 00035 00036 bool runOnModule(Module &M) override { 00037 WriteBitcodeToFile(&M, OS); 00038 return false; 00039 } 00040 }; 00041 } 00042 00043 char WriteBitcodePass::ID = 0; 00044 00045 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) { 00046 return new WriteBitcodePass(Str); 00047 }