• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
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 "llvm/Bitcode/BitcodeWriterPass.h"
15 #include "llvm/Bitcode/ReaderWriter.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/Pass.h"
19 using namespace llvm;
20 
run(Module & M)21 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
22   WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
23   return PreservedAnalyses::all();
24 }
25 
26 namespace {
27   class WriteBitcodePass : public ModulePass {
28     raw_ostream &OS; // raw_ostream to print on
29     bool ShouldPreserveUseListOrder;
30 
31   public:
32     static char ID; // Pass identification, replacement for typeid
WriteBitcodePass(raw_ostream & o,bool ShouldPreserveUseListOrder)33     explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
34         : ModulePass(ID), OS(o),
35           ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
36 
getPassName() const37     const char *getPassName() const override { return "Bitcode Writer"; }
38 
runOnModule(Module & M)39     bool runOnModule(Module &M) override {
40       WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
41       return false;
42     }
43   };
44 }
45 
46 char WriteBitcodePass::ID = 0;
47 
createBitcodeWriterPass(raw_ostream & Str,bool ShouldPreserveUseListOrder)48 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
49                                           bool ShouldPreserveUseListOrder) {
50   return new WriteBitcodePass(Str, ShouldPreserveUseListOrder);
51 }
52