bugpoint.cpp revision e3f056154537194afd06c1940de72d4b6f2f4147
1//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===// 2// 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//===----------------------------------------------------------------------===// 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. 13// 14//===----------------------------------------------------------------------===// 15 16#include "BugDriver.h" 17#include "ToolRunner.h" 18#include "llvm/Analysis/LinkAllAnalyses.h" 19#include "llvm/Transforms/LinkAllPasses.h" 20#include "llvm/Support/PassNameParser.h" 21#include "llvm/Support/CommandLine.h" 22#include "llvm/Support/PluginLoader.h" 23#include "llvm/System/Process.h" 24#include "llvm/System/Signals.h" 25#include "llvm/LinkAllVMCore.h" 26using namespace llvm; 27 28// 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 35static 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> 43PassList(cl::desc("Passes available:"), cl::ZeroOrMore); 44 45/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 46bool llvm::BugpointIsInterrupted = false; 47 48static void BugpointInterruptFunction() { 49 BugpointIsInterrupted = true; 50} 51 52int main(int argc, char **argv) { 53 cl::ParseCommandLineOptions(argc, argv, 54 " LLVM automatic testcase reducer. See\nhttp://" 55 "llvm.org/docs/CommandGuide/bugpoint.html" 56 " for more information.\n"); 57 sys::PrintStackTraceOnErrorSignal(); 58 sys::SetInterruptFunction(BugpointInterruptFunction); 59 60 BugDriver D(argv[0],AsChild); 61 if (D.addSources(InputFilenames)) return 1; 62 D.addPasses(PassList.begin(), PassList.end()); 63 64 // Bugpoint has the ability of generating a plethora of core files, so to 65 // avoid filling up the disk, we prevent it 66 sys::Process::PreventCoreFiles(); 67 68 try { 69 return D.run(); 70 } catch (ToolExecutionError &TEE) { 71 std::cerr << "Tool execution error: " << TEE.what() << '\n'; 72 } catch (const std::string& msg) { 73 std::cerr << argv[0] << ": " << msg << "\n"; 74 } catch (...) { 75 std::cerr << "Whoops, an exception leaked out of bugpoint. " 76 << "This is a bug in bugpoint!\n"; 77 } 78 return 1; 79} 80