[llvm-commits] [llvm] r111372 - /llvm/trunk/tools/opt/opt.cpp
Dan Gohman
gohman at apple.com
Wed Aug 18 10:42:59 PDT 2010
Author: djg
Date: Wed Aug 18 12:42:59 2010
New Revision: 111372
URL: http://llvm.org/viewvc/llvm-project?rev=111372&view=rev
Log:
Allow the -analyze option to follow the -o option, which defaults to
standard output, instead of just hardcoding outs().
Modified:
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=111372&r1=111371&r2=111372&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Wed Aug 18 12:42:59 2010
@@ -138,17 +138,18 @@
struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
static char ID;
const PassInfo *PassToPrint;
- CallGraphSCCPassPrinter(const PassInfo *PI) :
- CallGraphSCCPass(ID), PassToPrint(PI) {}
+ raw_ostream &Out;
+ CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out) :
+ CallGraphSCCPass(ID), PassToPrint(PI), Out(out) {}
virtual bool runOnSCC(CallGraphSCC &SCC) {
if (!Quiet) {
- outs() << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
Function *F = (*I)->getFunction();
if (F)
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(outs(),
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
F->getParent());
}
}
@@ -169,13 +170,14 @@
struct ModulePassPrinter : public ModulePass {
static char ID;
const PassInfo *PassToPrint;
- ModulePassPrinter(const PassInfo *PI) : ModulePass(ID),
- PassToPrint(PI) {}
+ raw_ostream &Out;
+ ModulePassPrinter(const PassInfo *PI, raw_ostream &out)
+ : ModulePass(ID), PassToPrint(PI), Out(out) {}
virtual bool runOnModule(Module &M) {
if (!Quiet) {
- outs() << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(outs(), &M);
+ Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
}
// Get and print pass...
@@ -193,17 +195,18 @@
char ModulePassPrinter::ID = 0;
struct FunctionPassPrinter : public FunctionPass {
const PassInfo *PassToPrint;
+ raw_ostream &Out;
static char ID;
- FunctionPassPrinter(const PassInfo *PI) : FunctionPass(ID),
- PassToPrint(PI) {}
+ FunctionPassPrinter(const PassInfo *PI, raw_ostream &out)
+ : FunctionPass(ID), PassToPrint(PI), Out(out) {}
virtual bool runOnFunction(Function &F) {
if (!Quiet) {
- outs() << "Printing analysis '" << PassToPrint->getPassName()
- << "' for function '" << F.getName() << "':\n";
+ Out << "Printing analysis '" << PassToPrint->getPassName()
+ << "' for function '" << F.getName() << "':\n";
}
// Get and print pass...
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(outs(),
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
F.getParent());
return false;
}
@@ -221,13 +224,14 @@
struct LoopPassPrinter : public LoopPass {
static char ID;
const PassInfo *PassToPrint;
- LoopPassPrinter(const PassInfo *PI) :
- LoopPass(ID), PassToPrint(PI) {}
+ raw_ostream &Out;
+ LoopPassPrinter(const PassInfo *PI, raw_ostream &out) :
+ LoopPass(ID), PassToPrint(PI), Out(out) {}
virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
if (!Quiet) {
- outs() << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(outs(),
+ Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
L->getHeader()->getParent()->getParent());
}
// Get and print pass...
@@ -246,18 +250,19 @@
struct BasicBlockPassPrinter : public BasicBlockPass {
const PassInfo *PassToPrint;
+ raw_ostream &Out;
static char ID;
- BasicBlockPassPrinter(const PassInfo *PI)
- : BasicBlockPass(ID), PassToPrint(PI) {}
+ BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out)
+ : BasicBlockPass(ID), PassToPrint(PI), Out(out) {}
virtual bool runOnBasicBlock(BasicBlock &BB) {
if (!Quiet) {
- outs() << "Printing Analysis info for BasicBlock '" << BB.getName()
- << "': Pass " << PassToPrint->getPassName() << ":\n";
+ Out << "Printing Analysis info for BasicBlock '" << BB.getName()
+ << "': Pass " << PassToPrint->getPassName() << ":\n";
}
// Get and print pass...
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(outs(),
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
BB.getParent()->getParent());
return false;
}
@@ -381,10 +386,10 @@
// Figure out what stream we are supposed to write to...
raw_ostream *Out = 0;
- if (NoOutput || AnalyzeOnly) {
+ if (NoOutput) {
if (!OutputFilename.empty())
errs() << "WARNING: The -o (output filename) option is ignored when\n"
- "the --disable-output or --analyze options are used.\n";
+ "the --disable-output option is used.\n";
} else {
// Default to standard output.
if (OutputFilename.empty())
@@ -485,19 +490,19 @@
if (AnalyzeOnly) {
switch (Kind) {
case PT_BasicBlock:
- Passes.add(new BasicBlockPassPrinter(PassInf));
+ Passes.add(new BasicBlockPassPrinter(PassInf, *Out));
break;
case PT_Loop:
- Passes.add(new LoopPassPrinter(PassInf));
+ Passes.add(new LoopPassPrinter(PassInf, *Out));
break;
case PT_Function:
- Passes.add(new FunctionPassPrinter(PassInf));
+ Passes.add(new FunctionPassPrinter(PassInf, *Out));
break;
case PT_CallGraphSCC:
- Passes.add(new CallGraphSCCPassPrinter(PassInf));
+ Passes.add(new CallGraphSCCPassPrinter(PassInf, *Out));
break;
default:
- Passes.add(new ModulePassPrinter(PassInf));
+ Passes.add(new ModulePassPrinter(PassInf, *Out));
break;
}
}
@@ -534,7 +539,7 @@
if (!NoVerify && !VerifyEach)
Passes.add(createVerifierPass());
- // Write bitcode or assembly out to disk or outs() as the last step...
+ // Write bitcode or assembly to the output as the last step...
if (!NoOutput && !AnalyzeOnly) {
if (OutputAssembly)
Passes.add(createPrintModulePass(Out));
More information about the llvm-commits
mailing list