forked from OSchip/llvm-project
[flang][driver] Refactor boolean options
For boolean options, e.g. `-fxor-operator`/`-fno-xor-operator`, we ought to be using TableGen multi-classes. This way, we only have to write one definition to have both forms auto-generated. This patch refactors all of Flang's boolean options to use two new multi-classes: `OptInFC1FFOption` and `OptOutFC1FFOption`. These multi-classes are based on `OptInFFOption`/`OptOutFFOption`, respectively. I've also simplified the processing of the updated options in CompilerInvocation.cpp. With the new approach, "empty" help text (i.e. no `HelpText`) is now replaced with an empty string (i.e. HelpText<"">). When running flang-new --help, that's considered as non-empty help messages, which is then printed (that's controlled by `printHelp` from llvm/lib/Option/OptTable.cpp). This means that with this patch, flang-new --help will start printing e.g. -fno-backslash, even though there is no actual help text to print for this option (apart from the empty string ""). Tests are updated accordingly. Note that with this patch, both `-fxor-operator` and `-fno-xor-operator` (and other boolean options refactored here) remain available in `flang-new` and `flang-new -fc1`. In this respect, nothing changes. In a forthcoming patch, I will refine this so that `flang-new -fc1` only accepts `-ffoo` (`OptInFC1FFOption`) or `-fno-foo` (`OptOutCC1FFOption`). For clarity, `OptInFFOption`/`OptOutFFOption` are renamed as `OptInCC1FFOption`/`OptOutCC1FFOption`, respectively. Otherwise, this is an NFC from Clang's perspective. Differential Revision: https://reviews.llvm.org/D105881
This commit is contained in:
parent
92b00ffe0f
commit
55a9615599
|
@ -272,7 +272,7 @@ class MigratorOpts<string base>
|
|||
// Args.hasArg(OPT_ffoo) can be used to check that the flag is enabled.
|
||||
// This is useful if the option is usually disabled.
|
||||
// Use this only when the option cannot be declared via BoolFOption.
|
||||
multiclass OptInFFlag<string name, string pos_prefix, string neg_prefix="",
|
||||
multiclass OptInCC1FFlag<string name, string pos_prefix, string neg_prefix="",
|
||||
string help="", list<OptionFlag> flags=[]> {
|
||||
def f#NAME : Flag<["-"], "f"#name>, Flags<[CC1Option] # flags>,
|
||||
Group<f_Group>, HelpText<pos_prefix # help>;
|
||||
|
@ -283,7 +283,7 @@ multiclass OptInFFlag<string name, string pos_prefix, string neg_prefix="",
|
|||
// A boolean option which is opt-out in CC1. The negative option exists in CC1 and
|
||||
// Args.hasArg(OPT_fno_foo) can be used to check that the flag is disabled.
|
||||
// Use this only when the option cannot be declared via BoolFOption.
|
||||
multiclass OptOutFFlag<string name, string pos_prefix, string neg_prefix,
|
||||
multiclass OptOutCC1FFlag<string name, string pos_prefix, string neg_prefix,
|
||||
string help="", list<OptionFlag> flags=[]> {
|
||||
def f#NAME : Flag<["-"], "f"#name>, Flags<flags>,
|
||||
Group<f_Group>, HelpText<pos_prefix # help>;
|
||||
|
@ -291,6 +291,27 @@ multiclass OptOutFFlag<string name, string pos_prefix, string neg_prefix,
|
|||
Group<f_Group>, HelpText<neg_prefix # help>;
|
||||
}
|
||||
|
||||
// A boolean option which is opt-in in FC1. The positive option exists in FC1 and
|
||||
// Args.hasArg(OPT_ffoo) can be used to check that the flag is enabled.
|
||||
// This is useful if the option is usually disabled.
|
||||
multiclass OptInFC1FFlag<string name, string pos_prefix, string neg_prefix="",
|
||||
string help="", list<OptionFlag> flags=[]> {
|
||||
def f#NAME : Flag<["-"], "f"#name>, Flags<[FC1Option] # flags>,
|
||||
Group<f_Group>, HelpText<pos_prefix # help>;
|
||||
def fno_#NAME : Flag<["-"], "fno-"#name>, Flags<flags>,
|
||||
Group<f_Group>, HelpText<neg_prefix # help>;
|
||||
}
|
||||
|
||||
// A boolean option which is opt-out in FC1. The negative option exists in FC1 and
|
||||
// Args.hasArg(OPT_fno_foo) can be used to check that the flag is disabled.
|
||||
multiclass OptOutFC1FFlag<string name, string pos_prefix, string neg_prefix,
|
||||
string help="", list<OptionFlag> flags=[]> {
|
||||
def f#NAME : Flag<["-"], "f"#name>, Flags<flags>,
|
||||
Group<f_Group>, HelpText<pos_prefix # help>;
|
||||
def fno_#NAME : Flag<["-"], "fno-"#name>, Flags<[FC1Option] # flags>,
|
||||
Group<f_Group>, HelpText<neg_prefix # help>;
|
||||
}
|
||||
|
||||
// Creates a positive and negative flags where both of them are prefixed with
|
||||
// "m", have help text specified for positive and negative option, and a Group
|
||||
// optionally specified by the opt_group argument, otherwise Group<m_Group>.
|
||||
|
@ -1257,7 +1278,7 @@ defm addrsig : BoolFOption<"addrsig",
|
|||
CodeGenOpts<"Addrsig">, DefaultFalse,
|
||||
PosFlag<SetTrue, [CC1Option], "Emit">, NegFlag<SetFalse, [], "Don't emit">,
|
||||
BothFlags<[CoreOption], " an address-significance table">>;
|
||||
defm blocks : OptInFFlag<"blocks", "Enable the 'blocks' language feature", "", "", [CoreOption]>;
|
||||
defm blocks : OptInCC1FFlag<"blocks", "Enable the 'blocks' language feature", "", "", [CoreOption]>;
|
||||
def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group<f_Group>;
|
||||
defm borland_extensions : BoolFOption<"borland-extensions",
|
||||
LangOpts<"Borland">, DefaultFalse,
|
||||
|
@ -1273,7 +1294,7 @@ def fclang_abi_compat_EQ : Joined<["-"], "fclang-abi-compat=">, Group<f_clang_Gr
|
|||
Flags<[CC1Option]>, MetaVarName<"<version>">, Values<"<major>.<minor>,latest">,
|
||||
HelpText<"Attempt to match the ABI of Clang <version>">;
|
||||
def fclasspath_EQ : Joined<["-"], "fclasspath=">, Group<f_Group>;
|
||||
defm color_diagnostics : OptInFFlag<"color-diagnostics", "Enable", "Disable", " colors in diagnostics",
|
||||
defm color_diagnostics : OptInCC1FFlag<"color-diagnostics", "Enable", "Disable", " colors in diagnostics",
|
||||
[CoreOption, FlangOption]>;
|
||||
def fdiagnostics_color : Flag<["-"], "fdiagnostics-color">, Group<f_Group>,
|
||||
Flags<[CoreOption, NoXarchOption]>;
|
||||
|
@ -1394,7 +1415,7 @@ def fno_elide_type : Flag<["-"], "fno-elide-type">, Group<f_Group>,
|
|||
HelpText<"Do not elide types when printing diagnostics">,
|
||||
MarshallingInfoNegativeFlag<DiagnosticOpts<"ElideType">>;
|
||||
def feliminate_unused_debug_symbols : Flag<["-"], "feliminate-unused-debug-symbols">, Group<f_Group>;
|
||||
defm eliminate_unused_debug_types : OptOutFFlag<"eliminate-unused-debug-types",
|
||||
defm eliminate_unused_debug_types : OptOutCC1FFlag<"eliminate-unused-debug-types",
|
||||
"Do not emit ", "Emit ", " debug info for defined but unused types">;
|
||||
def femit_all_decls : Flag<["-"], "femit-all-decls">, Group<f_Group>, Flags<[CC1Option]>,
|
||||
HelpText<"Emit all declarations, even if unused">,
|
||||
|
@ -1499,7 +1520,7 @@ defm cxx_static_destructors : BoolFOption<"c++-static-destructors",
|
|||
def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>,
|
||||
Flags<[CC1Option]>, MarshallingInfoString<CodeGenOpts<"SymbolPartition">>;
|
||||
|
||||
defm memory_profile : OptInFFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">;
|
||||
defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">;
|
||||
def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
|
||||
Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<directory>">,
|
||||
HelpText<"Enable heap memory profiling and dump results into <directory>">;
|
||||
|
@ -2143,9 +2164,9 @@ defm pch_instantiate_templates : BoolFOption<"pch-instantiate-templates",
|
|||
LangOpts<"PCHInstantiateTemplates">, DefaultFalse,
|
||||
PosFlag<SetTrue, [], "Instantiate templates already while building a PCH">,
|
||||
NegFlag<SetFalse>, BothFlags<[CC1Option, CoreOption]>>;
|
||||
defm pch_codegen: OptInFFlag<"pch-codegen", "Generate ", "Do not generate ",
|
||||
defm pch_codegen: OptInCC1FFlag<"pch-codegen", "Generate ", "Do not generate ",
|
||||
"code for uses of this PCH that assumes an explicit object file will be built for the PCH">;
|
||||
defm pch_debuginfo: OptInFFlag<"pch-debuginfo", "Generate ", "Do not generate ",
|
||||
defm pch_debuginfo: OptInCC1FFlag<"pch-debuginfo", "Generate ", "Do not generate ",
|
||||
"debug info for types in an object file built from this PCH and do not generate them elsewhere">;
|
||||
|
||||
def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, Group<f_Group>,
|
||||
|
@ -4509,26 +4530,18 @@ def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group<f_Group>,
|
|||
HelpText<"Set the default real kind to an 8 byte wide type">;
|
||||
def flarge_sizes : Flag<["-"],"flarge-sizes">, Group<f_Group>,
|
||||
HelpText<"Use INTEGER(KIND=8) for the result type in size-related intrinsics">;
|
||||
def fbackslash : Flag<["-"], "fbackslash">, Group<f_Group>,
|
||||
HelpText<"Specify that backslash in string introduces an escape character">,
|
||||
DocBrief<[{Change the interpretation of backslashes in string literals from
|
||||
a single backslash character to "C-style" escape characters.}]>;
|
||||
def fno_backslash : Flag<["-"], "fno-backslash">, Group<f_Group>;
|
||||
def fxor_operator : Flag<["-"], "fxor-operator">, Group<f_Group>,
|
||||
HelpText<"Enable .XOR. as a synonym of .NEQV.">;
|
||||
def fno_xor_operator : Flag<["-"], "fno-xor-operator">, Group<f_Group>;
|
||||
def flogical_abbreviations : Flag<["-"], "flogical-abbreviations">, Group<f_Group>,
|
||||
HelpText<"Enable logical abbreviations">;
|
||||
def fno_logical_abbreviations : Flag<["-"], "fno-logical-abbreviations">, Group<f_Group>;
|
||||
def fimplicit_none : Flag<["-"], "fimplicit-none">, Group<f_Group>,
|
||||
HelpText<"No implicit typing allowed unless overridden by IMPLICIT statements">;
|
||||
def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group<f_Group>;
|
||||
|
||||
def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group<f_Group>,
|
||||
HelpText<"Enable the old style PARAMETER statement">;
|
||||
def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">, Group<f_Group>, MetaVarName<"<dir>">,
|
||||
HelpText<"Specify where to find the compiled intrinsic modules">,
|
||||
DocBrief<[{This option specifies the location of pre-compiled intrinsic modules,
|
||||
if they are not in the default location expected by the compiler.}]>;
|
||||
|
||||
defm backslash : OptInFC1FFlag<"backslash", "Specify that backslash in string introduces an escape character">;
|
||||
defm xor_operator : OptInFC1FFlag<"xor-operator", "Enable .XOR. as a synonym of .NEQV.">;
|
||||
defm logical_abbreviations : OptInFC1FFlag<"logical-abbreviations", "Enable logical abbreviations">;
|
||||
defm implicit_none : OptInFC1FFlag<"implicit-none", "No implicit typing allowed unless overridden by IMPLICIT statements">;
|
||||
}
|
||||
|
||||
def J : JoinedOrSeparate<["-"], "J">,
|
||||
|
@ -4583,13 +4596,10 @@ def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group<Action_Gro
|
|||
|
||||
def module_suffix : Separate<["-"], "module-suffix">, Group<f_Group>, MetaVarName<"<suffix>">,
|
||||
HelpText<"Use <suffix> as the suffix for module files (the default value is `.mod`)">;
|
||||
def fanalyzed_objects_for_unparse : Flag<["-"],
|
||||
"fanalyzed-objects-for-unparse">, Group<f_Group>;
|
||||
def fno_analyzed_objects_for_unparse : Flag<["-"],
|
||||
"fno-analyzed-objects-for-unparse">, Group<f_Group>,
|
||||
HelpText<"Do not use the analyzed objects when unparsing">;
|
||||
def fno_reformat : Flag<["-"], "fno-reformat">, Group<Preprocessor_Group>,
|
||||
HelpText<"Dump the cooked character stream in -E mode">;
|
||||
defm analyzed_objects_for_unparse : OptOutFC1FFlag<"analyzed-objects-for-unparse", "", "Do not use the analyzed objects when unparsing">;
|
||||
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -277,32 +277,27 @@ static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
|
|||
}
|
||||
}
|
||||
|
||||
if (const llvm::opt::Arg *arg =
|
||||
args.getLastArg(clang::driver::options::OPT_fimplicit_none,
|
||||
clang::driver::options::OPT_fno_implicit_none)) {
|
||||
opts.features.Enable(
|
||||
Fortran::common::LanguageFeature::ImplicitNoneTypeAlways,
|
||||
arg->getOption().matches(clang::driver::options::OPT_fimplicit_none));
|
||||
}
|
||||
if (const llvm::opt::Arg *arg =
|
||||
args.getLastArg(clang::driver::options::OPT_fbackslash,
|
||||
clang::driver::options::OPT_fno_backslash)) {
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes,
|
||||
arg->getOption().matches(clang::driver::options::OPT_fbackslash));
|
||||
}
|
||||
if (const llvm::opt::Arg *arg =
|
||||
args.getLastArg(clang::driver::options::OPT_flogical_abbreviations,
|
||||
clang::driver::options::OPT_fno_logical_abbreviations)) {
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::LogicalAbbreviations,
|
||||
arg->getOption().matches(
|
||||
clang::driver::options::OPT_flogical_abbreviations));
|
||||
}
|
||||
if (const llvm::opt::Arg *arg =
|
||||
args.getLastArg(clang::driver::options::OPT_fxor_operator,
|
||||
clang::driver::options::OPT_fno_xor_operator)) {
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::XOROperator,
|
||||
arg->getOption().matches(clang::driver::options::OPT_fxor_operator));
|
||||
}
|
||||
// -f{no-}implicit-none
|
||||
opts.features.Enable(
|
||||
Fortran::common::LanguageFeature::ImplicitNoneTypeAlways,
|
||||
args.hasFlag(clang::driver::options::OPT_fimplicit_none,
|
||||
clang::driver::options::OPT_fno_implicit_none, false));
|
||||
|
||||
// -f{no-}backslash
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes,
|
||||
args.hasFlag(clang::driver::options::OPT_fbackslash,
|
||||
clang::driver::options::OPT_fno_backslash, false));
|
||||
|
||||
// -f{no-}logical-abbreviations
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::LogicalAbbreviations,
|
||||
args.hasFlag(clang::driver::options::OPT_flogical_abbreviations,
|
||||
clang::driver::options::OPT_fno_logical_abbreviations, false));
|
||||
|
||||
// -f{no-}xor-operator
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::XOROperator,
|
||||
args.hasFlag(clang::driver::options::OPT_fxor_operator,
|
||||
clang::driver::options::OPT_fno_xor_operator, false));
|
||||
|
||||
if (args.hasArg(
|
||||
clang::driver::options::OPT_falternative_parameter_statement)) {
|
||||
opts.features.Enable(Fortran::common::LanguageFeature::OldStyleParameter);
|
||||
|
@ -406,11 +401,10 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
|
|||
res.SetModuleFileSuffix(moduleSuffix->getValue());
|
||||
}
|
||||
|
||||
// -fno-analyzed-objects-for-unparse
|
||||
if (args.hasArg(
|
||||
clang::driver::options::OPT_fno_analyzed_objects_for_unparse)) {
|
||||
res.SetUseAnalyzedObjectsForUnparse(false);
|
||||
}
|
||||
// -f{no-}analyzed-objects-for-unparse
|
||||
res.SetUseAnalyzedObjectsForUnparse(
|
||||
args.hasFlag(clang::driver::options::OPT_fanalyzed_objects_for_unparse,
|
||||
clang::driver::options::OPT_fno_analyzed_objects_for_unparse, true));
|
||||
|
||||
return diags.getNumErrors() == numErrorsBefore;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,12 @@
|
|||
! CHECK-NEXT: Specify where to find the compiled intrinsic modules
|
||||
! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics
|
||||
! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
|
||||
! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
|
||||
! CHECK-NEXT: -fno-backslash
|
||||
! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
|
||||
! CHECK-NEXT: -fno-implicit-none
|
||||
! CHECK-NEXT: -fno-logical-abbreviations
|
||||
! CHECK-NEXT: {{[[:space:]]$}}
|
||||
! CHECK-NEXT: -fno-xor-operator
|
||||
! CHECK-NEXT: -fopenacc Enable OpenACC
|
||||
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
|
||||
! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
|
||||
|
|
|
@ -40,7 +40,12 @@
|
|||
! HELP-NEXT: Specify where to find the compiled intrinsic modules
|
||||
! HELP-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics
|
||||
! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
|
||||
! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
|
||||
! HELP-NEXT: -fno-backslash
|
||||
! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
|
||||
! HELP-NEXT: -fno-implicit-none
|
||||
! HELP-NEXT: -fno-logical-abbreviations
|
||||
! HELP-NEXT: {{[[:space:]]$}}
|
||||
! HELP-NEXT: -fno-xor-operator
|
||||
! HELP-NEXT: -fopenacc Enable OpenACC
|
||||
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
|
||||
! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
|
||||
|
@ -69,6 +74,8 @@
|
|||
! HELP-FC1-NEXT: -E Only run the preprocessor
|
||||
! HELP-FC1-NEXT: -falternative-parameter-statement
|
||||
! HELP-FC1-NEXT: Enable the old style PARAMETER statement
|
||||
! HELP-FC1-NEXT: -fanalyzed-objects-for-unparse
|
||||
! HELP-FC1-NEXT: {{[[:space:]]$}}
|
||||
! HELP-FC1-NEXT: -fbackslash Specify that backslash in string introduces an escape character
|
||||
! HELP-FC1-NEXT: -fdebug-dump-all Dump symbols and the parse tree after the semantic checks
|
||||
! HELP-FC1-NEXT: -fdebug-dump-parse-tree-no-sema
|
||||
|
@ -104,7 +111,12 @@
|
|||
! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
|
||||
! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse
|
||||
! HELP-FC1-NEXT: Do not use the analyzed objects when unparsing
|
||||
! HELP-FC1-NEXT: -fno-backslash
|
||||
! HELP-FC1-NEXT: -fno-implicit-none
|
||||
! HELP-FC1-NEXT: -fno-logical-abbreviations
|
||||
! HELP-FC1-NEXT: {{[[:space:]]$}}
|
||||
! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode
|
||||
! HELP-FC1-NEXT: -fno-xor-operator
|
||||
! HELP-FC1-NEXT: -fopenacc Enable OpenACC
|
||||
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
|
||||
! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
|
||||
|
|
Loading…
Reference in New Issue