blob: 9e5b4c4e87986013b50e3fc98ec235e8b9dfce50 [file] [log] [blame]
Chris Lattnerebec8032003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
John Criswell09344dc2003-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 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 Lattner73a6bdd2002-11-20 22:28:10 +000017#include "llvm/Support/PassNameParser.h"
Chris Lattner947143d2004-02-18 20:22:11 +000018#include "llvm/Support/ToolRunner.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000019#include "llvm/Support/CommandLine.h"
20#include "llvm/Support/PluginLoader.h"
Reid Spencera079b692004-12-27 06:18:02 +000021#include "llvm/System/Process.h"
Chris Lattner278f5152004-05-27 05:41:36 +000022#include "llvm/System/Signals.h"
Brian Gaeke960707c2003-11-11 22:41:34 +000023using namespace llvm;
24
Chris Lattner73a6bdd2002-11-20 22:28:10 +000025static cl::list<std::string>
26InputFilenames(cl::Positional, cl::OneOrMore,
27 cl::desc("<input llvm ll/bc files>"));
28
29// The AnalysesList is automatically populated with registered Passes by the
30// PassNameParser.
31//
32static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukmand792c9b2003-07-24 18:17:43 +000033PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattner73a6bdd2002-11-20 22:28:10 +000034
Chris Lattner73a6bdd2002-11-20 22:28:10 +000035int main(int argc, char **argv) {
Chris Lattner849619e2003-10-18 21:55:35 +000036 cl::ParseCommandLineOptions(argc, argv,
37 " LLVM automatic testcase reducer. See\nhttp://"
38 "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
39 " for more information.\n");
Reid Spencere3263ec2004-08-29 19:28:55 +000040 sys::PrintStackTraceOnErrorSignal();
Chris Lattner73a6bdd2002-11-20 22:28:10 +000041
Chris Lattner73a6bdd2002-11-20 22:28:10 +000042 BugDriver D(argv[0]);
43 if (D.addSources(InputFilenames)) return 1;
44 D.addPasses(PassList.begin(), PassList.end());
45
Misha Brukman46e18d42003-09-12 20:42:57 +000046 // Bugpoint has the ability of generating a plethora of core files, so to
Reid Spencer7c16caa2004-09-01 22:55:40 +000047 // avoid filling up the disk, we prevent it
Reid Spencera079b692004-12-27 06:18:02 +000048 sys::Process::PreventCoreFiles();
Misha Brukman46e18d42003-09-12 20:42:57 +000049
Chris Lattnereb89dba2004-02-18 17:32:54 +000050 try {
51 return D.run();
Chris Lattner947143d2004-02-18 20:22:11 +000052 } catch (ToolExecutionError &TEE) {
Misha Brukman6aa3c832004-07-23 01:30:49 +000053 std::cerr << "Tool execution error: " << TEE.what() << '\n';
Reid Spencer996ec722004-12-30 05:36:08 +000054 } catch (const std::string& msg) {
55 std::cerr << argv[0] << ": " << msg << "\n";
Chris Lattnereb89dba2004-02-18 17:32:54 +000056 } catch (...) {
57 std::cerr << "Whoops, an exception leaked out of bugpoint. "
58 << "This is a bug in bugpoint!\n";
Chris Lattnereb89dba2004-02-18 17:32:54 +000059 }
Reid Spencer996ec722004-12-30 05:36:08 +000060 return 1;
Chris Lattner73a6bdd2002-11-20 22:28:10 +000061}