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