llvm.org GIT mirror llvm / e8e1e4b
add a new CreateBitcodeWriterPass method, which creates a bitcode writer as a pass git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36828 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
2 changed file(s) with 48 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2020 class Module;
2121 class ModuleProvider;
2222 class MemoryBuffer;
23 class ModulePass;
2324
2425 /// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
2526 /// and prepare for lazy deserialization of function bodies. If successful,
3738 /// WriteBitcodeToFile - Write the specified module to the specified output
3839 /// stream.
3940 void WriteBitcodeToFile(const Module *M, std::ostream &Out);
41
42 /// CreateBitcodeWriterPass - Create and return a pass that writes the module
43 /// to the specified ostream.
44 ModulePass *CreateBitcodeWriterPass(std::ostream &Str);
4045 } // End llvm namespace
4146
4247 #endif
0 //===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Chris Lattner and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // BitcodeWriterPass implementation.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Bitcode/ReaderWriter.h"
14 #include "llvm/Pass.h"
15 using namespace llvm;
16
17 namespace {
18 class WriteBitcodePass : public ModulePass {
19 std::ostream *Out; // ostream to print on
20 public:
21 static char ID; // Pass identifcation, replacement for typeid
22 WriteBitcodePass() : ModulePass((intptr_t) &ID), Out(0) { }
23 WriteBitcodePass(std::ostream &o) : ModulePass((intptr_t) &ID), Out(&o) {}
24
25 bool runOnModule(Module &M) {
26 if (Out)
27 WriteBitcodeToFile(&M, *Out);
28 return false;
29 }
30 };
31 }
32
33 char WriteBitcodePass::ID = 0;
34 static RegisterPass X("emitbitcode", "Bitcode Writer");
35
36 /// CreateBitcodeWriterPass - Create and return a pass that writes the module
37 /// to the specified ostream.
38 ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
39 return new WriteBitcodePass(Str);
40 }
41
42