When the user hits ctrl-c, bugpoint should attempt to stop reduction as
[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 "llvm/Support/PassNameParser.h"
18 #include "llvm/Support/ToolRunner.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/PluginLoader.h"
21 #include "llvm/System/Process.h"
22 #include "llvm/System/Signals.h"
23 using namespace llvm;
24
25 static cl::list<std::string>
26 InputFilenames(cl::Positional, cl::OneOrMore,
27                cl::desc("<input llvm ll/bc files>"));
28
29 // The AnalysesList is automatically populated with registered Passes by the
30 // PassNameParser.
31 //
32 static cl::list<const PassInfo*, bool, PassNameParser>
33 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
34
35 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
36 bool llvm::BugpointIsInterrupted = false;
37
38 static void BugpointInterruptFunction() {
39   BugpointIsInterrupted = true;
40 }
41
42 int main(int argc, char **argv) {
43   cl::ParseCommandLineOptions(argc, argv,
44                               " LLVM automatic testcase reducer. See\nhttp://"
45                               "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
46                               " for more information.\n");
47   sys::PrintStackTraceOnErrorSignal();
48   sys::SetInterruptFunction(BugpointInterruptFunction);
49   
50   BugDriver D(argv[0]);
51   if (D.addSources(InputFilenames)) return 1;
52   D.addPasses(PassList.begin(), PassList.end());
53
54   // Bugpoint has the ability of generating a plethora of core files, so to
55   // avoid filling up the disk, we prevent it
56   sys::Process::PreventCoreFiles();
57
58   try {
59     return D.run();
60   } catch (ToolExecutionError &TEE) {
61     std::cerr << "Tool execution error: " << TEE.what() << '\n';
62   } catch (const std::string& msg) {
63     std::cerr << argv[0] << ": " << msg << "\n";
64   } catch (...) {
65     std::cerr << "Whoops, an exception leaked out of bugpoint.  "
66               << "This is a bug in bugpoint!\n";
67   }
68   return 1;
69 }