From 09caa3751f3c53a8c8a7a81c2a60d6c8ddf5a980 Mon Sep 17 00:00:00 2001 From: Brian Gaeke Date: Fri, 30 Jan 2004 21:53:46 +0000 Subject: [PATCH] Give clients of MachineFunctionPrinter the ability to specify a banner and choose an ostream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11016 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/Passes.h | 7 +++++-- lib/CodeGen/MachineFunction.cpp | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index 409f900a137..01638691cfb 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -15,6 +15,8 @@ #ifndef LLVM_CODEGEN_PASSES_H #define LLVM_CODEGEN_PASSES_H +#include + namespace llvm { class FunctionPass; @@ -23,8 +25,9 @@ namespace llvm { /// MachineFunctionPrinter pass - This pass prints out the machine function to /// standard error, as a debugging tool. - FunctionPass *createMachineFunctionPrinterPass(); - + FunctionPass *createMachineFunctionPrinterPass(std::ostream *OS = &std::cerr, + const std::string &Banner =""); + /// PHIElimination pass - This pass eliminates machine instruction PHI nodes /// by inserting copy instructions. This destroys SSA information, but is the /// desired input for some register allocators. This pass is "required" by diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index fa77906332b..e25fe8d5885 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -34,6 +34,12 @@ static AnnotationID MF_AID( namespace { struct Printer : public MachineFunctionPass { + std::ostream *OS; + const std::string &Banner; + + Printer (std::ostream *_OS, const std::string &_Banner) : + OS (_OS), Banner (_Banner) { } + const char *getPassName() const { return "MachineFunction Printer"; } virtual void getAnalysisUsage(AnalysisUsage &AU) const { @@ -41,14 +47,19 @@ namespace { } bool runOnMachineFunction(MachineFunction &MF) { - MF.dump(); + (*OS) << Banner; + MF.print (*OS); return false; } }; } -FunctionPass *llvm::createMachineFunctionPrinterPass() { - return new Printer(); +/// Returns a newly-created MachineFunction Printer pass. The default output +/// stream is std::cerr; the default banner is empty. +/// +FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS, + const std::string &Banner) { + return new Printer(OS, Banner); } namespace {