LLVM API Documentation

BitcodeWriterPass.cpp

Go to the documentation of this file.
00001 //===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // BitcodeWriterPass implementation.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Bitcode/ReaderWriter.h"
00015 #include "llvm/Pass.h"
00016 using namespace llvm;
00017 
00018 namespace {
00019   class WriteBitcodePass : public ModulePass {
00020     // FIXME: Kill off std::ostream
00021     std::ostream *Out;
00022     raw_ostream *RawOut; // raw_ostream to print on
00023   public:
00024     static char ID; // Pass identification, replacement for typeid
00025     explicit WriteBitcodePass(std::ostream &o)
00026       : ModulePass(&ID), Out(&o), RawOut(0) {}
00027     explicit WriteBitcodePass(raw_ostream &o)
00028       : ModulePass(&ID), Out(0), RawOut(&o) {}
00029     
00030     const char *getPassName() const { return "Bitcode Writer"; }
00031     
00032     bool runOnModule(Module &M) {
00033       if (Out) {
00034         WriteBitcodeToFile(&M, *Out);
00035       } else {
00036         WriteBitcodeToFile(&M, *RawOut);
00037       }
00038       return false;
00039     }
00040   };
00041 }
00042 
00043 char WriteBitcodePass::ID = 0;
00044 
00045 /// CreateBitcodeWriterPass - Create and return a pass that writes the module
00046 /// to the specified ostream.
00047 ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
00048   return new WriteBitcodePass(Str);
00049 }
00050 
00051 
00052 /// createBitcodeWriterPass - Create and return a pass that writes the module
00053 /// to the specified ostream.
00054 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
00055   return new WriteBitcodePass(Str);
00056 }