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