2003-09-30 18:37:50 +00:00
|
|
|
//===- llvm/Assembly/PrintModulePass.h - Printing Pass ----------*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-18 20:31:42 +00:00
|
|
|
//
|
2002-04-27 06:56:12 +00:00
|
|
|
// This file defines two passes to print out a module. The PrintModulePass pass
|
|
|
|
// simply prints out the entire module when it is executed. The
|
|
|
|
// PrintFunctionPass class is designed to be pipelined with other
|
|
|
|
// FunctionPass's, and prints out the functions of the class as they are
|
|
|
|
// processed.
|
2001-10-18 20:31:42 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
|
|
|
|
#define LLVM_ASSEMBLY_PRINTMODULEPASS_H
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
2002-08-18 00:37:14 +00:00
|
|
|
#include "llvm/Module.h"
|
2001-10-18 20:31:42 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-10-18 20:31:42 +00:00
|
|
|
class PrintModulePass : public Pass {
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream *Out; // ostream to print on
|
2001-10-18 20:31:42 +00:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2002-07-23 17:58:09 +00:00
|
|
|
PrintModulePass() : Out(&std::cerr), DeleteStream(false) {}
|
|
|
|
PrintModulePass(std::ostream *o, bool DS = false)
|
2002-01-21 07:31:50 +00:00
|
|
|
: Out(o), DeleteStream(DS) {
|
2001-10-18 20:31:42 +00:00
|
|
|
}
|
2002-04-29 14:57:45 +00:00
|
|
|
|
2002-07-23 17:58:09 +00:00
|
|
|
~PrintModulePass() {
|
2001-10-18 20:31:42 +00:00
|
|
|
if (DeleteStream) delete Out;
|
|
|
|
}
|
|
|
|
|
2002-06-25 16:13:24 +00:00
|
|
|
bool run(Module &M) {
|
2002-09-19 20:49:25 +00:00
|
|
|
(*Out) << M << std::flush;
|
2001-10-18 20:31:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-04-28 21:26:51 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2002-01-21 07:31:50 +00:00
|
|
|
};
|
2001-10-18 20:31:42 +00:00
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
class PrintFunctionPass : public FunctionPass {
|
|
|
|
std::string Banner; // String to print before each function
|
2002-01-21 07:31:50 +00:00
|
|
|
std::ostream *Out; // ostream to print on
|
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2002-07-23 17:58:09 +00:00
|
|
|
PrintFunctionPass() : Banner(""), Out(&std::cerr), DeleteStream(false) {}
|
|
|
|
PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
|
|
|
|
bool DS = false)
|
2002-01-21 07:31:50 +00:00
|
|
|
: Banner(B), Out(o), DeleteStream(DS) {
|
|
|
|
}
|
2002-04-29 14:57:45 +00:00
|
|
|
|
2002-04-08 21:52:58 +00:00
|
|
|
inline ~PrintFunctionPass() {
|
2002-01-21 07:31:50 +00:00
|
|
|
if (DeleteStream) delete Out;
|
|
|
|
}
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
// runOnFunction - This pass just prints a banner followed by the function as
|
2002-01-21 07:31:50 +00:00
|
|
|
// it's processed.
|
2001-10-18 20:31:42 +00:00
|
|
|
//
|
2002-06-25 16:13:24 +00:00
|
|
|
bool runOnFunction(Function &F) {
|
|
|
|
(*Out) << Banner << (Value&)F;
|
2001-10-18 20:31:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-04-28 21:26:51 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2001-10-18 20:31:42 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-10-18 20:31:42 +00:00
|
|
|
#endif
|