Fix spelling and grammar in a comment.
[oota-llvm.git] / tools / bugpoint / OptimizerDriver.cpp
index a3ce42ec71c3b18ab948d79618441c8a0e2e942e..3ded5e866b3e025baaea3eee40a49dcd3df6ff2d 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -114,6 +114,8 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
   return 0;
 }
 
+cl::opt<bool> SilencePasses("silence-passes", cl::desc("Suppress output of running passes (both stdout and stderr)"));
+
 /// runPasses - Run the specified passes on Program, outputting a bitcode file
 /// and writing the filename into OutputFile if successful.  If the
 /// optimizations fail for some reason (optimizer crashes), return true,
@@ -124,7 +126,8 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
 ///
 bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
                           std::string &OutputFilename, bool DeleteOutput,
-                          bool Quiet) const {
+                          bool Quiet, unsigned NumExtraArgs,
+                          const char * const *ExtraArgs) const {
   // setup the output file name
   cout << std::flush;
   sys::Path uniqueFilename("bugpoint-output.bc");
@@ -156,7 +159,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
   // setup the child process' arguments
   const char** args = (const char**)
     alloca(sizeof(const char*) * 
-          (Passes.size()+13+2*PluginLoader::getNumPlugins()));
+           (Passes.size()+13+2*PluginLoader::getNumPlugins()+NumExtraArgs));
   int n = 0;
   sys::Path tool = sys::Program::FindProgramByName(ToolName);
   if (UseValgrind) {
@@ -182,6 +185,8 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
        E = pass_args.end(); I != E; ++I )
     args[n++] = I->c_str();
   args[n++] = inputFilename.c_str();
+  for (unsigned i = 0; i < NumExtraArgs; ++i)
+    args[n++] = *ExtraArgs;
   args[n++] = 0;
 
   sys::Path prog;
@@ -189,7 +194,12 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
     prog = sys::Program::FindProgramByName("valgrind");
   else
     prog = tool;
-  int result = sys::Program::ExecuteAndWait(prog, args, 0, 0,
+  
+  // Redirect stdout and stderr to nowhere if SilencePasses is given
+  sys::Path Nowhere;
+  const sys::Path *Redirects[3] = {0, &Nowhere, &Nowhere};
+
+  int result = sys::Program::ExecuteAndWait(prog, args, 0, (SilencePasses ? Redirects : 0),
                                             Timeout, MemoryLimit, &ErrMsg);
 
   // If we are supposed to delete the bitcode file or if the passes crashed,
@@ -225,10 +235,12 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
 /// failure.
 Module *BugDriver::runPassesOn(Module *M,
                                const std::vector<const PassInfo*> &Passes,
-                               bool AutoDebugCrashes) {
+                               bool AutoDebugCrashes, unsigned NumExtraArgs,
+                               const char * const *ExtraArgs) {
   Module *OldProgram = swapProgramIn(M);
   std::string BitcodeResult;
-  if (runPasses(Passes, BitcodeResult, false/*delete*/, true/*quiet*/)) {
+  if (runPasses(Passes, BitcodeResult, false/*delete*/, true/*quiet*/,
+                NumExtraArgs, ExtraArgs)) {
     if (AutoDebugCrashes) {
       cerr << " Error running this sequence of passes"
            << " on the input program!\n";