blob: 230d3eb44f149f5d68183be9b529ebb650c5ab15 [file] [log] [blame]
Devang Patele330f2d2008-07-18 22:59:45 +00001//===- lto-bugpoing.cpp - The lto-bugpoint driver -------------------------===//
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// lto-bugpoint tool identifies minmal set of bitcode files that is causing
11// failure when Link Time Optimization is enabled. The failure is identified
12// using developer provided validation script.
13//
14//===----------------------------------------------------------------------===//
15
16#include "LTOBugPoint.h"
17#include <iostream>
18#include <fstream>
19
20int main(int argc, char **argv) {
21 try {
22
23 if (argc != 4) {
24 std::cerr << "Invalid number of lto-bugpoint arguments!\n";
25 return 1;
26 }
27
28 std::ios::openmode input_mode = std::ios::in;
29
30 // First argument is linker command line options file. This text file
31 // is a list of linker command line options, one option per line.
32 // First line always list the absolute path to invoke the linker.
33 std::istream *LinkerArgsFile = new std::ifstream(argv[1], input_mode);
34 if (!LinkerArgsFile->good()) {
35 std::cerr << argv[0] << ": error opening " << argv[1] << "!\n";
36 return 1;
37 }
38
39 // Second argment is a text file that includes the linker input
40 // file paths, one input file path per line.
41 std::istream *LinkerInputsFile = new std::ifstream(argv[2], input_mode);
42 if (!LinkerInputsFile->good()) {
43 std::cerr << argv[0] << ": error opening " << argv[2] << "!\n";
44 delete LinkerArgsFile;
45 return 1;
46 }
47
48 // Third argument is absolute path to the validation script. This
49 // script is used to validate LTO error under investigation.
Devang Patel5dd66a02008-07-18 23:46:41 +000050 std::string ValidationScript = argv[3];
Devang Patele330f2d2008-07-18 22:59:45 +000051 LTOBugPoint bugFinder(*LinkerArgsFile, *LinkerInputsFile);
52
Devang Patel5dd66a02008-07-18 23:46:41 +000053 llvm::SmallVector<std::string, 4> TroubleMakers;
Devang Patel4f574f52008-07-21 23:04:39 +000054 if (!bugFinder.findTroubleMakers(TroubleMakers, ValidationScript)) {
55 std::cerr << "lto-bugpoint:" << bugFinder.getErrMsg() << "\n";
Devang Patel5dd66a02008-07-18 23:46:41 +000056 return 1;
Devang Patel4f574f52008-07-21 23:04:39 +000057 }
Devang Patel5dd66a02008-07-18 23:46:41 +000058
Devang Patele330f2d2008-07-18 22:59:45 +000059 return 0;
60 } catch (const std::string& msg) {
61 std::cerr << argv[0] << ": " << msg << "\n";
62 } catch (...) {
63 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
64 }
65 return 1;
66}