blob: 21a462318124ae766c4b415cd623f2957a5a6292 [file] [log] [blame]
Chris Lattnerebec8032003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
Misha Brukman650ba8e2005-04-22 00:00:37 +00002//
John Criswell09344dc2003-10-20 17:47:21 +00003// 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.
Misha Brukman650ba8e2005-04-22 00:00:37 +00007//
John Criswell09344dc2003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner73a6bdd2002-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 Lattnerffac2862006-06-06 22:30:59 +000017#include "ToolRunner.h"
Chris Lattner652ce542005-10-24 01:05:53 +000018#include "llvm/Analysis/LinkAllAnalyses.h"
19#include "llvm/Transforms/LinkAllPasses.h"
Chris Lattner73a6bdd2002-11-20 22:28:10 +000020#include "llvm/Support/PassNameParser.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000021#include "llvm/Support/CommandLine.h"
22#include "llvm/Support/PluginLoader.h"
Reid Spencera079b692004-12-27 06:18:02 +000023#include "llvm/System/Process.h"
Chris Lattner278f5152004-05-27 05:41:36 +000024#include "llvm/System/Signals.h"
Reid Spencerc1588f62006-06-07 23:06:50 +000025#include "llvm/LinkAllVMCore.h"
Brian Gaeke960707c2003-11-11 22:41:34 +000026using namespace llvm;
27
Reid Spencer842118c2005-12-22 20:02:55 +000028// AsChild - Specifies that this invocation of bugpoint is being generated
29// from a parent process. It is not intended to be used by users so the
30// option is hidden.
31static cl::opt<bool>
32 AsChild("as-child", cl::desc("Run bugpoint as child process"),
33 cl::ReallyHidden);
34
Chris Lattner73a6bdd2002-11-20 22:28:10 +000035static cl::list<std::string>
36InputFilenames(cl::Positional, cl::OneOrMore,
37 cl::desc("<input llvm ll/bc files>"));
38
39// The AnalysesList is automatically populated with registered Passes by the
40// PassNameParser.
41//
42static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukmand792c9b2003-07-24 18:17:43 +000043PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattner73a6bdd2002-11-20 22:28:10 +000044
Chris Lattnerbeb01fa2005-08-02 02:16:17 +000045/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
46bool llvm::BugpointIsInterrupted = false;
47
48static void BugpointInterruptFunction() {
49 BugpointIsInterrupted = true;
50}
51
Chris Lattner73a6bdd2002-11-20 22:28:10 +000052int main(int argc, char **argv) {
Chris Lattner849619e2003-10-18 21:55:35 +000053 cl::ParseCommandLineOptions(argc, argv,
54 " LLVM automatic testcase reducer. See\nhttp://"
Reid Spencerc67a0602006-03-14 05:54:52 +000055 "llvm.org/docs/CommandGuide/bugpoint.html"
Chris Lattner849619e2003-10-18 21:55:35 +000056 " for more information.\n");
Reid Spencere3263ec2004-08-29 19:28:55 +000057 sys::PrintStackTraceOnErrorSignal();
Chris Lattnerbeb01fa2005-08-02 02:16:17 +000058 sys::SetInterruptFunction(BugpointInterruptFunction);
59
Reid Spencer842118c2005-12-22 20:02:55 +000060 BugDriver D(argv[0],AsChild);
Chris Lattner73a6bdd2002-11-20 22:28:10 +000061 if (D.addSources(InputFilenames)) return 1;
62 D.addPasses(PassList.begin(), PassList.end());
63
Misha Brukman46e18d42003-09-12 20:42:57 +000064 // Bugpoint has the ability of generating a plethora of core files, so to
Reid Spencer7c16caa2004-09-01 22:55:40 +000065 // avoid filling up the disk, we prevent it
Reid Spencera079b692004-12-27 06:18:02 +000066 sys::Process::PreventCoreFiles();
Misha Brukman46e18d42003-09-12 20:42:57 +000067
Chris Lattnereb89dba2004-02-18 17:32:54 +000068 try {
69 return D.run();
Chris Lattner947143d2004-02-18 20:22:11 +000070 } catch (ToolExecutionError &TEE) {
Misha Brukman6aa3c832004-07-23 01:30:49 +000071 std::cerr << "Tool execution error: " << TEE.what() << '\n';
Reid Spencer996ec722004-12-30 05:36:08 +000072 } catch (const std::string& msg) {
73 std::cerr << argv[0] << ": " << msg << "\n";
Chris Lattnereb89dba2004-02-18 17:32:54 +000074 } catch (...) {
75 std::cerr << "Whoops, an exception leaked out of bugpoint. "
76 << "This is a bug in bugpoint!\n";
Chris Lattnereb89dba2004-02-18 17:32:54 +000077 }
Reid Spencer996ec722004-12-30 05:36:08 +000078 return 1;
Chris Lattner73a6bdd2002-11-20 22:28:10 +000079}