[lld] cbcdb52 - [ELF] Simplify --build-id/--color-diagnostics with AliasArgs. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 01:14:57 PDT 2022
Author: Fangrui Song
Date: 2022-07-25T01:14:53-07:00
New Revision: cbcdb5248db7feecb01307fb9334bfea282cd47e
URL: https://github.com/llvm/llvm-project/commit/cbcdb5248db7feecb01307fb9334bfea282cd47e
DIFF: https://github.com/llvm/llvm-project/commit/cbcdb5248db7feecb01307fb9334bfea282cd47e.diff
LOG: [ELF] Simplify --build-id/--color-diagnostics with AliasArgs. NFC
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/DriverUtils.cpp
lld/ELF/Options.td
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 30534f7983b4..36d4e3b50fa5 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -809,13 +809,10 @@ static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &args) {
// --build-id=sha1 are actually tree hashes for performance reasons.
static std::pair<BuildIdKind, std::vector<uint8_t>>
getBuildId(opt::InputArgList &args) {
- auto *arg = args.getLastArg(OPT_build_id, OPT_build_id_eq);
+ auto *arg = args.getLastArg(OPT_build_id);
if (!arg)
return {BuildIdKind::None, {}};
- if (arg->getOption().getID() == OPT_build_id)
- return {BuildIdKind::Fast, {}};
-
StringRef s = arg->getValue();
if (s == "fast")
return {BuildIdKind::Fast, {}};
diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index 54e4f9374e61..1fb6315244f0 100644
--- a/lld/ELF/DriverUtils.cpp
+++ b/lld/ELF/DriverUtils.cpp
@@ -52,23 +52,16 @@ ELFOptTable::ELFOptTable() : 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);
+ auto *arg = args.getLastArg(OPT_color_diagnostics);
if (!arg)
return;
- if (arg->getOption().getID() == OPT_color_diagnostics) {
+ StringRef s = arg->getValue();
+ if (s == "always")
lld::errs().enable_colors(true);
- } else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
+ else if (s == "never")
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);
- }
+ else if (s != "auto")
+ error("unknown option: --color-diagnostics=" + s);
}
static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index c98d21717de0..80c0ff9fe1b8 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -50,10 +50,9 @@ def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries (default)">
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
-def build_id: F<"build-id">, HelpText<"Alias for --build-id=fast">;
-
-def build_id_eq: J<"build-id=">, HelpText<"Generate build ID note">,
+def build_id: J<"build-id=">, HelpText<"Generate build ID note">,
MetaVarName<"[fast,md5,sha1,uuid,0x<hexstring>]">;
+def : F<"build-id">, Alias<build_id>, AliasArgs<["fast"]>, HelpText<"Alias for --build-id=fast">;
defm check_sections: B<"check-sections",
"Check section addresses for overlaps (default)",
@@ -119,12 +118,13 @@ defm call_graph_profile_sort: BB<"call-graph-profile-sort",
// --chroot doesn't have a help text because it is an internal option.
def chroot: Separate<["--"], "chroot">;
-defm color_diagnostics: BB<"color-diagnostics",
- "Alias for --color-diagnostics=always",
- "Alias for --color-diagnostics=never">;
-def color_diagnostics_eq: JJ<"color-diagnostics=">,
+def color_diagnostics: JJ<"color-diagnostics=">,
HelpText<"Use colors in diagnostics (default: auto)">,
MetaVarName<"[auto,always,never]">;
+def : Flag<["--"], "color-diagnostics">, Alias<color_diagnostics>, AliasArgs<["always"]>,
+ HelpText<"Alias for --color-diagnostics=always">;
+def : Flag<["--"], "no-color-diagnostics">, Alias<color_diagnostics>, AliasArgs<["never"]>,
+ HelpText<"Alias for --color-diagnostics=never">;
def cref: FF<"cref">,
HelpText<"Output cross reference table. If -Map is specified, print to the map file">;
More information about the llvm-commits
mailing list