Merge error at my side. Fixed.
[oota-llvm.git] / tools / bugpoint / bugpoint.cpp
1 //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This program is an automated compiler debugger tool.  It is used to narrow
11 // down miscompilations and crash problems to a specific pass in the compiler,
12 // and the specific Module or Function input that is causing the problem.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "BugDriver.h"
17 #include "ToolRunner.h"
18 #include "llvm/LinkAllPasses.h"
19 #include "llvm/Support/PassNameParser.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/ManagedStatic.h"
22 #include "llvm/Support/PluginLoader.h"
23 #include "llvm/System/Process.h"
24 #include "llvm/System/Signals.h"
25 #include "llvm/LinkAllVMCore.h"
26 #include <iostream>
27 using namespace llvm;
28
29 // AsChild - Specifies that this invocation of bugpoint is being generated
30 // from a parent process. It is not intended to be used by users so the 
31 // option is hidden.
32 static cl::opt<bool> 
33 AsChild("as-child", cl::desc("Run bugpoint as child process"), 
34         cl::ReallyHidden);
35           
36 static cl::opt<bool> 
37 FindBugs("find-bugs", cl::desc("Run many different optimization sequences"
38                                "on program to find bugs"), cl::init(false));
39
40 static cl::list<std::string>
41 InputFilenames(cl::Positional, cl::OneOrMore,
42                cl::desc("<input llvm ll/bc files>"));
43
44 static cl::opt<unsigned>
45 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
46              cl::desc("Number of seconds program is allowed to run before it "
47                       "is killed (default is 300s), 0 disables timeout"));
48
49 // The AnalysesList is automatically populated with registered Passes by the
50 // PassNameParser.
51 //
52 static cl::list<const PassInfo*, bool, PassNameParser>
53 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
54
55 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
56 bool llvm::BugpointIsInterrupted = false;
57
58 static void BugpointInterruptFunction() {
59   BugpointIsInterrupted = true;
60 }
61
62 int main(int argc, char **argv) {
63   llvm_shutdown_obj X;  // Call llvm_shutdown() on exit.
64   cl::ParseCommandLineOptions(argc, argv,
65                               " LLVM automatic testcase reducer. See\nhttp://"
66                               "llvm.org/docs/CommandGuide/bugpoint.html"
67                               " for more information.\n");
68   sys::PrintStackTraceOnErrorSignal();
69   sys::SetInterruptFunction(BugpointInterruptFunction);
70   
71   BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue);
72   if (D.addSources(InputFilenames)) return 1;
73   D.addPasses(PassList.begin(), PassList.end());
74
75   // Bugpoint has the ability of generating a plethora of core files, so to
76   // avoid filling up the disk, we prevent it
77   sys::Process::PreventCoreFiles();
78
79   try {
80     return D.run();
81   } catch (ToolExecutionError &TEE) {
82     std::cerr << "Tool execution error: " << TEE.what() << '\n';
83   } catch (const std::string& msg) {
84     std::cerr << argv[0] << ": " << msg << "\n";
85   } catch (...) {
86     std::cerr << "Whoops, an exception leaked out of bugpoint.  "
87               << "This is a bug in bugpoint!\n";
88   }
89   return 1;
90 }