2003-09-30 20:37:50 +02:00
|
|
|
//===- llvm/Assembly/PrintModulePass.h - Printing Pass ----------*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02: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 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-18 22:31:42 +02:00
|
|
|
//
|
2002-04-27 08:56:12 +02: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 22:31:42 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
|
|
|
|
#define LLVM_ASSEMBLY_PRINTMODULEPASS_H
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
2002-08-18 02:37:14 +02:00
|
|
|
#include "llvm/Module.h"
|
2006-11-29 00:31:42 +01:00
|
|
|
#include "llvm/Support/Streams.h"
|
2001-10-18 22:31:42 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-09-20 06:48:05 +02:00
|
|
|
class PrintModulePass : public ModulePass {
|
2006-12-07 02:30:32 +01:00
|
|
|
OStream *Out; // ostream to print on
|
2001-10-18 22:31:42 +02:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2007-05-02 23:39:20 +02:00
|
|
|
static const char ID;
|
2007-05-01 23:15:47 +02:00
|
|
|
PrintModulePass() : ModulePass((intptr_t)&ID), Out(&cerr), DeleteStream(false) {}
|
2006-12-07 02:30:32 +01:00
|
|
|
PrintModulePass(OStream *o, bool DS = false)
|
2007-05-01 23:15:47 +02:00
|
|
|
: ModulePass((intptr_t)&ID), Out(o), DeleteStream(DS) {}
|
2002-04-29 16:57:45 +02:00
|
|
|
|
2002-07-23 19:58:09 +02:00
|
|
|
~PrintModulePass() {
|
2001-10-18 22:31:42 +02:00
|
|
|
if (DeleteStream) delete Out;
|
|
|
|
}
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2004-09-20 06:48:05 +02:00
|
|
|
bool runOnModule(Module &M) {
|
2002-09-19 22:49:25 +02:00
|
|
|
(*Out) << M << std::flush;
|
2001-10-18 22:31:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2002-04-28 23:26:51 +02:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2002-01-21 08:31:50 +01:00
|
|
|
};
|
2001-10-18 22:31:42 +02:00
|
|
|
|
2002-04-27 08:56:12 +02:00
|
|
|
class PrintFunctionPass : public FunctionPass {
|
|
|
|
std::string Banner; // String to print before each function
|
2006-12-07 02:30:32 +01:00
|
|
|
OStream *Out; // ostream to print on
|
2002-01-21 08:31:50 +01:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2007-05-02 23:39:20 +02:00
|
|
|
static const char ID;
|
2007-05-01 23:15:47 +02:00
|
|
|
PrintFunctionPass() : FunctionPass((intptr_t)&ID), Banner(""), Out(&cerr),
|
|
|
|
DeleteStream(false) {}
|
2006-12-07 02:30:32 +01:00
|
|
|
PrintFunctionPass(const std::string &B, OStream *o = &cout,
|
2002-07-23 19:58:09 +02:00
|
|
|
bool DS = false)
|
2007-05-01 23:15:47 +02:00
|
|
|
: FunctionPass((intptr_t)&ID), Banner(B), Out(o), DeleteStream(DS) {}
|
2002-04-29 16:57:45 +02:00
|
|
|
|
2002-04-08 23:52:58 +02:00
|
|
|
inline ~PrintFunctionPass() {
|
2002-01-21 08:31:50 +01:00
|
|
|
if (DeleteStream) delete Out;
|
|
|
|
}
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2002-04-27 08:56:12 +02:00
|
|
|
// runOnFunction - This pass just prints a banner followed by the function as
|
2002-01-21 08:31:50 +01:00
|
|
|
// it's processed.
|
2001-10-18 22:31:42 +02:00
|
|
|
//
|
2002-06-25 18:13:24 +02:00
|
|
|
bool runOnFunction(Function &F) {
|
2006-05-29 04:32:43 +02:00
|
|
|
(*Out) << Banner << static_cast<Value&>(F);
|
2001-10-18 22:31:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2002-04-28 23:26:51 +02:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2001-10-18 22:31:42 +02:00
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-10-18 22:31:42 +02:00
|
|
|
#endif
|