Chris Lattner | ebec803 | 2003-10-20 17:57:13 +0000 | [diff] [blame] | 1 | //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===// |
John Criswell | 09344dc | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 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" |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 17 | #include "llvm/Support/PassNameParser.h" |
Misha Brukman | 0c2305b | 2003-08-07 21:19:30 +0000 | [diff] [blame] | 18 | #include "Support/CommandLine.h" |
Misha Brukman | 46e18d4 | 2003-09-12 20:42:57 +0000 | [diff] [blame] | 19 | #include "Config/unistd.h" |
| 20 | #include <sys/resource.h> |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 23 | static cl::list<std::string> |
| 24 | InputFilenames(cl::Positional, cl::OneOrMore, |
| 25 | cl::desc("<input llvm ll/bc files>")); |
| 26 | |
| 27 | // The AnalysesList is automatically populated with registered Passes by the |
| 28 | // PassNameParser. |
| 29 | // |
| 30 | static cl::list<const PassInfo*, bool, PassNameParser> |
Misha Brukman | d792c9b | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 31 | PassList(cl::desc("Passes available:"), cl::ZeroOrMore); |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 33 | int main(int argc, char **argv) { |
Chris Lattner | 849619e | 2003-10-18 21:55:35 +0000 | [diff] [blame] | 34 | cl::ParseCommandLineOptions(argc, argv, |
| 35 | " LLVM automatic testcase reducer. See\nhttp://" |
| 36 | "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html" |
| 37 | " for more information.\n"); |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 39 | BugDriver D(argv[0]); |
| 40 | if (D.addSources(InputFilenames)) return 1; |
| 41 | D.addPasses(PassList.begin(), PassList.end()); |
| 42 | |
Misha Brukman | 46e18d4 | 2003-09-12 20:42:57 +0000 | [diff] [blame] | 43 | // Bugpoint has the ability of generating a plethora of core files, so to |
| 44 | // avoid filling up the disk, set the max core file size to 0. |
| 45 | struct rlimit rlim; |
| 46 | rlim.rlim_cur = rlim.rlim_max = 0; |
| 47 | int res = setrlimit(RLIMIT_CORE, &rlim); |
| 48 | if (res < 0) { |
| 49 | // setrlimit() may have failed, but we're not going to let that stop us |
| 50 | perror("setrlimit: RLIMIT_CORE"); |
| 51 | } |
| 52 | |
Chris Lattner | eb89dba | 2004-02-18 17:32:54 +0000 | [diff] [blame^] | 53 | try { |
| 54 | return D.run(); |
| 55 | } catch (...) { |
| 56 | std::cerr << "Whoops, an exception leaked out of bugpoint. " |
| 57 | << "This is a bug in bugpoint!\n"; |
| 58 | return 1; |
| 59 | } |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 60 | } |