Merge branch 'master' into msp430
[llvm/msp430.git] / lib / Bitcode / Writer / BitcodeWriterPass.cpp
blob209cf0980d2d3f107b5aca6d9897c0f730806ef4
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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Bitcode/ReaderWriter.h"
15 #include "llvm/Pass.h"
16 using namespace llvm;
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) {}
30 const char *getPassName() const { return "Bitcode Writer"; }
32 bool runOnModule(Module &M) {
33 if (Out) {
34 WriteBitcodeToFile(&M, *Out);
35 } else {
36 WriteBitcodeToFile(&M, *RawOut);
38 return false;
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);