2003-09-30 18:37:50 +00:00
|
|
|
//===- llvm/Assembly/PrintModulePass.h - Printing Pass ----------*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
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.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
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
|
2007-10-26 03:03:51 +00:00
|
|
|
// FunctionPass's, and prints out the functions of the module as they are
|
2002-04-27 06:56:12 +00:00
|
|
|
// 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"
|
2006-11-28 23:31:42 +00:00
|
|
|
#include "llvm/Support/Streams.h"
|
2001-10-18 20:31:42 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-09-20 04:48:05 +00:00
|
|
|
class PrintModulePass : public ModulePass {
|
2006-12-07 01:30:32 +00:00
|
|
|
OStream *Out; // ostream to print on
|
2001-10-18 20:31:42 +00:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2007-08-12 08:12:35 +00:00
|
|
|
PrintModulePass() : ModulePass(intptr_t(&ID)), Out(&cerr),
|
|
|
|
DeleteStream(false) {}
|
2006-12-07 01:30:32 +00:00
|
|
|
PrintModulePass(OStream *o, bool DS = false)
|
2007-08-12 08:12:35 +00:00
|
|
|
: ModulePass(intptr_t(&ID)), Out(o), DeleteStream(DS) {}
|
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;
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-09-20 04:48:05 +00:00
|
|
|
bool runOnModule(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
|
2006-12-07 01:30:32 +00:00
|
|
|
OStream *Out; // ostream to print on
|
2002-01-21 07:31:50 +00:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2007-08-12 08:12:35 +00:00
|
|
|
PrintFunctionPass() : FunctionPass(intptr_t(&ID)), Banner(""), Out(&cerr),
|
2007-05-01 21:15:47 +00:00
|
|
|
DeleteStream(false) {}
|
2006-12-07 01:30:32 +00:00
|
|
|
PrintFunctionPass(const std::string &B, OStream *o = &cout,
|
2002-07-23 17:58:09 +00:00
|
|
|
bool DS = false)
|
2007-08-12 08:12:35 +00:00
|
|
|
: FunctionPass(intptr_t(&ID)), 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;
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
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) {
|
2006-05-29 02:32:43 +00:00
|
|
|
(*Out) << Banner << static_cast<Value&>(F);
|
2001-10-18 20:31:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
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
|