summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-18 17:42:59 +0000
committerDan Gohman <gohman@apple.com>2010-08-18 17:42:59 +0000
commit4931b312c06d89b14d54fdd6c3cdd374d76af7b8 (patch)
tree50246beacce33cbccd02d62bfb94845a31a8cb8d /tools
parent86cbc1bb11c1de74afcd96a421f74429faca4c2f (diff)
downloadllvm-4931b312c06d89b14d54fdd6c3cdd374d76af7b8.tar.gz
llvm-4931b312c06d89b14d54fdd6c3cdd374d76af7b8.tar.bz2
llvm-4931b312c06d89b14d54fdd6c3cdd374d76af7b8.tar.xz
Allow the -analyze option to follow the -o option, which defaults to
standard output, instead of just hardcoding outs(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/opt/opt.cpp65
1 files changed, 35 insertions, 30 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 8783061dd4..b8700685ca 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -138,17 +138,18 @@ namespace {
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 @@ char CallGraphSCCPassPrinter::ID = 0;
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 @@ struct ModulePassPrinter : public ModulePass {
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 @@ char FunctionPassPrinter::ID = 0;
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 @@ char LoopPassPrinter::ID = 0;
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 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
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 @@ int main(int argc, char **argv) {
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));