add a new CreateBitcodeWriterPass method, which creates a bitcode writer as
[oota-llvm.git] / lib / Bitcode / Writer / BitcodeWriterPass.cpp
1 //===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source 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     std::ostream *Out;                 // ostream to print on
21   public:
22     static char ID; // Pass identifcation, replacement for typeid
23     WriteBitcodePass() : ModulePass((intptr_t) &ID), Out(0) { } 
24     WriteBitcodePass(std::ostream &o) : ModulePass((intptr_t) &ID), Out(&o) {}
25     
26     bool runOnModule(Module &M) {
27       if (Out)
28         WriteBitcodeToFile(&M, *Out);
29       return false;
30     }
31   };
32 }
33
34 char WriteBitcodePass::ID = 0;
35 static RegisterPass<WriteBitcodePass> X("emitbitcode", "Bitcode Writer");
36
37 /// CreateBitcodeWriterPass - Create and return a pass that writes the module
38 /// to the specified ostream.
39 ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
40   return new WriteBitcodePass(Str);
41 }
42
43