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 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 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 { |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 20 | raw_ostream &OS; // raw_ostream to print on |
Chris Lattner | e8e1e4b | 2007-05-06 02:30:12 +0000 | [diff] [blame] | 21 | public: |
Daniel Dunbar | d1ce3b4 | 2008-10-22 17:39:14 +0000 | [diff] [blame] | 22 | static char ID; // Pass identification, replacement for typeid |
Daniel Dunbar | d1ce3b4 | 2008-10-22 17:39:14 +0000 | [diff] [blame] | 23 | explicit WriteBitcodePass(raw_ostream &o) |
Owen Anderson | 9ccaf53 | 2010-08-05 23:42:04 +0000 | [diff] [blame] | 24 | : ModulePass(ID), OS(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) { |
Chris Lattner | b515d75 | 2009-08-23 07:49:08 +0000 | [diff] [blame] | 29 | WriteBitcodeToFile(&M, OS); |
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 | |
Daniel Dunbar | d1ce3b4 | 2008-10-22 17:39:14 +0000 | [diff] [blame] | 37 | /// createBitcodeWriterPass - Create and return a pass that writes the module |
| 38 | /// to the specified ostream. |
| 39 | ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) { |
| 40 | return new WriteBitcodePass(Str); |
| 41 | } |