blob: 74123116da81be75d28aa55f26cfcb829a1d2c41 [file] [log] [blame]
Chris Lattnere8e1e4b2007-05-06 02:30:12 +00001//===--- 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"
16using namespace llvm;
17
18namespace {
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
34char WriteBitcodePass::ID = 0;
35static RegisterPass<WriteBitcodePass> X("emitbitcode", "Bitcode Writer");
36
37/// CreateBitcodeWriterPass - Create and return a pass that writes the module
38/// to the specified ostream.
39ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
40 return new WriteBitcodePass(Str);
41}
42
43