blob: 4757cacb4ca6febf8c90e100071b58b8a035890d [file] [log] [blame]
Chandler Carruthb7bdfd62014-01-13 07:38:24 +00001//===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
Chris Lattner7ef41712007-05-06 02:30:12 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner7ef41712007-05-06 02:30:12 +00007//
8//===----------------------------------------------------------------------===//
9//
10// BitcodeWriterPass implementation.
11//
12//===----------------------------------------------------------------------===//
13
Chandler Carruthb7bdfd62014-01-13 07:38:24 +000014#include "llvm/Bitcode/BitcodeWriterPass.h"
Chris Lattner7ef41712007-05-06 02:30:12 +000015#include "llvm/Bitcode/ReaderWriter.h"
Chandler Carruthb7bdfd62014-01-13 07:38:24 +000016#include "llvm/IR/Module.h"
17#include "llvm/IR/PassManager.h"
Chris Lattner7ef41712007-05-06 02:30:12 +000018#include "llvm/Pass.h"
19using namespace llvm;
20
Chandler Carruthb7bdfd62014-01-13 07:38:24 +000021PreservedAnalyses BitcodeWriterPass::run(Module *M) {
22 WriteBitcodeToFile(M, OS);
23 return PreservedAnalyses::all();
24}
25
Chris Lattner7ef41712007-05-06 02:30:12 +000026namespace {
27 class WriteBitcodePass : public ModulePass {
Chris Lattner69733952009-08-23 07:49:08 +000028 raw_ostream &OS; // raw_ostream to print on
Chris Lattner7ef41712007-05-06 02:30:12 +000029 public:
Daniel Dunbar890d0de2008-10-22 17:39:14 +000030 static char ID; // Pass identification, replacement for typeid
Daniel Dunbar890d0de2008-10-22 17:39:14 +000031 explicit WriteBitcodePass(raw_ostream &o)
Owen Andersona7aed182010-08-06 18:33:48 +000032 : ModulePass(ID), OS(o) {}
Joe Abbey2ad8df22012-11-25 15:23:39 +000033
Gordon Henriksen35f398a2007-11-04 20:28:31 +000034 const char *getPassName() const { return "Bitcode Writer"; }
Joe Abbey2ad8df22012-11-25 15:23:39 +000035
Chris Lattner7ef41712007-05-06 02:30:12 +000036 bool runOnModule(Module &M) {
Chris Lattner69733952009-08-23 07:49:08 +000037 WriteBitcodeToFile(&M, OS);
Chris Lattner7ef41712007-05-06 02:30:12 +000038 return false;
39 }
40 };
41}
42
43char WriteBitcodePass::ID = 0;
Chris Lattner7ef41712007-05-06 02:30:12 +000044
Daniel Dunbar890d0de2008-10-22 17:39:14 +000045ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
46 return new WriteBitcodePass(Str);
47}