BitcodeWriterPass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #include "llvm/Bitcode/ReaderWriter.h"
  14. #include "llvm/Pass.h"
  15. using namespace llvm;
  16. namespace {
  17. class WriteBitcodePass : public ModulePass {
  18. // FIXME: Kill off std::ostream
  19. std::ostream *Out;
  20. raw_ostream *RawOut; // raw_ostream to print on
  21. public:
  22. static char ID; // Pass identification, replacement for typeid
  23. explicit WriteBitcodePass(std::ostream &o)
  24. : ModulePass(&ID), Out(&o), RawOut(0) {}
  25. explicit WriteBitcodePass(raw_ostream &o)
  26. : ModulePass(&ID), Out(0), RawOut(&o) {}
  27. const char *getPassName() const { return "Bitcode Writer"; }
  28. bool runOnModule(Module &M) {
  29. if (Out) {
  30. WriteBitcodeToFile(&M, *Out);
  31. } else {
  32. WriteBitcodeToFile(&M, *RawOut);
  33. }
  34. return false;
  35. }
  36. };
  37. }
  38. char WriteBitcodePass::ID = 0;
  39. /// CreateBitcodeWriterPass - Create and return a pass that writes the module
  40. /// to the specified ostream.
  41. ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
  42. return new WriteBitcodePass(Str);
  43. }
  44. /// createBitcodeWriterPass - Create and return a pass that writes the module
  45. /// to the specified ostream.
  46. ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
  47. return new WriteBitcodePass(Str);
  48. }