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"
|
2004-07-04 12:58:20 +02:00
|
|
|
#include <iostream>
|
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 {
|
2002-01-20 23:54:45 +01:00
|
|
|
std::ostream *Out; // ostream to print on
|
2001-10-18 22:31:42 +02:00
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2002-07-23 19:58:09 +02:00
|
|
|
PrintModulePass() : Out(&std::cerr), DeleteStream(false) {}
|
|
|
|
PrintModulePass(std::ostream *o, bool DS = false)
|
2002-01-21 08:31:50 +01:00
|
|
|
: Out(o), DeleteStream(DS) {
|
2001-10-18 22:31:42 +02:00
|
|
|
}
|
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
|
2002-01-21 08:31:50 +01:00
|
|
|
std::ostream *Out; // ostream to print on
|
|
|
|
bool DeleteStream; // Delete the ostream in our dtor?
|
|
|
|
public:
|
2002-07-23 19:58:09 +02:00
|
|
|
PrintFunctionPass() : Banner(""), Out(&std::cerr), DeleteStream(false) {}
|
|
|
|
PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
|
|
|
|
bool DS = false)
|
2002-01-21 08:31:50 +01:00
|
|
|
: 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) {
|
|
|
|
(*Out) << Banner << (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
|