For PR797:
authorReid Spencer <rspencer@reidspencer.com>
Mon, 21 Aug 2006 06:04:45 +0000 (06:04 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Mon, 21 Aug 2006 06:04:45 +0000 (06:04 +0000)
Adjust usage of the ExecuteAndWait function to use the last argument which
is the ErrMsg string. This is necessitated because this function no longer
throws exceptions on error.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29791 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/GraphWriter.cpp
tools/bugpoint/OptimizerDriver.cpp
tools/bugpoint/ToolRunner.cpp
tools/gccld/GenerateCode.cpp
tools/gccld/gccld.cpp
tools/gccld/gccld.h
tools/llvm-ld/llvm-ld.cpp
tools/llvmc/CompilerDriver.cpp
tools/llvmc/CompilerDriver.h
tools/llvmc/llvmc.cpp

index 152261fbac62f36c9c1049d9e8165ec6334daa1f..501cc6d89d3c4c6da5b596c82e4366e71a297887 100644 (file)
@@ -19,6 +19,7 @@
 using namespace llvm;
 
 void llvm::DisplayGraph(const sys::Path &Filename) {
+  std::string ErrMsg;
 #if HAVE_GRAPHVIZ
   sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
 
@@ -28,8 +29,8 @@ void llvm::DisplayGraph(const sys::Path &Filename) {
   args.push_back(0);
   
   std::cerr << "Running 'Graphviz' program... " << std::flush;
-  if (sys::Program::ExecuteAndWait(Graphviz, &args[0])) {
-    std::cerr << "Error viewing graph: 'Graphviz' not in path?\n";
+  if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,&ErrMsg)) {
+    std::cerr << "Error viewing graph: " << ErrMsg << "\n";
   }
 #elif (HAVE_GV && HAVE_DOT)
   sys::Path PSFilename = Filename;
@@ -48,8 +49,8 @@ void llvm::DisplayGraph(const sys::Path &Filename) {
   args.push_back(0);
   
   std::cerr << "Running 'dot' program... " << std::flush;
-  if (sys::Program::ExecuteAndWait(dot, &args[0])) {
-    std::cerr << "Error viewing graph: 'dot' not in path?\n";
+  if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,&ErrMsg)) {
+    std::cerr << "Error viewing graph: '" << ErrMsg << "\n";
   } else {
     std::cerr << " done. \n";
 
@@ -59,8 +60,9 @@ void llvm::DisplayGraph(const sys::Path &Filename) {
     args.push_back(PSFilename.c_str());
     args.push_back(0);
     
-    if (sys::Program::ExecuteAndWait(gv, &args[0])) {
-      std::cerr << "Error viewing graph: 'gv' not in path?\n";
+    ErrMsg.clear();
+    if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,&ErrMsg)) {
+      std::cerr << "Error viewing graph: " << ErrMsg << "\n";
     }
   }
   PSFilename.eraseFromDisk();
@@ -72,8 +74,8 @@ void llvm::DisplayGraph(const sys::Path &Filename) {
   args.push_back(0);
   
   std::cerr << "Running 'dotty' program... " << std::flush;
-  if (sys::Program::ExecuteAndWait(dotty, &args[0])) {
-    std::cerr << "Error viewing graph: 'dotty' not in path?\n";
+  if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,&ErrMsg)) {
+    std::cerr << "Error viewing graph: " << ErrMsg << "\n";
   } else {
 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns.
     return;
index 0ac514bbefede4273b541927f2f0e743dc479843..4311200cc362725b77ae4c3448ebd3313a2a3b64 100644 (file)
@@ -179,7 +179,8 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
   args[n++] = 0;
 
   sys::Path prog(sys::Program::FindProgramByName(ToolName));
-  int result = sys::Program::ExecuteAndWait(prog,args,0,0,Timeout);
+  std::string ErrMsg;
+  int result = sys::Program::ExecuteAndWait(prog,args,0,0,Timeout,&ErrMsg);
 
   // If we are supposed to delete the bytecode file or if the passes crashed,
   // remove it now.  This may fail if the file was never created, but that's ok.
@@ -194,10 +195,12 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
       std::cout << "Success!\n";
     else if (result > 0)
       std::cout << "Exited with error code '" << result << "'\n";
-    else if (result == -9999)
-      std::cout << "Program not executable\n";
-    else if (result < 0)
-      std::cout << "Crashed with signal #" << abs(result) << "\n";
+    else if (result < 0) {
+      if (result == -1)
+        std::cout << "Execute failed: " << ErrMsg << "\n";
+      else
+        std::cout << "Crashed with signal #" << abs(result) << "\n";
+    }
     if (result & 0x01000000)
       std::cout << "Dumped core\n";
   }
index 067bf658c7329557fffe3654d90d64cc70c2b800..8712baf353c7d7e247ea8fe6f056ba8f0afd89a5 100644 (file)
@@ -55,7 +55,7 @@ static void ProcessFailure(sys::Path ProgPath, const char** Args) {
   sys::Path ErrorFilename("error_messages");
   ErrorFilename.makeUnique();
   RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename,
-                        ErrorFilename); // FIXME: check return code
+                        ErrorFilename); // FIXME: check return code ?
 
   // Print out the error messages generated by GCC if possible...
   std::ifstream ErrorFile(ErrorFilename.c_str());
index 63dda12aa07c9dd15fc75383c8be7fb11dcd7e00..285f7ca84cdceceeb4dc3878ce23ec6522a96a7e 100644 (file)
@@ -297,6 +297,7 @@ int llvm::GenerateBytecode(Module *M, int StripLevel, bool Internalize,
 int llvm::GenerateAssembly(const std::string &OutputFilename,
                            const std::string &InputFilename,
                            const sys::Path &llc,
+                           std::string& ErrMsg,
                            bool Verbose) {
   // Run LLC to convert the bytecode file into assembly code.
   std::vector<const char*> args;
@@ -307,13 +308,14 @@ int llvm::GenerateAssembly(const std::string &OutputFilename,
   args.push_back(InputFilename.c_str());
   args.push_back(0);
   if (Verbose) dumpArgs(&args[0]);
-  return sys::Program::ExecuteAndWait(llc, &args[0]);
+  return sys::Program::ExecuteAndWait(llc, &args[0],0,0,0,&ErrMsg);
 }
 
 /// GenerateCFile - generates a C source file from the specified bytecode file.
 int llvm::GenerateCFile(const std::string &OutputFile,
                         const std::string &InputFile,
                         const sys::Path &llc,
+                        std::string& ErrMsg,
                         bool Verbose) {
   // Run LLC to convert the bytecode file into C.
   std::vector<const char*> args;
@@ -325,7 +327,7 @@ int llvm::GenerateCFile(const std::string &OutputFile,
   args.push_back(InputFile.c_str());
   args.push_back(0);
   if (Verbose) dumpArgs(&args[0]);
-  return sys::Program::ExecuteAndWait(llc, &args[0]);
+  return sys::Program::ExecuteAndWait(llc, &args[0],0,0,0,&ErrMsg);
 }
 
 /// GenerateNative - generates a native executable file from the specified
@@ -352,6 +354,7 @@ int llvm::GenerateNative(const std::string &OutputFilename,
                          bool ExportAllAsDynamic,
                          const std::vector<std::string> &RPaths,
                          const std::string &SOName,
+                         std::string& ErrMsg,
                          bool Verbose) {
   // Remove these environment variables from the environment of the
   // programs that we will execute.  It appears that GCC sets these
@@ -436,7 +439,8 @@ int llvm::GenerateNative(const std::string &OutputFilename,
 
   // Run the compiler to assembly and link together the program.
   if (Verbose) dumpArgs(&args[0]);
-  int Res = sys::Program::ExecuteAndWait(gcc, &args[0],(const char**)clean_env);
+  int Res = sys::Program::ExecuteAndWait(
+      gcc, &args[0],(const char**)clean_env,0,0,&ErrMsg);
 
   delete [] clean_env;
 
index 22a26ef91a70ae7e5464f94aea9b79cce8e0eb8e..a9df06d69c79607e92003ba441aa31890a4e66be 100644 (file)
@@ -320,12 +320,19 @@ int main(int argc, char **argv, char **envp ) {
 
       // Generate an assembly language file for the bytecode.
       if (Verbose) std::cout << "Generating Assembly Code\n";
-      GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput, llc,
-                       Verbose);
+      std::string ErrMsg;
+      if (0 != GenerateAssembly(
+          AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
+        std::cerr << argv[0] << ": " << ErrMsg << "\n";
+        return 2;
+      }
       if (Verbose) std::cout << "Generating Native Code\n";
-      GenerateNative(OutputFilename, AssemblyFile.toString(),
+      if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
                      LibPaths, Libraries, gcc, envp, LinkAsLibrary,
-                     NoInternalize, RPath, SOName, Verbose);
+                     NoInternalize, RPath, SOName, ErrMsg, Verbose) ) {
+        std::cerr << argv[0] << ": " << ErrMsg << "\n";
+        return 2;
+      }
 
       if (!SaveTemps) {
         // Remove the assembly language file.
@@ -353,11 +360,19 @@ int main(int argc, char **argv, char **envp ) {
 
       // Generate an assembly language file for the bytecode.
       if (Verbose) std::cout << "Generating C Source Code\n";
-      GenerateCFile(CFile.toString(), RealBytecodeOutput, llc, Verbose);
+      std::string ErrMsg;
+      if (0 != GenerateCFile(
+          CFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
+        std::cerr << argv[0] << ": " << ErrMsg << "\n";
+        return 2;
+      }
       if (Verbose) std::cout << "Generating Native Code\n";
-      GenerateNative(OutputFilename, CFile.toString(),
+      if (0 != GenerateNative(OutputFilename, CFile.toString(),
                      LibPaths, Libraries, gcc, envp, LinkAsLibrary,
-                     NoInternalize, RPath, SOName, Verbose);
+                     NoInternalize, RPath, SOName, ErrMsg, Verbose)) {
+        std::cerr << argv[0] << ": " << ErrMsg << "\n";
+        return 2;
+      }
 
       if (!SaveTemps) {
         // Remove the assembly language file.
index 8dbae884c22cfb5b1d3770e78411e849929c3329..62c058a2df5b7c63ef094fe68e53f2a3ba9439ac 100644 (file)
@@ -30,12 +30,14 @@ int
 GenerateAssembly (const std::string &OutputFilename,
                   const std::string &InputFilename,
                   const sys::Path &llc,
+                  std::string& ErrMsg,
                   bool Verbose=false);
 
 int
 GenerateCFile (const std::string &OutputFile,
                const std::string &InputFile,
                const sys::Path &llc,
+               std::string& ErrMsg,
                bool Verbose=false);
 int
 GenerateNative (const std::string &OutputFilename,
@@ -48,6 +50,7 @@ GenerateNative (const std::string &OutputFilename,
                 bool ExportAllAsDynamic,
                 const std::vector<std::string> &RPath,
                 const std::string &SOName,
+                std::string& ErrMsg,
                 bool Verbose=false);
 
 } // End llvm namespace
index 9b56bdd1f0e8c456a4a4393a533d4d627e123670..c8e505c9757bff4d327630a1334e0d6f5e0d8655 100644 (file)
@@ -227,7 +227,8 @@ void GenerateBytecode(Module* M, const std::string& FileName) {
 ///
 static int GenerateAssembly(const std::string &OutputFilename,
                             const std::string &InputFilename,
-                            const sys::Path &llc) {
+                            const sys::Path &llc,
+                            std::string &ErrMsg ) {
   // Run LLC to convert the bytecode file into assembly code.
   std::vector<const char*> args;
   args.push_back(llc.c_str());
@@ -237,13 +238,14 @@ static int GenerateAssembly(const std::string &OutputFilename,
   args.push_back(InputFilename.c_str());
   args.push_back(0);
 
-  return sys::Program::ExecuteAndWait(llc,&args[0]);
+  return sys::Program::ExecuteAndWait(llc,&args[0],0,0,0,&ErrMsg);
 }
 
 /// GenerateCFile - generates a C source file from the specified bytecode file.
 static int GenerateCFile(const std::string &OutputFile,
                          const std::string &InputFile,
-                         const sys::Path &llc) {
+                         const sys::Path &llc,
+                         std::string& ErrMsg) {
   // Run LLC to convert the bytecode file into C.
   std::vector<const char*> args;
   args.push_back(llc.c_str());
@@ -253,7 +255,7 @@ static int GenerateCFile(const std::string &OutputFile,
   args.push_back(OutputFile.c_str());
   args.push_back(InputFile.c_str());
   args.push_back(0);
-  return sys::Program::ExecuteAndWait(llc, &args[0]);
+  return sys::Program::ExecuteAndWait(llc, &args[0],0,0,0,&ErrMsg);
 }
 
 /// GenerateNative - generates a native object file from the
@@ -275,7 +277,8 @@ static int GenerateCFile(const std::string &OutputFile,
 static int GenerateNative(const std::string &OutputFilename,
                           const std::string &InputFilename,
                           const std::vector<std::string> &Libraries,
-                          const sys::Path &gcc, char ** const envp) {
+                          const sys::Path &gcc, char ** const envp,
+                          std::string& ErrMsg) {
   // Remove these environment variables from the environment of the
   // programs that we will execute.  It appears that GCC sets these
   // environment variables so that the programs it uses can configure
@@ -329,7 +332,8 @@ static int GenerateNative(const std::string &OutputFilename,
   args.push_back(0);
 
   // Run the compiler to assembly and link together the program.
-  int R = sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env);
+  int R = sys::Program::ExecuteAndWait(
+      gcc, &args[0], (const char**)clean_env,0,0,&ErrMsg);
   delete [] clean_env;
   return R;
 }
@@ -497,7 +501,8 @@ int main(int argc, char **argv, char **envp) {
           args[1] = RealBytecodeOutput.c_str();
           args[2] = tmp_output.c_str();
           args[3] = 0;
-          if (0 == sys::Program::ExecuteAndWait(prog, args)) {
+          std::string ErrMsg;
+          if (0 == sys::Program::ExecuteAndWait(prog, args, 0,0,0, &ErrMsg)) {
             if (tmp_output.isBytecodeFile()) {
               sys::Path target(RealBytecodeOutput);
               target.eraseFromDisk();
@@ -505,6 +510,9 @@ int main(int argc, char **argv, char **envp) {
             } else
               return PrintAndReturn(
                 "Post-link optimization output is not bytecode");
+          } else {
+            std::cerr << argv[0] << ": " << ErrMsg << "\n";
+            return 2;
           }
         }
       }
@@ -533,10 +541,19 @@ int main(int argc, char **argv, char **envp) {
 
         // Generate an assembly language file for the bytecode.
         if (Verbose) std::cout << "Generating Assembly Code\n";
-        GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput, llc);
+        std::string ErrMsg;
+        if (0 != GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput,
+            llc, ErrMsg)) {
+          std::cerr << argv[0] << ": " << ErrMsg << "\n";
+          return 1;
+        }
+
         if (Verbose) std::cout << "Generating Native Code\n";
-        GenerateNative(OutputFilename, AssemblyFile.toString(), Libraries,
-                       gcc, envp);
+        if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
+            Libraries,gcc,envp,ErrMsg)) {
+          std::cerr << argv[0] << ": " << ErrMsg << "\n";
+          return 1;
+        }
 
         // Remove the assembly language file.
         AssemblyFile.eraseFromDisk();
@@ -559,9 +576,19 @@ int main(int argc, char **argv, char **envp) {
 
         // Generate an assembly language file for the bytecode.
         if (Verbose) std::cout << "Generating Assembly Code\n";
-        GenerateCFile(CFile.toString(), RealBytecodeOutput, llc);
+        std::string ErrMsg;
+        if (0 != GenerateCFile(
+            CFile.toString(), RealBytecodeOutput, llc, ErrMsg)) {
+          std::cerr << argv[0] << ": " << ErrMsg << "\n";
+          return 1;
+        }
+
         if (Verbose) std::cout << "Generating Native Code\n";
-        GenerateNative(OutputFilename, CFile.toString(), Libraries, gcc, envp);
+        if (0 != GenerateNative(OutputFilename, CFile.toString(), Libraries, 
+            gcc, envp, ErrMsg)) {
+          std::cerr << argv[0] << ": " << ErrMsg << "\n";
+          return 1;
+        }
 
         // Remove the assembly language file.
         CFile.eraseFromDisk();
index 64232f3d2c1b5ddc424cb3ff8a38f895c4769bea..a204964cd84187e09dbac53a870f8030ca6b8a95 100644 (file)
@@ -451,7 +451,7 @@ private:
     return action;
   }
 
-  bool DoAction(Action*action) {
+  int DoAction(Action*action, std::string& ErrMsg) {
     assert(action != 0 && "Invalid Action!");
     if (isSet(VERBOSE_FLAG))
       WriteAction(action);
@@ -477,15 +477,17 @@ private:
       if (isSet(TIME_ACTIONS_FLAG)) {
         Timer timer(action->program.toString());
         timer.startTimer();
-        int resultCode = sys::Program::ExecuteAndWait(action->program, Args);
+        int resultCode = 
+          sys::Program::ExecuteAndWait(action->program, Args,0,0,0,&ErrMsg);
         timer.stopTimer();
         timer.print(timer,std::cerr);
-        return resultCode == 0;
+        return resultCode;
       }
       else
-        return 0 == sys::Program::ExecuteAndWait(action->program, Args);
+        return 
+          sys::Program::ExecuteAndWait(action->program, Args, 0,0,0, &ErrMsg);
     }
-    return true;
+    return 0;
   }
 
   /// This method tries various variants of a linkage item's file
@@ -594,7 +596,7 @@ private:
 /// @name Methods
 /// @{
 public:
-  virtual int execute(const InputList& InpList, const sys::Path& Output ) {
+  virtual int execute(const InputList& InpList, const sys::Path& Output, std::string& ErrMsg ) {
     try {
       // Echo the configuration of options if we're running verbose
       if (isSet(DEBUG_FLAG)) {
@@ -851,8 +853,9 @@ public:
       std::vector<Action*>::iterator AI = actions.begin();
       std::vector<Action*>::iterator AE = actions.end();
       while (AI != AE) {
-        if (!DoAction(*AI))
-          throw std::string("Action failed");
+        int ActionResult = DoAction(*AI, ErrMsg);
+        if (ActionResult != 0)
+          return ActionResult;
         AI++;
       }
 
@@ -932,8 +935,9 @@ public:
         link->args.push_back(Output.toString());
 
         // Execute the link
-        if (!DoAction(link))
-            throw std::string("Action failed");
+        int ActionResult = DoAction(link, ErrMsg);
+        if (ActionResult != 0)
+          return ActionResult;
       }
     } catch (std::string& msg) {
       cleanup();
index 41ad2c3bb46d79c7620c86626ab73357b60a75dc..02ec0e9f524390d0860eae8b655b1b8ab20a2c45 100644 (file)
@@ -150,7 +150,8 @@ namespace llvm {
     /// @{
     public:
       /// @brief Execute the actions requested for the given input list.
-      virtual int execute(const InputList& list, const sys::Path& output) = 0;
+      virtual int execute(
+        const InputList& list, const sys::Path& output, std::string& ErrMsg) =0;
 
       /// @brief Set the final phase at which compilation terminates
       virtual void setFinalPhase(Phases phase) = 0;
index 496eaa419449ff70541cb6c190e3c8eb55c0717c..f2e7c1fb37b966b87b8b45a48187f9379dec8f81 100644 (file)
@@ -355,9 +355,10 @@ int main(int argc, char **argv) {
     }
 
     // Tell the driver to do its thing
-    int result = CD->execute(InpList, sys::Path(OutputFilename));
+    std::string ErrMsg;
+    int result = CD->execute(InpList, sys::Path(OutputFilename), ErrMsg);
     if (result != 0) {
-      throw std::string("Error executing actions. Terminated.");
+      std::cerr << argv[0] << ": " << ErrMsg << '\n';
       return result;
     }