(Hopefully) unbreak Apple-style builds.
[llvm/msp430.git] / tools / bugpoint / bugpoint.cpp
blob20f0e99a848881b40180c27afef40bb912d05ce5
1 //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
14 //===----------------------------------------------------------------------===//
16 #include "BugDriver.h"
17 #include "ToolRunner.h"
18 #include "llvm/LinkAllPasses.h"
19 #include "llvm/Support/PassNameParser.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/ManagedStatic.h"
22 #include "llvm/Support/PluginLoader.h"
23 #include "llvm/Support/PrettyStackTrace.h"
24 #include "llvm/System/Process.h"
25 #include "llvm/System/Signals.h"
26 #include "llvm/LinkAllVMCore.h"
27 #include <iostream>
28 using namespace llvm;
30 // AsChild - Specifies that this invocation of bugpoint is being generated
31 // from a parent process. It is not intended to be used by users so the
32 // option is hidden.
33 static cl::opt<bool>
34 AsChild("as-child", cl::desc("Run bugpoint as child process"),
35 cl::ReallyHidden);
37 static cl::opt<bool>
38 FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
39 "on program to find bugs"), cl::init(false));
41 static cl::list<std::string>
42 InputFilenames(cl::Positional, cl::OneOrMore,
43 cl::desc("<input llvm ll/bc files>"));
45 static cl::opt<unsigned>
46 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
47 cl::desc("Number of seconds program is allowed to run before it "
48 "is killed (default is 300s), 0 disables timeout"));
50 static cl::opt<unsigned>
51 MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"),
52 cl::desc("Maximum amount of memory to use. 0 disables check."));
54 // The AnalysesList is automatically populated with registered Passes by the
55 // PassNameParser.
57 static cl::list<const PassInfo*, bool, PassNameParser>
58 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
60 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
61 bool llvm::BugpointIsInterrupted = false;
63 static void BugpointInterruptFunction() {
64 BugpointIsInterrupted = true;
67 int main(int argc, char **argv) {
68 llvm::sys::PrintStackTraceOnErrorSignal();
69 llvm::PrettyStackTraceProgram X(argc, argv);
70 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
71 cl::ParseCommandLineOptions(argc, argv,
72 "LLVM automatic testcase reducer. See\nhttp://"
73 "llvm.org/cmds/bugpoint.html"
74 " for more information.\n");
75 sys::SetInterruptFunction(BugpointInterruptFunction);
77 BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
78 if (D.addSources(InputFilenames)) return 1;
79 D.addPasses(PassList.begin(), PassList.end());
81 // Bugpoint has the ability of generating a plethora of core files, so to
82 // avoid filling up the disk, we prevent it
83 sys::Process::PreventCoreFiles();
85 try {
86 return D.run();
87 } catch (ToolExecutionError &TEE) {
88 std::cerr << "Tool execution error: " << TEE.what() << '\n';
89 } catch (const std::string& msg) {
90 std::cerr << argv[0] << ": " << msg << "\n";
91 } catch (const std::bad_alloc &e) {
92 std::cerr << "Oh no, a bugpoint process ran out of memory!\n"
93 "To increase the allocation limits for bugpoint child\n"
94 "processes, use the -mlimit option.\n";
95 } catch (const std::exception &e) {
96 std::cerr << "Whoops, a std::exception leaked out of bugpoint: "
97 << e.what() << "\n"
98 << "This is a bug in bugpoint!\n";
99 } catch (...) {
100 std::cerr << "Whoops, an exception leaked out of bugpoint. "
101 << "This is a bug in bugpoint!\n";
103 return 1;