63036d20fc1b9001d4f97adc6c491bda32a0bf4f
[oota-llvm.git] / WriteBytecodePass.h
1 //===- llvm/Bytecode/WriteBytecodePass.h - Bytecode Writer Pass -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a simple pass to write the working module to a file after
11 // pass processing is completed.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_BYTECODE_WRITEBYTECODEPASS_H
16 #define LLVM_BYTECODE_WRITEBYTECODEPASS_H
17
18 #include "llvm/Pass.h"
19 #include "llvm/Bytecode/Writer.h"
20 #include "llvm/Support/Streams.h"
21
22 namespace llvm {
23
24 class WriteBytecodePass : public ModulePass {
25   OStream *Out;                 // ostream to print on
26   bool DeleteStream;
27   bool CompressFile;
28 public:
29   static char ID; // Pass identifcation, replacement for typeid
30   WriteBytecodePass()
31     : ModulePass((intptr_t) &ID), Out(&cout), DeleteStream(false), 
32       CompressFile(false) {}
33   WriteBytecodePass(OStream *o, bool DS = false, bool CF = false)
34     : ModulePass((intptr_t) &ID), Out(o), DeleteStream(DS), CompressFile(CF) {}
35
36   inline ~WriteBytecodePass() {
37     if (DeleteStream) delete Out;
38   }
39
40   bool runOnModule(Module &M) {
41     WriteBytecodeToFile(&M, *Out, CompressFile);
42     return false;
43   }
44 };
45
46 } // End llvm namespace
47
48 #endif