From d40a0b8af771f9b37dd2985fc692443c0ac5473e Mon Sep 17 00:00:00 2001 From: "Paul C. Anagnostopoulos" Date: Wed, 28 Apr 2021 19:55:12 -0400 Subject: [PATCH] [TableGen] [Clang] Clean up Options.td and add asserts. Differential Revision: https://reviews.llvm.org/D101766 --- clang/include/clang/Driver/Options.td | 47 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b17eb50..78cc0a4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -274,10 +274,10 @@ class MigratorOpts // Use this only when the option cannot be declared via BoolFOption. multiclass OptInFFlag flags=[]> { - def f#NAME : Flag<["-"], "f"#name>, Flags, - Group, HelpText; + def f#NAME : Flag<["-"], "f"#name>, Flags<[CC1Option] # flags>, + Group, HelpText; def fno_#NAME : Flag<["-"], "fno-"#name>, Flags, - Group, HelpText; + Group, HelpText; } // A boolean option which is opt-out in CC1. The negative option exists in CC1 and @@ -286,9 +286,9 @@ multiclass OptInFFlag flags=[]> { def f#NAME : Flag<["-"], "f"#name>, Flags, - Group, HelpText; - def fno_#NAME : Flag<["-"], "fno-"#name>, Flags, - Group, HelpText; + Group, HelpText; + def fno_#NAME : Flag<["-"], "fno-"#name>, Flags<[CC1Option] # flags>, + Group, HelpText; } // Creates a positive and negative flags where both of them are prefixed with @@ -297,9 +297,9 @@ multiclass OptOutFFlag { def m#NAME : Flag<["-"], "m"#name>, Group, - HelpText; + HelpText; def mno_#NAME : Flag<["-"], "mno-"#name>, Group, - HelpText; + HelpText; } //===----------------------------------------------------------------------===// @@ -349,8 +349,8 @@ class BothFlags option_flags, string help = ""> { class ApplySuffix { FlagDef Result = FlagDef; + flag.OptionFlags # suffix.OptionFlags, + flag.Help # suffix.Help, flag.ImpliedBy>; } // Definition of the command line flag with positive spelling, e.g. "-ffoo". @@ -368,16 +368,16 @@ class FlagDefExpanded : FlagDef { // Name of the TableGen record. - string RecordName = prefix#!cond(flag.Polarity : "", true : "no_")#name; + string RecordName = prefix # !if(flag.Polarity, "", "no_") # name; // Spelling of the flag. - string Spelling = prefix#!cond(flag.Polarity : "", true : "no-")#spelling; + string Spelling = prefix # !if(flag.Polarity, "", "no-") # spelling; // Can the flag be implied by another flag? bit CanBeImplied = !not(!empty(flag.ImpliedBy)); // C++ code that will be assigned to the keypath when the flag is present. - code ValueAsCode = !cond(flag.Value : "true", true: "false"); + code ValueAsCode = !if(flag.Value, "true", "false"); } // TableGen record for a single marshalled flag. @@ -406,11 +406,19 @@ multiclass BoolOption.Result, prefix, NAME, spelling_base>; - // TODO: Assert that the flags have different polarity. - // TODO: Assert that the flags have different value. - // TODO: Assert that only one of the flags can be implied. + // The flags must have different polarity, different values, and only + // one can be implied. + assert !xor(flag1.Polarity, flag2.Polarity), + "the flags must have different polarity: flag1: " # + flag1.Polarity # ", flag2: " # flag2.Polarity; + assert !ne(flag1.Value, flag2.Value), + "the flags must have different values: flag1: " # + flag1.Value # ", flag2: " # flag2.Value; + assert !not(!and(flag1.CanBeImplied, flag2.CanBeImplied)), + "only one of the flags can be implied: flag1: " # + flag1.CanBeImplied # ", flag2: " # flag2.CanBeImplied; - defvar implied = !cond(flag1.CanBeImplied: flag1, true: flag2); + defvar implied = !if(flag1.CanBeImplied, flag1, flag2); def flag1.RecordName : MarshalledFlagRec; def flag2.RecordName : MarshalledFlagRec; @@ -1921,8 +1929,9 @@ def flax_vector_conversions_EQ : Joined<["-"], "flax-vector-conversions=">, Grou "LangOptions::LaxVectorConversionKind::Integer", "LangOptions::LaxVectorConversionKind::All"]>, MarshallingInfoEnum, - !strconcat(open_cl.KeyPath, " ? LangOptions::LaxVectorConversionKind::None" - " : LangOptions::LaxVectorConversionKind::All")>; + open_cl.KeyPath # + " ? LangOptions::LaxVectorConversionKind::None" # + " : LangOptions::LaxVectorConversionKind::All">; def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group, Alias, AliasArgs<["integer"]>; def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group; -- 2.7.4