forked from OSchip/llvm-project
lld/MachO: Move MachOOptTable to DriverUtils.cpp, remove DriverUtils.h
This makes lld/MachO look more like lld/COFF and lld/ELF, as discussed in D91640.
This commit is contained in:
parent
72ccec1bbc
commit
c519bc7e16
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "Driver.h"
|
||||
#include "Config.h"
|
||||
#include "DriverUtils.h"
|
||||
#include "InputFiles.h"
|
||||
#include "LTO.h"
|
||||
#include "ObjC.h"
|
||||
|
@ -34,7 +33,6 @@
|
|||
#include "llvm/LTO/LTO.h"
|
||||
#include "llvm/Object/Archive.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
@ -53,68 +51,6 @@ using namespace lld::macho;
|
|||
|
||||
Configuration *lld::macho::config;
|
||||
|
||||
// Create prefix string literals used in Options.td
|
||||
#define PREFIX(NAME, VALUE) const char *NAME[] = VALUE;
|
||||
#include "Options.inc"
|
||||
#undef PREFIX
|
||||
|
||||
// Create table mapping all options defined in Options.td
|
||||
static const opt::OptTable::Info optInfo[] = {
|
||||
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
|
||||
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
|
||||
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
|
||||
#include "Options.inc"
|
||||
#undef OPTION
|
||||
};
|
||||
|
||||
MachOOptTable::MachOOptTable() : OptTable(optInfo) {}
|
||||
|
||||
// Set color diagnostics according to --color-diagnostics={auto,always,never}
|
||||
// or --no-color-diagnostics flags.
|
||||
static void handleColorDiagnostics(opt::InputArgList &args) {
|
||||
auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
|
||||
OPT_no_color_diagnostics);
|
||||
if (!arg)
|
||||
return;
|
||||
if (arg->getOption().getID() == OPT_color_diagnostics) {
|
||||
lld::errs().enable_colors(true);
|
||||
} else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
|
||||
lld::errs().enable_colors(false);
|
||||
} else {
|
||||
StringRef s = arg->getValue();
|
||||
if (s == "always")
|
||||
lld::errs().enable_colors(true);
|
||||
else if (s == "never")
|
||||
lld::errs().enable_colors(false);
|
||||
else if (s != "auto")
|
||||
error("unknown option: --color-diagnostics=" + s);
|
||||
}
|
||||
}
|
||||
|
||||
opt::InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
|
||||
// Make InputArgList from string vectors.
|
||||
unsigned missingIndex;
|
||||
unsigned missingCount;
|
||||
SmallVector<const char *, 256> vec(argv.data(), argv.data() + argv.size());
|
||||
|
||||
opt::InputArgList args = ParseArgs(vec, missingIndex, missingCount);
|
||||
|
||||
if (missingCount)
|
||||
error(Twine(args.getArgString(missingIndex)) + ": missing argument");
|
||||
|
||||
handleColorDiagnostics(args);
|
||||
|
||||
for (opt::Arg *arg : args.filtered(OPT_UNKNOWN))
|
||||
error("unknown argument: " + arg->getSpelling());
|
||||
return args;
|
||||
}
|
||||
|
||||
void MachOOptTable::printHelp(const char *argv0, bool showHidden) const {
|
||||
PrintHelp(lld::outs(), (std::string(argv0) + " [options] file...").c_str(),
|
||||
"LLVM Linker", showHidden);
|
||||
lld::outs() << "\n";
|
||||
}
|
||||
|
||||
static HeaderFileType getOutputType(const opt::InputArgList &args) {
|
||||
// TODO: -r, -dylinker, -preload...
|
||||
opt::Arg *outputArg = args.getLastArg(OPT_bundle, OPT_dylib, OPT_execute);
|
||||
|
|
|
@ -10,11 +10,16 @@
|
|||
#define LLD_MACHO_DRIVER_H
|
||||
|
||||
#include "lld/Common/LLVM.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Option/OptTable.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
namespace lld {
|
||||
namespace macho {
|
||||
|
||||
class DylibFile;
|
||||
|
||||
class MachOOptTable : public llvm::opt::OptTable {
|
||||
public:
|
||||
MachOOptTable();
|
||||
|
@ -30,6 +35,12 @@ enum {
|
|||
#undef OPTION
|
||||
};
|
||||
|
||||
// Check for both libfoo.dylib and libfoo.tbd (in that order).
|
||||
llvm::Optional<std::string> resolveDylibPath(llvm::StringRef path);
|
||||
|
||||
llvm::Optional<DylibFile *> makeDylibFromTAPI(llvm::MemoryBufferRef mbref,
|
||||
DylibFile *umbrella = nullptr);
|
||||
|
||||
} // namespace macho
|
||||
} // namespace lld
|
||||
|
||||
|
|
|
@ -6,20 +6,86 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "DriverUtils.h"
|
||||
#include "Driver.h"
|
||||
#include "InputFiles.h"
|
||||
|
||||
#include "lld/Common/ErrorHandler.h"
|
||||
#include "lld/Common/Memory.h"
|
||||
#include "llvm/Option/Arg.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIReader.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
using namespace llvm::opt;
|
||||
using namespace llvm::sys;
|
||||
using namespace lld;
|
||||
using namespace lld::macho;
|
||||
|
||||
// Create prefix string literals used in Options.td
|
||||
#define PREFIX(NAME, VALUE) const char *NAME[] = VALUE;
|
||||
#include "Options.inc"
|
||||
#undef PREFIX
|
||||
|
||||
// Create table mapping all options defined in Options.td
|
||||
static const opt::OptTable::Info optInfo[] = {
|
||||
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
|
||||
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
|
||||
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
|
||||
#include "Options.inc"
|
||||
#undef OPTION
|
||||
};
|
||||
|
||||
MachOOptTable::MachOOptTable() : OptTable(optInfo) {}
|
||||
|
||||
// Set color diagnostics according to --color-diagnostics={auto,always,never}
|
||||
// or --no-color-diagnostics flags.
|
||||
static void handleColorDiagnostics(opt::InputArgList &args) {
|
||||
auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
|
||||
OPT_no_color_diagnostics);
|
||||
if (!arg)
|
||||
return;
|
||||
if (arg->getOption().getID() == OPT_color_diagnostics) {
|
||||
lld::errs().enable_colors(true);
|
||||
} else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
|
||||
lld::errs().enable_colors(false);
|
||||
} else {
|
||||
StringRef s = arg->getValue();
|
||||
if (s == "always")
|
||||
lld::errs().enable_colors(true);
|
||||
else if (s == "never")
|
||||
lld::errs().enable_colors(false);
|
||||
else if (s != "auto")
|
||||
error("unknown option: --color-diagnostics=" + s);
|
||||
}
|
||||
}
|
||||
|
||||
opt::InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
|
||||
// Make InputArgList from string vectors.
|
||||
unsigned missingIndex;
|
||||
unsigned missingCount;
|
||||
SmallVector<const char *, 256> vec(argv.data(), argv.data() + argv.size());
|
||||
|
||||
opt::InputArgList args = ParseArgs(vec, missingIndex, missingCount);
|
||||
|
||||
if (missingCount)
|
||||
error(Twine(args.getArgString(missingIndex)) + ": missing argument");
|
||||
|
||||
handleColorDiagnostics(args);
|
||||
|
||||
for (opt::Arg *arg : args.filtered(OPT_UNKNOWN))
|
||||
error("unknown argument: " + arg->getSpelling());
|
||||
return args;
|
||||
}
|
||||
|
||||
void MachOOptTable::printHelp(const char *argv0, bool showHidden) const {
|
||||
PrintHelp(lld::outs(), (std::string(argv0) + " [options] file...").c_str(),
|
||||
"LLVM Linker", showHidden);
|
||||
lld::outs() << "\n";
|
||||
}
|
||||
|
||||
Optional<std::string> macho::resolveDylibPath(StringRef path) {
|
||||
// TODO: if a tbd and dylib are both present, we should check to make sure
|
||||
// they are consistent.
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
//===- DriverUtils.h --------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLD_MACHO_DRIVER_UTILS_H
|
||||
#define LLD_MACHO_DRIVER_UTILS_H
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
namespace lld {
|
||||
namespace macho {
|
||||
|
||||
class DylibFile;
|
||||
|
||||
// Check for both libfoo.dylib and libfoo.tbd (in that order).
|
||||
llvm::Optional<std::string> resolveDylibPath(llvm::StringRef path);
|
||||
|
||||
llvm::Optional<DylibFile *> makeDylibFromTAPI(llvm::MemoryBufferRef mbref,
|
||||
DylibFile *umbrella = nullptr);
|
||||
|
||||
} // namespace macho
|
||||
} // namespace lld
|
||||
|
||||
#endif
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
#include "InputFiles.h"
|
||||
#include "Config.h"
|
||||
#include "DriverUtils.h"
|
||||
#include "Driver.h"
|
||||
#include "ExportTrie.h"
|
||||
#include "InputSection.h"
|
||||
#include "MachOStructs.h"
|
||||
|
|
Loading…
Reference in New Issue