summaryrefslogtreecommitdiff
path: root/include/llvm/Bytecode/WriteBytecodePass.h
blob: 5c21ccded5de2d97eddb27fcaca9c1ccae071001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===- llvm/Bytecode/WriteBytecodePass.h - Bytecode Writer Pass -*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines a simple pass to write the working module to a file after
// pass processing is completed.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_BYTECODE_WRITEBYTECODEPASS_H
#define LLVM_BYTECODE_WRITEBYTECODEPASS_H

#include "llvm/Pass.h"
#include "llvm/Bytecode/Writer.h"
#include "llvm/Support/Streams.h"

namespace llvm {

class WriteBytecodePass : public ModulePass {
  OStream *Out;                 // ostream to print on
  bool DeleteStream;
  bool CompressFile;
public:
  static const int ID; // Pass identifcation, replacement for typeid
  WriteBytecodePass()
    : ModulePass((intptr_t) &ID), Out(&cout), DeleteStream(false), 
      CompressFile(false) {}
  WriteBytecodePass(OStream *o, bool DS = false, bool CF = false)
    : ModulePass((intptr_t) &ID), Out(o), DeleteStream(DS), CompressFile(CF) {}

  inline ~WriteBytecodePass() {
    if (DeleteStream) delete Out;
  }

  bool runOnModule(Module &M) {
    WriteBytecodeToFile(&M, *Out, CompressFile);
    return false;
  }
};

} // End llvm namespace

#endif