[clang] 7694b57 - [Driver] Add multiclass OptInFlag and OptOutFlag to simplify boolean option definition
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 2 13:22:21 PDT 2020
Author: Fangrui Song
Date: 2020-06-02T13:22:12-07:00
New Revision: 7694b571d9fd6a8a6c96af1e7995068f7066f6f1
URL: https://github.com/llvm/llvm-project/commit/7694b571d9fd6a8a6c96af1e7995068f7066f6f1
DIFF: https://github.com/llvm/llvm-project/commit/7694b571d9fd6a8a6c96af1e7995068f7066f6f1.diff
LOG: [Driver] Add multiclass OptInFlag and OptOutFlag to simplify boolean option definition
Reviewed By: dblaikie, echristo
Differential Revision: https://reviews.llvm.org/D80883
Added:
Modified:
clang/include/clang/Driver/Options.td
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 3a5f75660421..b807febe1d44 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -66,6 +66,26 @@ class DocFlatten { bit DocFlatten = 1; }
// GCC compatibility.
class IgnoredGCCCompat : Flags<[HelpHidden]> {}
+// A boolean option which is opt-in in CC1. The positive option exists in CC1 and
+// Args.hasArg(OPT_ffoo) is used to check that the flag is enabled.
+// This is useful if the option is usually disabled.
+multiclass OptInFFlag<string name, string pos_prefix, string neg_prefix,
+ string help, list<OptionFlag> flags=[]> {
+ def f#NAME : Flag<["-"], "f"#name>, Flags<!listconcat([CC1Option], flags)>,
+ HelpText<!strconcat(pos_prefix, help)>;
+ def fno_#NAME : Flag<["-"], "fno-"#name>, Flags<flags>,
+ HelpText<!strconcat(neg_prefix, help)>;
+}
+
+// A boolean option which is opt-out in CC1. The negative option exists in CC1 and
+// Args.hasArg(OPT_fno_foo) is used to check that the flag is disabled.
+multiclass OptOutFFlag<string name, string pos_prefix, string neg_prefix,
+ string help, list<OptionFlag> flags=[]> {
+ def f#NAME : Flag<["-"], "f"#name>, Flags<flags>, HelpText<!strconcat(pos_prefix, help)>;
+ def fno_ #NAME : Flag<["-"], "fno-"#name>, Flags<!listconcat([CC1Option], flags)>,
+ HelpText<!strconcat(neg_prefix, help)>;
+}
+
/////////
// Groups
@@ -824,10 +844,7 @@ def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
-def faddrsig : Flag<["-"], "faddrsig">, Group<f_Group>, Flags<[CoreOption, CC1Option]>,
- HelpText<"Emit an address-significance table">;
-def fno_addrsig : Flag<["-"], "fno-addrsig">, Group<f_Group>, Flags<[CoreOption]>,
- HelpText<"Don't emit an address-significance table">;
+defm addrsig : OptInFFlag<"addrsig", "Emit", "Don't emit", " an address-significance table", [CoreOption]>;
def fblocks : Flag<["-"], "fblocks">, Group<f_Group>, Flags<[CoreOption, CC1Option]>,
HelpText<"Enable the 'blocks' language feature">;
def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group<f_Group>;
@@ -969,15 +986,8 @@ def fno_math_errno : Flag<["-"], "fno-math-errno">, Group<f_Group>;
def fbracket_depth_EQ : Joined<["-"], "fbracket-depth=">, Group<f_Group>, Flags<[CoreOption]>;
def fsignaling_math : Flag<["-"], "fsignaling-math">, Group<f_Group>;
def fno_signaling_math : Flag<["-"], "fno-signaling-math">, Group<f_Group>;
-def fjump_tables : Flag<["-"], "fjump-tables">, Group<f_Group>;
-def fno_jump_tables : Flag<["-"], "fno-jump-tables">, Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"Do not use jump tables for lowering switches">;
-def fforce_enable_int128 : Flag<["-"], "fforce-enable-int128">,
- Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"Enable support for int128_t type">;
-def fno_force_enable_int128 : Flag<["-"], "fno-force-enable-int128">,
- Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"Disable support for int128_t type">;
+defm jump_tables : OptOutFFlag<"jump-tables", "Use", "Do not use", " jump tables for lowering switches">;
+defm force_enable_int128 : OptInFFlag<"force-enable-int128", "Enable", "Disable", " support for int128_t type">;
def fkeep_static_consts : Flag<["-"], "fkeep-static-consts">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Keep static const variables even if unused">;
def ffixed_point : Flag<["-"], "ffixed-point">, Group<f_Group>,
More information about the cfe-commits
mailing list