[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / tools / llvm-readtapi / llvm-readtapi.cpp
blob1a3a66e2a7a1c3c5ddb78aeaf21f70e8f4acc46c
1 //===-- llvm-readtapi.cpp - tapi file reader and manipulator -----*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the command-line driver for llvm-readtapi.
11 //===----------------------------------------------------------------------===//
12 #include "DiffEngine.h"
13 #include "llvm/Object/TapiUniversal.h"
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/Error.h"
16 #include "llvm/Support/InitLLVM.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Support/WithColor.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include <cstdlib>
22 using namespace llvm;
23 using namespace MachO;
24 using namespace object;
26 namespace {
27 cl::OptionCategory TapiCat("llvm-readtapi options");
28 cl::OptionCategory CompareCat("llvm-readtapi --compare options");
30 cl::opt<std::string> InputFileName(cl::Positional, cl::desc("<tapi file>"),
31 cl::Required, cl::cat(TapiCat));
32 cl::opt<std::string> CompareInputFileName(cl::Positional,
33 cl::desc("<comparison file>"),
34 cl::Required, cl::cat(CompareCat));
35 enum OutputKind {
36 Compare,
39 cl::opt<OutputKind>
40 Output(cl::desc("choose command action:"),
41 cl::values(clEnumValN(Compare, "compare",
42 "compare tapi file for library differences")),
43 cl::init(OutputKind::Compare), cl::cat(TapiCat));
44 } // anonymous namespace
46 Expected<std::unique_ptr<Binary>> convertFileToBinary(std::string &Filename) {
47 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
48 MemoryBuffer::getFileOrSTDIN(Filename);
49 if (BufferOrErr.getError())
50 return errorCodeToError(BufferOrErr.getError());
51 return createBinary(BufferOrErr.get()->getMemBufferRef());
54 int main(int Argc, char **Argv) {
55 InitLLVM X(Argc, Argv);
56 cl::HideUnrelatedOptions(TapiCat);
57 cl::ParseCommandLineOptions(Argc, Argv,
58 "TAPI File Reader and Manipulator Tool");
60 if (Output == OutputKind::Compare) {
61 if (InputFileName.empty() || CompareInputFileName.empty()) {
62 cl::PrintHelpMessage();
63 return EXIT_FAILURE;
66 ExitOnError ExitOnErr("error: '" + InputFileName + "' ",
67 /*DefaultErrorExitCode=*/2);
68 auto BinLHS = ExitOnErr(convertFileToBinary(InputFileName));
70 TapiUniversal *FileLHS = dyn_cast<TapiUniversal>(BinLHS.get());
71 if (!FileLHS) {
72 ExitOnErr(createStringError(std::errc::executable_format_error,
73 "unsupported file format"));
76 ExitOnErr.setBanner("error: '" + CompareInputFileName + "' ");
77 auto BinRHS = ExitOnErr(convertFileToBinary(CompareInputFileName));
79 TapiUniversal *FileRHS = dyn_cast<TapiUniversal>(BinRHS.get());
80 if (!FileRHS) {
81 ExitOnErr(createStringError(std::errc::executable_format_error,
82 "unsupported file format"));
85 raw_ostream &OS = outs();
86 return DiffEngine(FileLHS, FileRHS).compareFiles(OS);
89 return 0;