blob: 3c89dce525a36ff6b0a74e55d7b39d1bd454ca9d [file] [log] [blame]
Chris Lattner94321112003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
John Criswell7c0e0222003-10-20 17:47:21 +00002//
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 Lattnerafade922002-11-20 22:28:10 +00009//
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 Lattnerafade922002-11-20 22:28:10 +000017#include "llvm/Support/PassNameParser.h"
Chris Lattner230fef82004-02-18 20:22:11 +000018#include "llvm/Support/ToolRunner.h"
Misha Brukmane49603d2003-08-07 21:19:30 +000019#include "Support/CommandLine.h"
Misha Brukman67b36e42003-09-12 20:42:57 +000020#include "Config/unistd.h"
21#include <sys/resource.h>
Brian Gaeked0fde302003-11-11 22:41:34 +000022using namespace llvm;
23
Chris Lattnerafade922002-11-20 22:28:10 +000024static cl::list<std::string>
25InputFilenames(cl::Positional, cl::OneOrMore,
26 cl::desc("<input llvm ll/bc files>"));
27
28// The AnalysesList is automatically populated with registered Passes by the
29// PassNameParser.
30//
31static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukman50733362003-07-24 18:17:43 +000032PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattnerafade922002-11-20 22:28:10 +000033
Chris Lattnerafade922002-11-20 22:28:10 +000034int main(int argc, char **argv) {
Chris Lattner670406d2003-10-18 21:55:35 +000035 cl::ParseCommandLineOptions(argc, argv,
36 " LLVM automatic testcase reducer. See\nhttp://"
37 "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
38 " for more information.\n");
Chris Lattnerafade922002-11-20 22:28:10 +000039
Chris Lattnerafade922002-11-20 22:28:10 +000040 BugDriver D(argv[0]);
41 if (D.addSources(InputFilenames)) return 1;
42 D.addPasses(PassList.begin(), PassList.end());
43
Misha Brukman67b36e42003-09-12 20:42:57 +000044 // Bugpoint has the ability of generating a plethora of core files, so to
45 // avoid filling up the disk, set the max core file size to 0.
46 struct rlimit rlim;
47 rlim.rlim_cur = rlim.rlim_max = 0;
48 int res = setrlimit(RLIMIT_CORE, &rlim);
49 if (res < 0) {
50 // setrlimit() may have failed, but we're not going to let that stop us
51 perror("setrlimit: RLIMIT_CORE");
52 }
53
Chris Lattner74d45272004-02-18 17:32:54 +000054 try {
55 return D.run();
Chris Lattner230fef82004-02-18 20:22:11 +000056 } catch (ToolExecutionError &TEE) {
57 std::cerr << "Tool execution error: " << TEE.getMessage() << "\n";
58 return 1;
Chris Lattner74d45272004-02-18 17:32:54 +000059 } catch (...) {
60 std::cerr << "Whoops, an exception leaked out of bugpoint. "
61 << "This is a bug in bugpoint!\n";
62 return 1;
63 }
Chris Lattnerafade922002-11-20 22:28:10 +000064}