blob: 0f25cf8a50675abb594ae2bd468f4f89f7c8c610 [file] [log] [blame]
Chris Lattner94321112003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell7c0e0222003-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 Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell7c0e0222003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
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 Lattner831843d2005-10-24 01:05:53 +000017#include "llvm/Analysis/LinkAllAnalyses.h"
18#include "llvm/Transforms/LinkAllPasses.h"
Chris Lattnerafade922002-11-20 22:28:10 +000019#include "llvm/Support/PassNameParser.h"
Chris Lattner230fef82004-02-18 20:22:11 +000020#include "llvm/Support/ToolRunner.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000021#include "llvm/Support/CommandLine.h"
22#include "llvm/Support/PluginLoader.h"
Reid Spencer51163302004-12-27 06:18:02 +000023#include "llvm/System/Process.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000024#include "llvm/System/Signals.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 Lattnerf9aaae02005-08-02 02:16:17 +000037/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
38bool llvm::BugpointIsInterrupted = false;
39
40static void BugpointInterruptFunction() {
41 BugpointIsInterrupted = true;
42}
43
Chris Lattnerafade922002-11-20 22:28:10 +000044int main(int argc, char **argv) {
Chris Lattner670406d2003-10-18 21:55:35 +000045 cl::ParseCommandLineOptions(argc, argv,
46 " LLVM automatic testcase reducer. See\nhttp://"
47 "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
48 " for more information.\n");
Reid Spencer9de7b332004-08-29 19:28:55 +000049 sys::PrintStackTraceOnErrorSignal();
Chris Lattnerf9aaae02005-08-02 02:16:17 +000050 sys::SetInterruptFunction(BugpointInterruptFunction);
51
Chris Lattnerafade922002-11-20 22:28:10 +000052 BugDriver D(argv[0]);
53 if (D.addSources(InputFilenames)) return 1;
54 D.addPasses(PassList.begin(), PassList.end());
55
Misha Brukman67b36e42003-09-12 20:42:57 +000056 // Bugpoint has the ability of generating a plethora of core files, so to
Reid Spencer551ccae2004-09-01 22:55:40 +000057 // avoid filling up the disk, we prevent it
Reid Spencer51163302004-12-27 06:18:02 +000058 sys::Process::PreventCoreFiles();
Misha Brukman67b36e42003-09-12 20:42:57 +000059
Chris Lattner74d45272004-02-18 17:32:54 +000060 try {
61 return D.run();
Chris Lattner230fef82004-02-18 20:22:11 +000062 } catch (ToolExecutionError &TEE) {
Misha Brukmaneed80e22004-07-23 01:30:49 +000063 std::cerr << "Tool execution error: " << TEE.what() << '\n';
Reid Spencer1ef8bda2004-12-30 05:36:08 +000064 } catch (const std::string& msg) {
65 std::cerr << argv[0] << ": " << msg << "\n";
Chris Lattner74d45272004-02-18 17:32:54 +000066 } catch (...) {
67 std::cerr << "Whoops, an exception leaked out of bugpoint. "
68 << "This is a bug in bugpoint!\n";
Chris Lattner74d45272004-02-18 17:32:54 +000069 }
Reid Spencer1ef8bda2004-12-30 05:36:08 +000070 return 1;
Chris Lattnerafade922002-11-20 22:28:10 +000071}