blob: a4eae3cecd06c8c6c09eb39b05c1b47de9317112 [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"
Reid Spencer551ccae2004-09-01 22:55:40 +000019#include "llvm/System/SysConfig.h"
20#include "llvm/Support/CommandLine.h"
21#include "llvm/Support/PluginLoader.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000022#include "llvm/System/Signals.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000023#include "llvm/Config/unistd.h"
24//#include <sys/resource.h>
Brian Gaeked0fde302003-11-11 22:41:34 +000025using namespace llvm;
26
Chris Lattnerafade922002-11-20 22:28:10 +000027static cl::list<std::string>
28InputFilenames(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//
34static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukman50733362003-07-24 18:17:43 +000035PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattnerafade922002-11-20 22:28:10 +000036
Chris Lattnerafade922002-11-20 22:28:10 +000037int main(int argc, char **argv) {
Chris Lattner670406d2003-10-18 21:55:35 +000038 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");
Reid Spencer9de7b332004-08-29 19:28:55 +000042 sys::PrintStackTraceOnErrorSignal();
Chris Lattnerafade922002-11-20 22:28:10 +000043
Chris Lattnerafade922002-11-20 22:28:10 +000044 BugDriver D(argv[0]);
45 if (D.addSources(InputFilenames)) return 1;
46 D.addPasses(PassList.begin(), PassList.end());
47
Misha Brukman67b36e42003-09-12 20:42:57 +000048 // Bugpoint has the ability of generating a plethora of core files, so to
Reid Spencer551ccae2004-09-01 22:55:40 +000049 // avoid filling up the disk, we prevent it
50 sys::PreventCoreFiles();
Misha Brukman67b36e42003-09-12 20:42:57 +000051
Chris Lattner74d45272004-02-18 17:32:54 +000052 try {
53 return D.run();
Chris Lattner230fef82004-02-18 20:22:11 +000054 } catch (ToolExecutionError &TEE) {
Misha Brukmaneed80e22004-07-23 01:30:49 +000055 std::cerr << "Tool execution error: " << TEE.what() << '\n';
Chris Lattner230fef82004-02-18 20:22:11 +000056 return 1;
Chris Lattner74d45272004-02-18 17:32:54 +000057 } catch (...) {
58 std::cerr << "Whoops, an exception leaked out of bugpoint. "
59 << "This is a bug in bugpoint!\n";
60 return 1;
61 }
Chris Lattnerafade922002-11-20 22:28:10 +000062}