Stephen Hines | d711dec | 2013-01-08 16:23:30 -0800 | [diff] [blame] | 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. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ReaderWriter_3_2.h" |
Stephen Hines | 99d4290 | 2013-12-16 17:45:42 -0800 | [diff] [blame] | 15 | #include "llvm/IR/Function.h" |
| 16 | #include "llvm/IR/Instructions.h" |
| 17 | #include "llvm/IR/Module.h" |
Stephen Hines | d711dec | 2013-01-08 16:23:30 -0800 | [diff] [blame] | 18 | #include "llvm/Pass.h" |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | class WriteBitcodePass : public ModulePass { |
| 23 | raw_ostream &OS; // raw_ostream to print on |
Stephen Hines | 99d4290 | 2013-12-16 17:45:42 -0800 | [diff] [blame] | 24 | |
Stephen Hines | d711dec | 2013-01-08 16:23:30 -0800 | [diff] [blame] | 25 | public: |
| 26 | static char ID; // Pass identification, replacement for typeid |
| 27 | explicit WriteBitcodePass(raw_ostream &o) |
| 28 | : ModulePass(ID), OS(o) {} |
| 29 | |
| 30 | const char *getPassName() const { return "Bitcode Writer"; } |
| 31 | |
| 32 | bool runOnModule(Module &M) { |
Stephen Hines | 99d4290 | 2013-12-16 17:45:42 -0800 | [diff] [blame] | 33 | bool Changed = false; |
Stephen Hines | d711dec | 2013-01-08 16:23:30 -0800 | [diff] [blame] | 34 | llvm_3_2::WriteBitcodeToFile(&M, OS); |
Stephen Hines | 99d4290 | 2013-12-16 17:45:42 -0800 | [diff] [blame] | 35 | return Changed; |
Stephen Hines | d711dec | 2013-01-08 16:23:30 -0800 | [diff] [blame] | 36 | } |
| 37 | }; |
| 38 | } |
| 39 | |
| 40 | char WriteBitcodePass::ID = 0; |
| 41 | |
Stephen Hines | d711dec | 2013-01-08 16:23:30 -0800 | [diff] [blame] | 42 | /// createBitcodeWriterPass - Create and return a pass that writes the module |
| 43 | /// to the specified ostream. |
| 44 | ModulePass *llvm_3_2::createBitcodeWriterPass(raw_ostream &Str) { |
| 45 | return new WriteBitcodePass(Str); |
| 46 | } |