blob: 209cf0980d2d3f107b5aca6d9897c0f730806ef4 [file] [log] [blame]
Chris Lattnere8e1e4b2007-05-06 02:30:12 +00001//===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnere8e1e4b2007-05-06 02:30:12 +00007//
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 {
Daniel Dunbard1ce3b42008-10-22 17:39:14 +000020 // FIXME: Kill off std::ostream
21 std::ostream *Out;
22 raw_ostream *RawOut; // raw_ostream to print on
Chris Lattnere8e1e4b2007-05-06 02:30:12 +000023 public:
Daniel Dunbard1ce3b42008-10-22 17:39:14 +000024 static char ID; // Pass identification, replacement for typeid
Dan Gohmanadf3eab2007-11-19 15:30:20 +000025 explicit WriteBitcodePass(std::ostream &o)
Daniel Dunbard1ce3b42008-10-22 17:39:14 +000026 : ModulePass(&ID), Out(&o), RawOut(0) {}
27 explicit WriteBitcodePass(raw_ostream &o)
28 : ModulePass(&ID), Out(0), RawOut(&o) {}
Gordon Henriksenbd76d662007-11-04 20:28:31 +000029
30 const char *getPassName() const { return "Bitcode Writer"; }
Chris Lattnere8e1e4b2007-05-06 02:30:12 +000031
32 bool runOnModule(Module &M) {
Daniel Dunbard1ce3b42008-10-22 17:39:14 +000033 if (Out) {
34 WriteBitcodeToFile(&M, *Out);
35 } else {
36 WriteBitcodeToFile(&M, *RawOut);
37 }
Chris Lattnere8e1e4b2007-05-06 02:30:12 +000038 return false;
39 }
40 };
41}
42
43char WriteBitcodePass::ID = 0;
Chris Lattnere8e1e4b2007-05-06 02:30:12 +000044
45/// CreateBitcodeWriterPass - Create and return a pass that writes the module
46/// to the specified ostream.
47ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
48 return new WriteBitcodePass(Str);
49}
50
51
Daniel Dunbard1ce3b42008-10-22 17:39:14 +000052/// createBitcodeWriterPass - Create and return a pass that writes the module
53/// to the specified ostream.
54ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
55 return new WriteBitcodePass(Str);
56}