[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / tools / llvm-driver / llvm-driver.cpp
bloba0f1ca831d93b6a417434b19fcd43271e186a2b7
1 //===-- llvm-driver.cpp ---------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringExtras.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Support/ErrorHandling.h"
13 #include "llvm/Support/LLVMDriver.h"
14 #include "llvm/Support/Path.h"
15 #include "llvm/Support/WithColor.h"
17 using namespace llvm;
19 #define LLVM_DRIVER_TOOL(tool, entry) \
20 int entry##_main(int argc, char **argv, const llvm::ToolContext &);
21 #include "LLVMDriverTools.def"
23 constexpr char subcommands[] =
24 #define LLVM_DRIVER_TOOL(tool, entry) " " tool "\n"
25 #include "LLVMDriverTools.def"
28 static void printHelpMessage() {
29 llvm::outs() << "OVERVIEW: llvm toolchain driver\n\n"
30 << "USAGE: llvm [subcommand] [options]\n\n"
31 << "SUBCOMMANDS:\n\n"
32 << subcommands
33 << "\n Type \"llvm <subcommand> --help\" to get more help on a "
34 "specific subcommand\n\n"
35 << "OPTIONS:\n\n --help - Display this message";
38 static int findTool(int Argc, char **Argv, const char *Argv0) {
39 if (!Argc) {
40 printHelpMessage();
41 return 1;
44 StringRef ToolName = Argv[0];
46 if (ToolName == "--help") {
47 printHelpMessage();
48 return 0;
51 StringRef Stem = sys::path::stem(ToolName);
52 auto Is = [=](StringRef Tool) {
53 auto IsImpl = [=](StringRef Stem) {
54 auto I = Stem.rfind_insensitive(Tool);
55 return I != StringRef::npos && (I + Tool.size() == Stem.size() ||
56 !llvm::isAlnum(Stem[I + Tool.size()]));
58 for (StringRef S : {Stem, sys::path::filename(ToolName)})
59 if (IsImpl(S))
60 return true;
61 return false;
64 auto MakeDriverArgs = [=]() -> llvm::ToolContext {
65 if (ToolName != Argv0)
66 return {Argv0, ToolName.data(), true};
67 return {Argv0, sys::path::filename(Argv0).data(), false};
70 #define LLVM_DRIVER_TOOL(tool, entry) \
71 if (Is(tool)) \
72 return entry##_main(Argc, Argv, MakeDriverArgs());
73 #include "LLVMDriverTools.def"
75 if (Is("llvm") || Argv0 == Argv[0])
76 return findTool(Argc - 1, Argv + 1, Argv0);
78 printHelpMessage();
79 return 1;
82 int main(int Argc, char **Argv) { return findTool(Argc, Argv, Argv[0]); }