Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 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 { |
Gordon Henriksen | bd76d66 | 2007-11-04 20:28:31 +0000 | [diff] [blame] | 20 | std::ostream &Out; // ostream to print on |
Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 21 | public: |
| 22 | static char ID; // Pass identifcation, replacement for typeid |
Dan Gohman | adf3eab | 2007-11-19 15:30:20 +0000 | [diff] [blame^] | 23 | explicit WriteBitcodePass(std::ostream &o) |
| 24 | : ModulePass((intptr_t) &ID), Out(o) {} |
Gordon Henriksen | bd76d66 | 2007-11-04 20:28:31 +0000 | [diff] [blame] | 25 | |
| 26 | const char *getPassName() const { return "Bitcode Writer"; } |
Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 27 | |
| 28 | bool runOnModule(Module &M) { |
Gordon Henriksen | bd76d66 | 2007-11-04 20:28:31 +0000 | [diff] [blame] | 29 | WriteBitcodeToFile(&M, Out); |
Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 30 | return false; |
| 31 | } |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | char WriteBitcodePass::ID = 0; |
Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 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 | |