[flang-commits] [clang] [clang-tools-extra] [flang] [lld] [llvm] [flang][clang] Add Visibility specific help text for options (PR #81869)

David Spickett via flang-commits flang-commits at lists.llvm.org
Thu Mar 14 09:04:59 PDT 2024


================
@@ -191,6 +191,60 @@ static MarshallingInfo createMarshallingInfo(const Record &R) {
   return Ret;
 }
 
+static void EmitHelpTextsForVariants(
+    raw_ostream &OS, std::vector<std::pair<std::vector<std::string>, StringRef>>
+                         HelpTextsForVariants) {
+  // OptTable must be constexpr so it uses std::arrays with these capacities.
+  const unsigned MaxVisibilityPerHelp = 2;
+  const unsigned MaxVisibilityHelp = 1;
+
+  // This function must initialise any unused elements of those arrays.
+  for (auto [Visibilities, _] : HelpTextsForVariants)
+    while (Visibilities.size() < MaxVisibilityPerHelp)
+      Visibilities.push_back("0");
+
+  while (HelpTextsForVariants.size() < MaxVisibilityHelp)
+    HelpTextsForVariants.push_back(
+        {std::vector<std::string>(MaxVisibilityPerHelp, "0"), ""});
+
+  OS << ", (std::array<std::pair<std::array<unsigned, " << MaxVisibilityPerHelp
+     << ">, const char*>, " << MaxVisibilityHelp << ">{{ ";
+
+  assert(HelpTextsForVariants.size() <= MaxVisibilityHelp &&
+         "Too many help text variants to store in "
+         "OptTable::HelpTextsForVariants");
+
+  for (auto VisibilityHelp = HelpTextsForVariants.cbegin();
+       VisibilityHelp != HelpTextsForVariants.cend(); ++VisibilityHelp) {
+    auto [Visibilities, Help] = *VisibilityHelp;
+
+    assert(Visibilities.size() <= MaxVisibilityPerHelp &&
+           "Too many visibilities to store in an "
+           "OptTable::HelpTextsForVariants entry");
+    OS << "std::make_pair(std::array<unsigned, " << MaxVisibilityPerHelp
+       << ">{{";
+
+    for (auto Visibility = Visibilities.cbegin();
+         Visibility != Visibilities.cend(); ++Visibility) {
+      OS << *Visibility;
+      if (std::next(Visibility) != Visibilities.cend())
+        OS << ", ";
+    }
+
+    OS << "}}, ";
+
+    if (Help.size())
+      OS << "\"" << Help << "\"";
----------------
DavidSpickett wrote:

No! Good spot, `HelpText` uses `write_cstring` which does so I'll use that.

https://github.com/llvm/llvm-project/pull/81869


More information about the flang-commits mailing list