[llvm] [utils][TableGen] Handle versions on clause/directive spellings (PR #143021)

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 6 06:48:11 PDT 2025


================
@@ -415,23 +466,29 @@ static void generateGetKind(ArrayRef<const Record *> Records, raw_ostream &OS,
   // std::pair<<Enum>, VersionRange>
   // get<DirLang><Enum>KindAndVersions(StringRef Str);
   OS << "\n";
-  OS << "std::pair<" << Qual << Enum << ", " << Qual << "VersionRange> " << Qual
-     << "get" << DirLang.getName() << Enum
+  OS << "std::pair<" << Qual << Enum << ", llvm::directive::VersionRange> "
+     << Qual << "get" << DirLang.getName() << Enum
      << "KindAndVersions(llvm::StringRef Str) {\n";
-  OS << "  VersionRange All{}; // Default-initialized to \"all-versions\"\n";
+  OS << "  directive::VersionRange All; // Default-initialized to \"all "
+        "versions\"\n";
   OS << "  return StringSwitch<std::pair<" << Enum << ", "
-     << "VersionRange>>(Str)\n";
+     << "directive::VersionRange>>(Str)\n";
+
+  directive::VersionRange All;
 
   for (const Record *R : Records) {
     BaseRecord Rec(R);
-    // FIXME: This will need to recognize different spellings for different
-    // versions.
-    StringRef Name = Rec.getSpellingForIdentifier();
-    if (ImplicitAsUnknown && R->getValueAsBit("isImplicit")) {
-      OS << "    .Case(\"" << Name << "\", {" << DefaultName << ", All})\n";
-    } else {
-      OS << "    .Case(\"" << Name << "\", {" << getIdentifierName(R, Prefix)
-         << ", All})\n";
+    std::string Ident = ImplicitAsUnknown && R->getValueAsBit("isImplicit")
+                            ? DefaultName
+                            : getIdentifierName(R, Prefix);
+
+    for (auto &[Name, Versions] : Rec.getSpellings()) {
+      OS << "    .Case(\"" << Name << "\", {" << Ident << ", ";
+      if (Versions.Min == All.Min && Versions.Max == All.Max) {
----------------
kparzysz wrote:

Done

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


More information about the llvm-commits mailing list