1 //===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // BitcodeWriterPass implementation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Bitcode/ReaderWriter.h"
15 #include "llvm/Pass.h"
19 class WriteBitcodePass : public ModulePass {
20 // FIXME: Kill off std::ostream
22 raw_ostream *RawOut; // raw_ostream to print on
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) {}
30 const char *getPassName() const { return "Bitcode Writer"; }
32 bool runOnModule(Module &M) {
34 WriteBitcodeToFile(&M, *Out);
36 WriteBitcodeToFile(&M, *RawOut);
43 char WriteBitcodePass::ID = 0;
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);
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);