diff --git a/include/llvm/Option/OptParser.td b/include/llvm/Option/OptParser.td index ea94abdff40..67fda9112ac 100644 --- a/include/llvm/Option/OptParser.td +++ b/include/llvm/Option/OptParser.td @@ -100,6 +100,8 @@ class Option prefixes, string name, OptionKind kind> { string MarshallingInfoKind = ?; code KeyPath = ?; code DefaultValue = ?; + code ImpliedValue = ?; + code ImpliedCheck = "false"; bit ShouldAlwaysEmit = false; code NormalizerRetTy = ?; code NormalizedValuesScope = ""; @@ -145,9 +147,10 @@ class ValuesCode { code ValuesCode = valuecode; } // Helpers for defining marshalling information. -class DefaultAnyOf options, string default = "false", string separator = " || "> { - code DefaultValue = !foldl(default, options, accumulator, option, - !strconcat(accumulator, separator, !cast(option.KeyPath))); +class ImpliedByAnyOf options, code value = "true"> { + code ImpliedCheck = !foldl("false", options, accumulator, option, + !strconcat(accumulator, " || ", !cast(option.KeyPath))); + code ImpliedValue = value; } class MarshallingInfo { @@ -159,21 +162,21 @@ class MarshallingInfo { class MarshallingInfoString : MarshallingInfo {} -class MarshallingInfoFlag> - : MarshallingInfo { +class MarshallingInfoFlag + : MarshallingInfo { code Normalizer = "normalizeSimpleFlag"; code Denormalizer = "denormalizeSimpleFlag"; } class MarshallingInfoBitfieldFlag - : MarshallingInfoFlag> { + : MarshallingInfoFlag { code Normalizer = "(normalizeFlagToValue)"; code ValueMerger = "mergeMaskValue"; code ValueExtractor = "(extractMaskValue)"; } class MarshallingInfoBooleanFlag - : MarshallingInfoFlag> { + : MarshallingInfoFlag { bit ShouldAlwaysEmit = 1; string MarshallingInfoKind = "BooleanFlag"; code Normalizer = "normalizeBooleanFlag"; diff --git a/unittests/Option/OptionMarshallingTest.cpp b/unittests/Option/OptionMarshallingTest.cpp index 4b53d047be8..71fb807b925 100644 --- a/unittests/Option/OptionMarshallingTest.cpp +++ b/unittests/Option/OptionMarshallingTest.cpp @@ -11,15 +11,17 @@ struct OptionWithMarshallingInfo { const char *Name; const char *KeyPath; - const char *DefaultValue; + const char *ImpliedCheck; + const char *ImpliedValue; }; static const OptionWithMarshallingInfo MarshallingTable[] = { #define OPTION_WITH_MARSHALLING( \ PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \ - NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \ - {NAME, #KEYPATH, #DEFAULT_VALUE}, + IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, \ + TABLE_INDEX) \ + {NAME, #KEYPATH, #IMPLIED_CHECK, #IMPLIED_VALUE}, #include "Opts.inc" #undef OPTION_WITH_MARSHALLING }; @@ -38,10 +40,16 @@ TEST(OptionMarshalling, EmittedSpecifiedKeyPath) { ASSERT_STREQ(MarshallingTable[3].KeyPath, "MarshalledFlagA"); } -TEST(OptionMarshalling, DefaultAnyOfConstructedDisjunctionOfKeypaths) { - ASSERT_STREQ(MarshallingTable[0].DefaultValue, "false"); - ASSERT_STREQ(MarshallingTable[1].DefaultValue, "false || MarshalledFlagD"); - ASSERT_STREQ(MarshallingTable[2].DefaultValue, "false || MarshalledFlagD"); - ASSERT_STREQ(MarshallingTable[3].DefaultValue, - "false || MarshalledFlagC || MarshalledFlagB"); +TEST(OptionMarshalling, ImpliedCheckContainsDisjunctionOfKeypaths) { + ASSERT_STREQ(MarshallingTable[0].ImpliedCheck, "false"); + + ASSERT_STREQ(MarshallingTable[1].ImpliedCheck, "false || MarshalledFlagD"); + ASSERT_STREQ(MarshallingTable[1].ImpliedValue, "true"); + + ASSERT_STREQ(MarshallingTable[2].ImpliedCheck, "false || MarshalledFlagD"); + ASSERT_STREQ(MarshallingTable[2].ImpliedValue, "true"); + + ASSERT_STREQ(MarshallingTable[3].ImpliedCheck, + "false || MarshalledFlagC || MarshalledFlagB"); + ASSERT_STREQ(MarshallingTable[3].ImpliedValue, "true"); } diff --git a/unittests/Option/Opts.td b/unittests/Option/Opts.td index 62cd6151ea9..01275a96420 100644 --- a/unittests/Option/Opts.td +++ b/unittests/Option/Opts.td @@ -46,10 +46,13 @@ def Blurmpq_eq : Flag<["--"], "blurmp=">; def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>; def marshalled_flag_d : Flag<["-"], "marshalled-flag-d">, - MarshallingInfoFlag<"MarshalledFlagD", DefaultAnyOf<[]>>; + MarshallingInfoFlag<"MarshalledFlagD">; def marshalled_flag_c : Flag<["-"], "marshalled-flag-c">, - MarshallingInfoFlag<"MarshalledFlagC", DefaultAnyOf<[marshalled_flag_d]>>; + MarshallingInfoFlag<"MarshalledFlagC">, + ImpliedByAnyOf<[marshalled_flag_d], "true">; def marshalled_flag_b : Flag<["-"], "marshalled-flag-b">, - MarshallingInfoFlag<"MarshalledFlagB", DefaultAnyOf<[marshalled_flag_d]>>; + MarshallingInfoFlag<"MarshalledFlagB">, + ImpliedByAnyOf<[marshalled_flag_d], "true">; def marshalled_flag_a : Flag<["-"], "marshalled-flag-a">, - MarshallingInfoFlag<"MarshalledFlagA", DefaultAnyOf<[marshalled_flag_c, marshalled_flag_b]>>; + MarshallingInfoFlag<"MarshalledFlagA">, + ImpliedByAnyOf<[marshalled_flag_c, marshalled_flag_b]>; diff --git a/utils/TableGen/OptParserEmitter.cpp b/utils/TableGen/OptParserEmitter.cpp index 91d9aeb104f..edbe6663057 100644 --- a/utils/TableGen/OptParserEmitter.cpp +++ b/utils/TableGen/OptParserEmitter.cpp @@ -71,6 +71,8 @@ public: StringRef KeyPath; StringRef DefaultValue; StringRef NormalizedValuesScope; + StringRef ImpliedCheck; + StringRef ImpliedValue; StringRef Normalizer; StringRef Denormalizer; StringRef ValueMerger; @@ -113,6 +115,10 @@ struct SimpleEnumValueTable { OS << ", "; emitScopedNormalizedValue(OS, DefaultValue); OS << ", "; + OS << ImpliedCheck; + OS << ", "; + emitScopedNormalizedValue(OS, ImpliedValue); + OS << ", "; OS << Normalizer; OS << ", "; OS << Denormalizer; @@ -188,6 +194,9 @@ static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) { Ret->KeyPath = R.getValueAsString("KeyPath"); Ret->DefaultValue = R.getValueAsString("DefaultValue"); Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope"); + Ret->ImpliedCheck = R.getValueAsString("ImpliedCheck"); + Ret->ImpliedValue = + R.getValueAsOptionalString("ImpliedValue").getValueOr(Ret->DefaultValue); Ret->Normalizer = R.getValueAsString("Normalizer"); Ret->Denormalizer = R.getValueAsString("Denormalizer");