[llvm-commits] CVS: llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Reid Spencer reid at x10sys.com
Wed Dec 29 21:36:23 PST 2004



Changes in directory llvm/tools/llvm-bcanalyzer:

llvm-bcanalyzer.cpp updated: 1.4 -> 1.5
---
Log message:

For PR351: http://llvm.cs.uiuc.edu/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.


---
Diffs of the changes:  (+47 -41)

Index: llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
diff -u llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp:1.4 llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp:1.5
--- llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp:1.4	Wed Sep  1 17:55:37 2004
+++ llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp	Wed Dec 29 23:36:07 2004
@@ -49,52 +49,58 @@
 static cl::opt<bool> Verify    ("verify", cl::desc("Progressively verify module"));
 
 int 
-main(int argc, char **argv) 
-{
-  cl::ParseCommandLineOptions(argc, argv, 
-    " llvm-bcanalyzer Analysis of ByteCode Dumper\n");
-
-  sys::PrintStackTraceOnErrorSignal();
-
-  std::ostream* Out = &std::cout;  // Default to printing to stdout...
-  std::istream* In  = &std::cin;   // Default to reading stdin
-  std::string ErrorMessage;
-  BytecodeAnalysis bca;
-
-  /// Determine what to generate
-  bca.detailedResults = !NoDetails;
-  bca.progressiveVerify = Verify;
-
-  /// Analyze the bytecode file
-  Module* M = AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage, (Dump?Out:0));
-
-  // All that bcanalyzer does is write the gathered statistics to the output
-  PrintBytecodeAnalysis(bca,*Out);
-
-  if ( M && Verify ) {
-    std::string verificationMsg;
-    try {
-      verifyModule( *M, ThrowExceptionAction );
-    } catch (std::string& errmsg ) {
-      verificationMsg = errmsg;
+main(int argc, char **argv) {
+  try {
+    cl::ParseCommandLineOptions(argc, argv, 
+      " llvm-bcanalyzer Analysis of ByteCode Dumper\n");
+
+    sys::PrintStackTraceOnErrorSignal();
+
+    std::ostream* Out = &std::cout;  // Default to printing to stdout...
+    std::istream* In  = &std::cin;   // Default to reading stdin
+    std::string ErrorMessage;
+    BytecodeAnalysis bca;
+
+    /// Determine what to generate
+    bca.detailedResults = !NoDetails;
+    bca.progressiveVerify = Verify;
+
+    /// Analyze the bytecode file
+    Module* M = AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage, (Dump?Out:0));
+
+    // All that bcanalyzer does is write the gathered statistics to the output
+    PrintBytecodeAnalysis(bca,*Out);
+
+    if ( M && Verify ) {
+      std::string verificationMsg;
+      try {
+        verifyModule( *M, ThrowExceptionAction );
+      } catch (std::string& errmsg ) {
+        verificationMsg = errmsg;
+      }
+      if ( verificationMsg.length() > 0 ) 
+        std::cerr << "Final Verification Message: " << verificationMsg << "\n";
     }
-    if ( verificationMsg.length() > 0 ) 
-      std::cerr << "Final Verification Message: " << verificationMsg << "\n";
-  }
 
 
-  // If there was an error, print it and stop.
-  if ( ErrorMessage.size() ) {
-    std::cerr << argv[0] << ": " << ErrorMessage << "\n";
-    return 1;
-  }
-  
+    // If there was an error, print it and stop.
+    if ( ErrorMessage.size() ) {
+      std::cerr << argv[0] << ": " << ErrorMessage << "\n";
+      return 1;
+    }
+    
 
-  if (Out != &std::cout) {
-    ((std::ofstream*)Out)->close();
-    delete Out;
+    if (Out != &std::cout) {
+      ((std::ofstream*)Out)->close();
+      delete Out;
+    }
+    return 0;
+  } catch (const std::string& msg) {
+    std::cerr << argv[0] << ": " << msg << "\n";
+  } catch (...) {
+    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
   }
-  return 0;
+  return 1;
 }
 
 // vim: sw=2






More information about the llvm-commits mailing list