diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:03:47 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:04:23 +0000 |
commit | 7fa27ce4a07f19b07799a767fc29416f3b625afb (patch) | |
tree | 27825c83636c4de341eb09a74f49f5d38a15d165 /llvm/tools/llvm-dwp | |
parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) | |
download | src-7fa27ce4a07f19b07799a767fc29416f3b625afb.tar.gz src-7fa27ce4a07f19b07799a767fc29416f3b625afb.zip |
Vendor import of llvm-project main llvmorg-17-init-19304-gd0b54bb50e51,vendor/llvm-project/llvmorg-17-init-19304-gd0b54bb50e51
the last commit before the upstream release/17.x branch was created.
Diffstat (limited to 'llvm/tools/llvm-dwp')
-rw-r--r-- | llvm/tools/llvm-dwp/Opts.td | 13 | ||||
-rw-r--r-- | llvm/tools/llvm-dwp/llvm-dwp.cpp | 86 |
2 files changed, 83 insertions, 16 deletions
diff --git a/llvm/tools/llvm-dwp/Opts.td b/llvm/tools/llvm-dwp/Opts.td new file mode 100644 index 000000000000..c01fa4a12cba --- /dev/null +++ b/llvm/tools/llvm-dwp/Opts.td @@ -0,0 +1,13 @@ +include "llvm/Option/OptParser.td" + +class F<string name, string help> : Flag<["-", "--"], name>, HelpText<help>; +class S<string name, string help> : Separate<["-", "--"], name>, HelpText<help>; + +def help : F<"help", "Display this help">; +def : F<"h", "Alias for --help">, Alias<help>; +def version : F<"version", "Display the version of this program">; + +def execFileNames : S<"e", "Specify the executable/library files to get the list of *.dwo from.">, MetaVarName<"<filename>">; +def outputFileName : S<"o", "Specify the output file.">, MetaVarName<"<filename>">; +def continueOnCuIndexOverflow: F<"continue-on-cu-index-overflow", "This turns an error when offset for .debug_*.dwo sections " + "overfolws into a warning.">, MetaVarName<"<filename>">; diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 0a2c1c1ccc02..350a37345e2c 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -23,6 +23,8 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/Option.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/InitLLVM.h" @@ -36,20 +38,46 @@ using namespace llvm::object; static mc::RegisterMCTargetOptionsFlags MCTargetOptionsFlags; -cl::OptionCategory DwpCategory("Specific Options"); -static cl::list<std::string> - InputFiles(cl::Positional, cl::desc("<input files>"), cl::cat(DwpCategory)); +// Command-line option boilerplate. +namespace { +enum ID { + OPT_INVALID = 0, // This is not an option ID. +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + OPT_##ID, +#include "Opts.inc" +#undef OPTION +}; -static cl::list<std::string> ExecFilenames( - "e", - cl::desc( - "Specify the executable/library files to get the list of *.dwo from"), - cl::value_desc("filename"), cl::cat(DwpCategory)); +#define PREFIX(NAME, VALUE) \ + static constexpr StringLiteral NAME##_init[] = VALUE; \ + static constexpr ArrayRef<StringLiteral> NAME(NAME##_init, \ + std::size(NAME##_init) - 1); +#include "Opts.inc" +#undef PREFIX -static cl::opt<std::string> OutputFilename(cl::Required, "o", - cl::desc("Specify the output file."), - cl::value_desc("filename"), - cl::cat(DwpCategory)); +static constexpr opt::OptTable::Info InfoTable[] = { +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + { \ + PREFIX, NAME, HELPTEXT, \ + METAVAR, OPT_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, OPT_##GROUP, \ + OPT_##ALIAS, ALIASARGS, VALUES}, +#include "Opts.inc" +#undef OPTION +}; + +class DwpOptTable : public opt::GenericOptTable { +public: + DwpOptTable() : GenericOptTable(InfoTable) {} +}; +} // end anonymous namespace + +// Options +static std::vector<std::string> ExecFilenames; +static std::string OutputFilename; +static bool ContinueOnCuIndexOverflow; static Expected<SmallVector<std::string, 16>> getDWOFilenames(StringRef ExecFilename) { @@ -100,15 +128,41 @@ static Expected<Triple> readTargetTriple(StringRef FileName) { int main(int argc, char **argv) { InitLLVM X(argc, argv); - cl::HideUnrelatedOptions({&DwpCategory, &getColorCategory()}); - cl::ParseCommandLineOptions(argc, argv, "merge split dwarf (.dwo) files\n"); + DwpOptTable Tbl; + llvm::BumpPtrAllocator A; + llvm::StringSaver Saver{A}; + opt::InputArgList Args = + Tbl.parseArgs(argc, argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) { + llvm::errs() << Msg << '\n'; + std::exit(1); + }); + + if (Args.hasArg(OPT_help)) { + Tbl.printHelp(llvm::outs(), "llvm-dwp [options] <input files>", + "merge split dwarf (.dwo) files"); + std::exit(0); + } + + if (Args.hasArg(OPT_version)) { + llvm::cl::PrintVersionMessage(); + std::exit(0); + } + + OutputFilename = Args.getLastArgValue(OPT_outputFileName, ""); + ContinueOnCuIndexOverflow = Args.hasArg(OPT_continueOnCuIndexOverflow); + + for (const llvm::opt::Arg *A : Args.filtered(OPT_execFileNames)) + ExecFilenames.emplace_back(A->getValue()); + + std::vector<std::string> DWOFilenames; + for (const llvm::opt::Arg *A : Args.filtered(OPT_INPUT)) + DWOFilenames.emplace_back(A->getValue()); llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetMCs(); llvm::InitializeAllTargets(); llvm::InitializeAllAsmPrinters(); - std::vector<std::string> DWOFilenames = InputFiles; for (const auto &ExecFilename : ExecFilenames) { auto DWOs = getDWOFilenames(ExecFilename); if (!DWOs) { @@ -207,7 +261,7 @@ int main(int argc, char **argv) { if (!MS) return error("no object streamer for target " + TripleName, Context); - if (auto Err = write(*MS, DWOFilenames)) { + if (auto Err = write(*MS, DWOFilenames, ContinueOnCuIndexOverflow)) { logAllUnhandledErrors(std::move(Err), WithColor::error()); return 1; } |