diff options
Diffstat (limited to 'llvm')
27 files changed, 173 insertions, 145 deletions
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index 09c61884..6f23de9 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -74,12 +74,12 @@ namespace llvm { : Data(&OneElt), Length(1) {} /// Construct an ArrayRef from a pointer and length. - /*implicit*/ ArrayRef(const T *data, size_t length) - : Data(data), Length(length) {} + constexpr /*implicit*/ ArrayRef(const T *data, size_t length) + : Data(data), Length(length) {} /// Construct an ArrayRef from a range. - ArrayRef(const T *begin, const T *end) - : Data(begin), Length(end - begin) {} + constexpr ArrayRef(const T *begin, const T *end) + : Data(begin), Length(end - begin) {} /// Construct an ArrayRef from a SmallVector. This is templated in order to /// avoid instantiating SmallVectorTemplateCommon<T> whenever we @@ -111,9 +111,9 @@ namespace llvm { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winit-list-lifetime" #endif - /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec) - : Data(Vec.begin() == Vec.end() ? (T*)nullptr : Vec.begin()), - Length(Vec.size()) {} + constexpr /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec) + : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()), + Length(Vec.size()) {} #if LLVM_GNUC_PREREQ(9, 0, 0) #pragma GCC diagnostic pop #endif diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h index 10d67b1..52354eb 100644 --- a/llvm/include/llvm/Option/OptTable.h +++ b/llvm/include/llvm/Option/OptTable.h @@ -44,7 +44,7 @@ public: struct Info { /// A null terminated array of prefix strings to apply to name while /// matching. - const char *const *Prefixes; + ArrayRef<StringLiteral> Prefixes; StringRef Name; const char *HelpText; const char *MetaVar; diff --git a/llvm/include/llvm/Option/Option.h b/llvm/include/llvm/Option/Option.h index 106f686..9b35e81 100644 --- a/llvm/include/llvm/Option/Option.h +++ b/llvm/include/llvm/Option/Option.h @@ -124,8 +124,9 @@ public: /// Get the default prefix for this option. StringRef getPrefix() const { - const char *Prefix = *Info->Prefixes; - return Prefix ? Prefix : StringRef(); + return Info->Prefixes.empty() + ? StringRef() + : static_cast<const StringRef &>(Info->Prefixes[0]); } /// Get the name of this option with the default prefix. diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp b/llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp index 8c1c7e2..10ed8a7 100644 --- a/llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp @@ -12,18 +12,21 @@ #include "COFFDirectiveParser.h" +#include <array> + using namespace llvm; using namespace jitlink; #define DEBUG_TYPE "jitlink" // Create prefix string literals used in Options.td -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "COFFOptions.inc" #undef PREFIX // Create table mapping all options defined in COFFOptions.td -static constexpr opt::OptTable::Info infoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> infoTable = { #define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \ {X1, \ X2, \ diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 786760f..c21072b 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -62,12 +62,10 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { if (int N = StrCmpOptionName(A.Name, B.Name)) return N < 0; - for (const char * const *APre = A.Prefixes, - * const *BPre = B.Prefixes; - *APre != nullptr && *BPre != nullptr; ++APre, ++BPre){ - if (int N = StrCmpOptionName(*APre, *BPre)) + for (size_t I = 0, K = std::min(A.Prefixes.size(), B.Prefixes.size()); I != K; + ++I) + if (int N = StrCmpOptionName(A.Prefixes[I], B.Prefixes[I])) return N < 0; - } // Names are the same, check that classes are in order; exactly one // should be joined, and it should succeed the other. @@ -131,11 +129,8 @@ OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase) // Build prefixes. for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions() + 1; i != e; ++i) { - if (const char *const *P = getInfo(i).Prefixes) { - for (; *P != nullptr; ++P) { - PrefixesUnion.insert(*P); - } - } + const auto &P = getInfo(i).Prefixes; + PrefixesUnion.insert(P.begin(), P.end()); } // Build prefix chars. @@ -168,8 +163,7 @@ static bool isInput(const StringSet<> &Prefixes, StringRef Arg) { /// \returns Matched size. 0 means no match. static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase) { - for (const char * const *Pre = I->Prefixes; *Pre != nullptr; ++Pre) { - StringRef Prefix(*Pre); + for (auto Prefix : I->Prefixes) { if (Str.startswith(Prefix)) { StringRef Rest = Str.substr(Prefix.size()); bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name) @@ -183,13 +177,10 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str, // Returns true if one of the Prefixes + In.Names matches Option static bool optionMatches(const OptTable::Info &In, StringRef Option) { - if (In.Prefixes) { - StringRef InName(In.Name); - for (size_t I = 0; In.Prefixes[I]; I++) - if (Option.endswith(InName)) - if (Option.slice(0, Option.size() - InName.size()) == In.Prefixes[I]) - return true; - } + for (auto Prefix : In.Prefixes) + if (Option.endswith(In.Name)) + if (Option.slice(0, Option.size() - In.Name.size()) == Prefix) + return true; return false; } @@ -221,13 +212,13 @@ OptTable::findByPrefix(StringRef Cur, unsigned int DisableFlags) const { std::vector<std::string> Ret; for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) { const Info &In = OptionInfos[I]; - if (!In.Prefixes || (!In.HelpText && !In.GroupID)) + if (In.Prefixes.empty() || (!In.HelpText && !In.GroupID)) continue; if (In.Flags & DisableFlags) continue; - for (int I = 0; In.Prefixes[I]; I++) { - std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t"; + for (auto Prefix : In.Prefixes) { + std::string S = (Prefix + In.Name + "\t").str(); if (In.HelpText) S += In.HelpText; if (StringRef(S).startswith(Cur) && S != std::string(Cur) + "\t") @@ -265,7 +256,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, // * Ignore positional argument option candidates (which do not // have prefixes). - if (!CandidateInfo.Prefixes) + if (CandidateInfo.Prefixes.empty()) continue; // Now check if the candidate ends with a character commonly used when @@ -285,8 +276,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, // Consider each possible prefix for each candidate to find the most // appropriate one. For example, if a user asks for "--helm", suggest // "--help" over "-help". - for (int P = 0; - const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) { + for (auto CandidatePrefix : CandidateInfo.Prefixes) { std::string Candidate = (CandidatePrefix + CandidateName).str(); StringRef CandidateRef = Candidate; unsigned Distance = diff --git a/llvm/lib/Option/Option.cpp b/llvm/lib/Option/Option.cpp index ebdba89..1f1eb93 100644 --- a/llvm/lib/Option/Option.cpp +++ b/llvm/lib/Option/Option.cpp @@ -58,11 +58,10 @@ void Option::print(raw_ostream &O) const { #undef P } - if (Info->Prefixes) { + if (!Info->Prefixes.empty()) { O << " Prefixes:["; - for (const char *const *Pre = Info->Prefixes; *Pre != nullptr; ++Pre) { - O << '"' << *Pre << (*(Pre + 1) == nullptr ? "\"" : "\", "); - } + for (size_t I = 0, N = Info->Prefixes.size(); I != N; ++I) + O << '"' << Info->Prefixes[I] << (I == N - 1 ? "\"" : "\", "); O << ']'; } diff --git a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp index c8ef0d1..9bdff11 100644 --- a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp @@ -37,11 +37,12 @@ enum { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Options.inc" #undef PREFIX -static constexpr llvm::opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \ {X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \ X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12}, diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 7f06ed0..74a20a4 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -41,11 +41,12 @@ enum { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Options.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \ {X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \ X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12}, diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp index 5ed3b2b..7c4e3d9 100644 --- a/llvm/tools/dsymutil/dsymutil.cpp +++ b/llvm/tools/dsymutil/dsymutil.cpp @@ -63,11 +63,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Options.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp index b2be58b..6dbf0a7 100644 --- a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp +++ b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp @@ -44,11 +44,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp index 52a75ee..bbf4b63 100644 --- a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp +++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp @@ -32,11 +32,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<llvm::StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp b/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp index eeb92a7..1c1ebdc 100644 --- a/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp +++ b/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp @@ -40,11 +40,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Options.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp index bef2800..f64acf96 100644 --- a/llvm/tools/llvm-ifs/llvm-ifs.cpp +++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp @@ -60,11 +60,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-lipo/llvm-lipo.cpp b/llvm/tools/llvm-lipo/llvm-lipo.cpp index b4a76e18..78cda75 100644 --- a/llvm/tools/llvm-lipo/llvm-lipo.cpp +++ b/llvm/tools/llvm-lipo/llvm-lipo.cpp @@ -73,26 +73,27 @@ enum LipoID { #undef OPTION }; -// LipoInfoTable below references LIPO_##PREFIX. OptionGroup has prefix nullptr. -constexpr const char *const *LIPO_nullptr = nullptr; -#define PREFIX(NAME, VALUE) const char *const LIPO_##NAME[] = VALUE; +namespace lipo { +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<llvm::StringLiteral> NAME = VALUE; #include "LipoOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info LipoInfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> LipoInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {LIPO_##PREFIX, NAME, HELPTEXT, \ - METAVAR, LIPO_##ID, opt::Option::KIND##Class, \ - PARAM, FLAGS, LIPO_##GROUP, \ - LIPO_##ALIAS, ALIASARGS, VALUES}, + {PREFIX, NAME, HELPTEXT, \ + METAVAR, LIPO_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, LIPO_##GROUP, \ + LIPO_##ALIAS, ALIASARGS, VALUES}, #include "LipoOpts.inc" #undef OPTION }; +} // namespace lipo class LipoOptTable : public opt::OptTable { public: - LipoOptTable() : OptTable(LipoInfoTable) {} + LipoOptTable() : OptTable(lipo::LipoInfoTable) {} }; enum class LipoAction { diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp index 7626580..5c773bd 100644 --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -60,11 +60,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-mt/llvm-mt.cpp b/llvm/tools/llvm-mt/llvm-mt.cpp index 3f70c89..b6d57fa 100644 --- a/llvm/tools/llvm-mt/llvm-mt.cpp +++ b/llvm/tools/llvm-mt/llvm-mt.cpp @@ -41,11 +41,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index 47644f0..953637c 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -64,11 +64,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp index bf39f8c..287744b 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -36,32 +36,27 @@ enum ObjcopyID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const OBJCOPY_##NAME[] = VALUE; +namespace objcopy_opt { +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "ObjcopyOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info ObjcopyInfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> ObjcopyInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {OBJCOPY_##PREFIX, \ - NAME, \ - HELPTEXT, \ - METAVAR, \ - OBJCOPY_##ID, \ - opt::Option::KIND##Class, \ - PARAM, \ - FLAGS, \ - OBJCOPY_##GROUP, \ - OBJCOPY_##ALIAS, \ - ALIASARGS, \ - VALUES}, + {PREFIX, NAME, HELPTEXT, \ + METAVAR, OBJCOPY_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, OBJCOPY_##GROUP, \ + OBJCOPY_##ALIAS, ALIASARGS, VALUES}, #include "ObjcopyOpts.inc" #undef OPTION }; +} // namespace objcopy_opt class ObjcopyOptTable : public opt::OptTable { public: - ObjcopyOptTable() : OptTable(ObjcopyInfoTable) { + ObjcopyOptTable() : OptTable(objcopy_opt::ObjcopyInfoTable) { setGroupedShortOptions(true); } }; @@ -75,15 +70,18 @@ enum InstallNameToolID { #undef OPTION }; +namespace install_name_tool { + #define PREFIX(NAME, VALUE) \ - const char *const INSTALL_NAME_TOOL_##NAME[] = VALUE; + constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "InstallNameToolOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InstallNameToolInfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> + InstallNameToolInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {INSTALL_NAME_TOOL_##PREFIX, \ + {PREFIX, \ NAME, \ HELPTEXT, \ METAVAR, \ @@ -98,10 +96,12 @@ static constexpr opt::OptTable::Info InstallNameToolInfoTable[] = { #include "InstallNameToolOpts.inc" #undef OPTION }; +} // namespace install_name_tool class InstallNameToolOptTable : public opt::OptTable { public: - InstallNameToolOptTable() : OptTable(InstallNameToolInfoTable) {} + InstallNameToolOptTable() + : OptTable(install_name_tool::InstallNameToolInfoTable) {} }; enum BitcodeStripID { @@ -113,14 +113,18 @@ enum BitcodeStripID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const BITCODE_STRIP_##NAME[] = VALUE; +namespace bitcode_strip { + +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "BitcodeStripOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info BitcodeStripInfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> + BitcodeStripInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {BITCODE_STRIP_##PREFIX, \ + {PREFIX, \ NAME, \ HELPTEXT, \ METAVAR, \ @@ -135,10 +139,11 @@ static constexpr opt::OptTable::Info BitcodeStripInfoTable[] = { #include "BitcodeStripOpts.inc" #undef OPTION }; +} // namespace bitcode_strip class BitcodeStripOptTable : public opt::OptTable { public: - BitcodeStripOptTable() : OptTable(BitcodeStripInfoTable) {} + BitcodeStripOptTable() : OptTable(bitcode_strip::BitcodeStripInfoTable) {} }; enum StripID { @@ -150,24 +155,29 @@ enum StripID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const STRIP_##NAME[] = VALUE; +namespace strip { +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "StripOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info StripInfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> StripInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {STRIP_##PREFIX, NAME, HELPTEXT, \ - METAVAR, STRIP_##ID, opt::Option::KIND##Class, \ - PARAM, FLAGS, STRIP_##GROUP, \ - STRIP_##ALIAS, ALIASARGS, VALUES}, + {PREFIX, NAME, HELPTEXT, \ + METAVAR, STRIP_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, STRIP_##GROUP, \ + STRIP_##ALIAS, ALIASARGS, VALUES}, #include "StripOpts.inc" #undef OPTION }; +} // namespace strip class StripOptTable : public opt::OptTable { public: - StripOptTable() : OptTable(StripInfoTable) { setGroupedShortOptions(true); } + StripOptTable() : OptTable(strip::StripInfoTable) { + setGroupedShortOptions(true); + } }; } // namespace diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index bb02cd0..5cd6acb 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -119,28 +119,29 @@ private: }; // ObjdumpOptID is in ObjdumpOptID.h - -#define PREFIX(NAME, VALUE) const char *const OBJDUMP_##NAME[] = VALUE; +namespace objdump_opt { +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "ObjdumpOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info ObjdumpInfoTable[] = { -#define OBJDUMP_nullptr nullptr +static constexpr std::initializer_list<opt::OptTable::Info> ObjdumpInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {OBJDUMP_##PREFIX, NAME, HELPTEXT, \ - METAVAR, OBJDUMP_##ID, opt::Option::KIND##Class, \ - PARAM, FLAGS, OBJDUMP_##GROUP, \ - OBJDUMP_##ALIAS, ALIASARGS, VALUES}, + {PREFIX, NAME, HELPTEXT, \ + METAVAR, OBJDUMP_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, OBJDUMP_##GROUP, \ + OBJDUMP_##ALIAS, ALIASARGS, VALUES}, #include "ObjdumpOpts.inc" #undef OPTION -#undef OBJDUMP_nullptr }; +} // namespace objdump_opt class ObjdumpOptTable : public CommonOptTable { public: ObjdumpOptTable() - : CommonOptTable(ObjdumpInfoTable, " [options] <input object files>", + : CommonOptTable(objdump_opt::ObjdumpInfoTable, + " [options] <input object files>", "llvm object file dumper") {} }; @@ -153,27 +154,28 @@ enum OtoolOptID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const OTOOL_##NAME[] = VALUE; +namespace otool { +#define PREFIX(NAME, VALUE) \ + constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "OtoolOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info OtoolInfoTable[] = { -#define OTOOL_nullptr nullptr +static constexpr std::initializer_list<opt::OptTable::Info> OtoolInfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - {OTOOL_##PREFIX, NAME, HELPTEXT, \ - METAVAR, OTOOL_##ID, opt::Option::KIND##Class, \ - PARAM, FLAGS, OTOOL_##GROUP, \ - OTOOL_##ALIAS, ALIASARGS, VALUES}, + {PREFIX, NAME, HELPTEXT, \ + METAVAR, OTOOL_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, OTOOL_##GROUP, \ + OTOOL_##ALIAS, ALIASARGS, VALUES}, #include "OtoolOpts.inc" #undef OPTION -#undef OTOOL_nullptr }; +} // namespace otool class OtoolOptTable : public CommonOptTable { public: OtoolOptTable() - : CommonOptTable(OtoolInfoTable, " [option...] [file...]", + : CommonOptTable(otool::OtoolInfoTable, " [option...] [file...]", "Mach-O object file displaying tool") {} }; diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp index 00fb9c1..ff21213 100644 --- a/llvm/tools/llvm-rc/llvm-rc.cpp +++ b/llvm/tools/llvm-rc/llvm-rc.cpp @@ -55,11 +55,13 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +namespace rc_opt { +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ @@ -70,10 +72,11 @@ static constexpr opt::OptTable::Info InfoTable[] = { #include "Opts.inc" #undef OPTION }; +} // namespace rc_opt class RcOptTable : public opt::OptTable { public: - RcOptTable() : OptTable(InfoTable, /* IgnoreCase = */ true) {} + RcOptTable() : OptTable(rc_opt::InfoTable, /* IgnoreCase = */ true) {} }; enum Windres_ID { @@ -85,25 +88,28 @@ enum Windres_ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const WINDRES_##NAME[] = VALUE; +namespace windres_opt { +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "WindresOpts.inc" #undef PREFIX -static constexpr opt::OptTable::Info WindresInfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ - { \ - WINDRES_##PREFIX, NAME, HELPTEXT, \ - METAVAR, WINDRES_##ID, opt::Option::KIND##Class, \ - PARAM, FLAGS, WINDRES_##GROUP, \ - WINDRES_##ALIAS, ALIASARGS, VALUES}, + {PREFIX, NAME, HELPTEXT, \ + METAVAR, WINDRES_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, WINDRES_##GROUP, \ + WINDRES_##ALIAS, ALIASARGS, VALUES}, #include "WindresOpts.inc" #undef OPTION }; +} // namespace windres_opt class WindresOptTable : public opt::OptTable { public: - WindresOptTable() : OptTable(WindresInfoTable, /* IgnoreCase = */ false) {} + WindresOptTable() + : OptTable(windres_opt::InfoTable, /* IgnoreCase = */ false) {} }; static ExitOnError ExitOnErr; diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index 7cb2036..57598b0 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -61,11 +61,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index de2e285..884f6f0 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -47,11 +47,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-strings/llvm-strings.cpp b/llvm/tools/llvm-strings/llvm-strings.cpp index 918ca5f..afaa00b 100644 --- a/llvm/tools/llvm-strings/llvm-strings.cpp +++ b/llvm/tools/llvm-strings/llvm-strings.cpp @@ -39,11 +39,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp index 833506a..b7e7fd2 100644 --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -56,11 +56,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp index 05fb5ff..fa5ef6d 100644 --- a/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp +++ b/llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp @@ -35,11 +35,12 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX -static constexpr opt::OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<opt::OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ { \ diff --git a/llvm/unittests/Option/OptionParsingTest.cpp b/llvm/unittests/Option/OptionParsingTest.cpp index 1857345..2f10e26 100644 --- a/llvm/unittests/Option/OptionParsingTest.cpp +++ b/llvm/unittests/Option/OptionParsingTest.cpp @@ -25,7 +25,8 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#define PREFIX(NAME, VALUE) \ + static constexpr std::initializer_list<StringLiteral> NAME = VALUE; #include "Opts.inc" #undef PREFIX @@ -35,7 +36,7 @@ enum OptionFlags { OptFlag3 = (1 << 6) }; -static constexpr OptTable::Info InfoTable[] = { +static constexpr std::initializer_list<OptTable::Info> InfoTable = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ {PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, \ diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp index e8bc9da..4617270 100644 --- a/llvm/utils/TableGen/OptParserEmitter.cpp +++ b/llvm/utils/TableGen/OptParserEmitter.cpp @@ -251,8 +251,8 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) { // Prefix values. OS << ", {"; for (const auto &PrefixKey : Prefix.first) - OS << "\"" << PrefixKey << "\" COMMA "; - OS << "nullptr})\n"; + OS << "llvm::StringLiteral(\"" << PrefixKey << "\") COMMA "; + OS << "})\n"; } OS << "#undef COMMA\n"; OS << "#endif // PREFIX\n\n"; @@ -265,7 +265,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) { OS << "OPTION("; // The option prefix; - OS << "nullptr"; + OS << "{}"; // The option string. OS << ", \"" << R.getValueAsString("Name") << '"'; |