2008-10-22 01:33:38 +02:00
|
|
|
//===--- VMCore/PrintModulePass.cpp - Module/Function Printer -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// PrintModulePass and PrintFunctionPass implementations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Assembly/PrintModulePass.h"
|
|
|
|
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Pass.h"
|
2010-01-05 02:30:18 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2008-10-22 05:25:22 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-10-22 01:33:38 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-10-25 07:33:48 +01:00
|
|
|
class PrintModulePass : public ModulePass {
|
2010-04-03 01:17:14 +02:00
|
|
|
std::string Banner;
|
2008-10-22 05:25:22 +02:00
|
|
|
raw_ostream *Out; // raw_ostream to print on
|
2008-10-22 01:33:38 +02:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
|
|
|
static char ID;
|
2010-08-06 20:33:48 +02:00
|
|
|
PrintModulePass() : ModulePass(ID), Out(&dbgs()),
|
2008-10-22 01:33:38 +02:00
|
|
|
DeleteStream(false) {}
|
2010-04-03 01:17:14 +02:00
|
|
|
PrintModulePass(const std::string &B, raw_ostream *o, bool DS)
|
2010-08-06 20:33:48 +02:00
|
|
|
: ModulePass(ID), Banner(B), Out(o), DeleteStream(DS) {}
|
2008-10-22 01:33:38 +02:00
|
|
|
|
|
|
|
~PrintModulePass() {
|
|
|
|
if (DeleteStream) delete Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnModule(Module &M) {
|
2010-04-03 01:17:14 +02:00
|
|
|
(*Out) << Banner << M;
|
2008-10-22 01:33:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PrintFunctionPass : public FunctionPass {
|
|
|
|
std::string Banner; // String to print before each function
|
2008-10-22 05:25:22 +02:00
|
|
|
raw_ostream *Out; // raw_ostream to print on
|
2008-10-22 01:33:38 +02:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
|
|
|
static char ID;
|
2010-08-06 20:33:48 +02:00
|
|
|
PrintFunctionPass() : FunctionPass(ID), Banner(""), Out(&dbgs()),
|
2008-10-22 01:33:38 +02:00
|
|
|
DeleteStream(false) {}
|
2008-10-22 05:25:22 +02:00
|
|
|
PrintFunctionPass(const std::string &B, raw_ostream *o, bool DS)
|
2010-08-06 20:33:48 +02:00
|
|
|
: FunctionPass(ID), Banner(B), Out(o), DeleteStream(DS) {}
|
2008-10-22 01:33:38 +02:00
|
|
|
|
2010-08-16 23:57:30 +02:00
|
|
|
~PrintFunctionPass() {
|
2008-10-22 01:33:38 +02:00
|
|
|
if (DeleteStream) delete Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// runOnFunction - This pass just prints a banner followed by the
|
|
|
|
// function as it's processed.
|
|
|
|
//
|
|
|
|
bool runOnFunction(Function &F) {
|
|
|
|
(*Out) << Banner << static_cast<Value&>(F);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
char PrintModulePass::ID = 0;
|
2010-07-22 00:09:45 +02:00
|
|
|
INITIALIZE_PASS(PrintModulePass, "print-module",
|
2010-10-08 00:25:06 +02:00
|
|
|
"Print module to stderr", false, false)
|
2008-10-22 01:33:38 +02:00
|
|
|
char PrintFunctionPass::ID = 0;
|
2010-07-22 00:09:45 +02:00
|
|
|
INITIALIZE_PASS(PrintFunctionPass, "print-function",
|
2010-10-08 00:25:06 +02:00
|
|
|
"Print function to stderr", false, false)
|
2008-10-22 01:33:38 +02:00
|
|
|
|
|
|
|
/// createPrintModulePass - Create and return a pass that writes the
|
2008-10-22 05:25:22 +02:00
|
|
|
/// module to the specified raw_ostream.
|
|
|
|
ModulePass *llvm::createPrintModulePass(llvm::raw_ostream *OS,
|
2010-04-03 01:17:14 +02:00
|
|
|
bool DeleteStream,
|
|
|
|
const std::string &Banner) {
|
|
|
|
return new PrintModulePass(Banner, OS, DeleteStream);
|
2008-10-22 01:33:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// createPrintFunctionPass - Create and return a pass that prints
|
2008-10-22 05:25:22 +02:00
|
|
|
/// functions to the specified raw_ostream as they are processed.
|
2008-10-22 01:33:38 +02:00
|
|
|
FunctionPass *llvm::createPrintFunctionPass(const std::string &Banner,
|
2008-10-22 05:25:22 +02:00
|
|
|
llvm::raw_ostream *OS,
|
|
|
|
bool DeleteStream) {
|
2008-10-22 01:33:38 +02:00
|
|
|
return new PrintFunctionPass(Banner, OS, DeleteStream);
|
|
|
|
}
|
|
|
|
|