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, EmitFunctionSummary);
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 bool EmitFunctionSummary;
31
32 public:
33 static char ID; // Pass identification, replacement for typeid
WriteBitcodePass(raw_ostream & o,bool ShouldPreserveUseListOrder,bool EmitFunctionSummary)34 explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder,
35 bool EmitFunctionSummary)
36 : ModulePass(ID), OS(o),
37 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
38 EmitFunctionSummary(EmitFunctionSummary) {}
39
getPassName() const40 const char *getPassName() const override { return "Bitcode Writer"; }
41
runOnModule(Module & M)42 bool runOnModule(Module &M) override {
43 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder,
44 EmitFunctionSummary);
45 return false;
46 }
47 };
48 }
49
50 char WriteBitcodePass::ID = 0;
51
createBitcodeWriterPass(raw_ostream & Str,bool ShouldPreserveUseListOrder,bool EmitFunctionSummary)52 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
53 bool ShouldPreserveUseListOrder,
54 bool EmitFunctionSummary) {
55 return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
56 EmitFunctionSummary);
57 }
58