diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-12-30 05:36:08 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-12-30 05:36:08 +0000 |
commit | 1ef8bdaedbd98bee35a573b8bc87149f2182cb5e (patch) | |
tree | dc21da7903997dfbcf6061f19b35a2a522c740b9 /tools/analyze/analyze.cpp | |
parent | c18671cdcd53df08cbeff7ecf443475f61971b9d (diff) |
For PR351:
* Place a try/catch block around the entire tool to Make sure std::string
exceptions are caught and printed before exiting the tool.
* Make sure we catch unhandled exceptions at the top level so that we don't
abort with a useless message but indicate than an unhandled exception was
generated.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19192 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/analyze/analyze.cpp')
-rw-r--r-- | tools/analyze/analyze.cpp | 96 |
1 files changed, 52 insertions, 44 deletions
diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp index 5a0c9508f6..0ac70687da 100644 --- a/tools/analyze/analyze.cpp +++ b/tools/analyze/analyze.cpp @@ -116,58 +116,66 @@ namespace { } int main(int argc, char **argv) { - cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n"); - sys::PrintStackTraceOnErrorSignal(); - - Module *CurMod = 0; try { + cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n"); + sys::PrintStackTraceOnErrorSignal(); + + Module *CurMod = 0; + try { #if 0 - TimeRegion RegionTimer(BytecodeLoadTimer); + TimeRegion RegionTimer(BytecodeLoadTimer); #endif - CurMod = ParseBytecodeFile(InputFilename); - if (!CurMod && !(CurMod = ParseAssemblyFile(InputFilename))){ - std::cerr << argv[0] << ": input file didn't read correctly.\n"; + CurMod = ParseBytecodeFile(InputFilename); + if (!CurMod && !(CurMod = ParseAssemblyFile(InputFilename))){ + std::cerr << argv[0] << ": input file didn't read correctly.\n"; + return 1; + } + } catch (const ParseException &E) { + std::cerr << argv[0] << ": " << E.getMessage() << "\n"; return 1; } - } catch (const ParseException &E) { - std::cerr << argv[0] << ": " << E.getMessage() << "\n"; - return 1; - } - // Create a PassManager to hold and optimize the collection of passes we are - // about to build... - // - PassManager Passes; + // Create a PassManager to hold and optimize the collection of passes we are + // about to build... + // + PassManager Passes; + + // Add an appropriate TargetData instance for this module... + Passes.add(new TargetData("analyze", CurMod)); + + // Make sure the input LLVM is well formed. + if (!NoVerify) + Passes.add(createVerifierPass()); + + // Create a new optimization pass for each one specified on the command line + for (unsigned i = 0; i < AnalysesList.size(); ++i) { + const PassInfo *Analysis = AnalysesList[i]; + + if (Analysis->getNormalCtor()) { + Pass *P = Analysis->getNormalCtor()(); + Passes.add(P); + + if (BasicBlockPass *BBP = dynamic_cast<BasicBlockPass*>(P)) + Passes.add(new BasicBlockPassPrinter(Analysis)); + else if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) + Passes.add(new FunctionPassPrinter(Analysis)); + else + Passes.add(new ModulePassPrinter(Analysis)); + + } else + std::cerr << argv[0] << ": cannot create pass: " + << Analysis->getPassName() << "\n"; + } - // Add an appropriate TargetData instance for this module... - Passes.add(new TargetData("analyze", CurMod)); + Passes.run(*CurMod); - // Make sure the input LLVM is well formed. - if (!NoVerify) - Passes.add(createVerifierPass()); + delete CurMod; + return 0; - // Create a new optimization pass for each one specified on the command line - for (unsigned i = 0; i < AnalysesList.size(); ++i) { - const PassInfo *Analysis = AnalysesList[i]; - - if (Analysis->getNormalCtor()) { - Pass *P = Analysis->getNormalCtor()(); - Passes.add(P); - - if (BasicBlockPass *BBP = dynamic_cast<BasicBlockPass*>(P)) - Passes.add(new BasicBlockPassPrinter(Analysis)); - else if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) - Passes.add(new FunctionPassPrinter(Analysis)); - else - Passes.add(new ModulePassPrinter(Analysis)); - - } else - std::cerr << argv[0] << ": cannot create pass: " - << Analysis->getPassName() << "\n"; + } catch (const std::string& msg) { + std::cerr << argv[0] << ": " << msg << "\n"; + } catch (...) { + std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } - - Passes.run(*CurMod); - - delete CurMod; - return 0; + return 1; } |