summaryrefslogtreecommitdiff
path: root/tools/lto-bugpoint/lto-bugpoint.cpp
blob: 8633415d65cc9980c9aa66f963bd9a65f2fda690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//===- lto-bugpoing.cpp - The lto-bugpoint driver -------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// lto-bugpoint tool identifies minmal set of bitcode files that is causing
// failure when Link Time Optimization is enabled. The failure is identified
// using developer provided validation script.
//
//===----------------------------------------------------------------------===//

#include "LTOBugPoint.h"
#include <iostream>
#include <fstream>

int main(int argc, char **argv) {
  try {

    if (argc !=  4) {
      std::cerr << "Invalid number of lto-bugpoint arguments!\n";
      return 1;
    }
    
    std::ios::openmode input_mode = std::ios::in;

    // First argument is linker command line options file. This text file
    // is a list of linker command line options, one option per line.
    // First line always list the absolute path to invoke the linker.
    std::istream *LinkerArgsFile = new std::ifstream(argv[1], input_mode);
    if (!LinkerArgsFile->good()) {
      std::cerr << argv[0] << ": error opening " << argv[1] << "!\n";
      return 1;
    }

    // Second argment is a text file that includes the linker input
    // file paths, one input file path per line. 
    std::istream *LinkerInputsFile = new std::ifstream(argv[2], input_mode);
    if (!LinkerInputsFile->good()) {
      std::cerr << argv[0] << ": error opening " << argv[2] << "!\n";
      delete LinkerArgsFile;
      return 1;
    }

    // Third argument is absolute path to the validation script. This
    // script is used to validate LTO error under investigation.
    std::istream *ValidationScriptFile = new std::ifstream(argv[3], input_mode);
    if (!ValidationScriptFile->good()) {
      std::cerr << argv[0] << ": error opening " << argv[3] << "!\n";
      delete LinkerArgsFile;
      delete LinkerInputsFile;
      return 1;
    }

    LTOBugPoint bugFinder(*LinkerArgsFile, *LinkerInputsFile);

    return 0;
  } catch (const std::string& msg) {
    std::cerr << argv[0] << ": " << msg << "\n";
  } catch (...) {
    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
  }
  return 1;
}