[llvm] [llvm][TableGen] Remove gen-opt-rst backend (PR #71374)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 02:50:23 PST 2023


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/71374

This is unused and was ported to clang with a different name in https://reviews.llvm.org/D123682. So if we were to bring it back it makes more sense to use that updated version.

>From ef74b332af142065257746c99592786f2596a2d1 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Mon, 6 Nov 2023 10:39:49 +0000
Subject: [PATCH] [llvm][TableGen] Remove gen-opt-rst backend

This is unused and was ported to clang with a different name in
https://reviews.llvm.org/D123682. So if we were to bring it back
it makes more sense to use that updated version.
---
 llvm/utils/TableGen/CMakeLists.txt    |   1 -
 llvm/utils/TableGen/OptRSTEmitter.cpp | 107 --------------------------
 2 files changed, 108 deletions(-)
 delete mode 100644 llvm/utils/TableGen/OptRSTEmitter.cpp

diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index 071ea3bc07054bb..9819a197311230a 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -68,7 +68,6 @@ add_tablegen(llvm-tblgen LLVM
   InstrDocsEmitter.cpp
   OptEmitter.cpp
   OptParserEmitter.cpp
-  OptRSTEmitter.cpp
   PredicateExpander.cpp
   PseudoLoweringEmitter.cpp
   CompressInstEmitter.cpp
diff --git a/llvm/utils/TableGen/OptRSTEmitter.cpp b/llvm/utils/TableGen/OptRSTEmitter.cpp
deleted file mode 100644
index 5a7f079dc1681cb..000000000000000
--- a/llvm/utils/TableGen/OptRSTEmitter.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-//===- OptParserEmitter.cpp - Table Driven Command Line Parsing -----------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "OptEmitter.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/TableGen/Record.h"
-#include "llvm/TableGen/TableGenBackend.h"
-
-using namespace llvm;
-
-/// OptParserEmitter - This tablegen backend takes an input .td file
-/// describing a list of options and emits a RST man page.
-static void EmitOptRST(RecordKeeper &Records, raw_ostream &OS) {
-  llvm::StringMap<std::vector<Record *>> OptionsByGroup;
-  std::vector<Record *> OptionsWithoutGroup;
-
-  // Get the options.
-  std::vector<Record *> Opts = Records.getAllDerivedDefinitions("Option");
-  array_pod_sort(Opts.begin(), Opts.end(), CompareOptionRecords);
-
-  // Get the option groups.
-  const std::vector<Record *> &Groups =
-      Records.getAllDerivedDefinitions("OptionGroup");
-  for (unsigned i = 0, e = Groups.size(); i != e; ++i) {
-    const Record &R = *Groups[i];
-    OptionsByGroup.try_emplace(R.getValueAsString("Name"));
-  }
-
-  // Map options to their group.
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-    const Record &R = *Opts[i];
-    if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) {
-      OptionsByGroup[DI->getDef()->getValueAsString("Name")].push_back(Opts[i]);
-    } else {
-      OptionsByGroup["options"].push_back(Opts[i]);
-    }
-  }
-
-  // Print options under their group.
-  for (const auto &KV : OptionsByGroup) {
-    std::string GroupName = KV.getKey().upper();
-    OS << GroupName << '\n';
-    OS << std::string(GroupName.size(), '-') << '\n';
-    OS << '\n';
-
-    for (Record *R : KV.getValue()) {
-      OS << ".. option:: ";
-
-      // Print the prefix.
-      std::vector<StringRef> Prefixes = R->getValueAsListOfStrings("Prefixes");
-      if (!Prefixes.empty())
-        OS << Prefixes[0];
-
-      // Print the option name.
-      OS << R->getValueAsString("Name");
-
-      StringRef MetaVarName;
-      // Print the meta-variable.
-      if (!isa<UnsetInit>(R->getValueInit("MetaVarName"))) {
-        MetaVarName = R->getValueAsString("MetaVarName");
-      } else if (!isa<UnsetInit>(R->getValueInit("Values")))
-        MetaVarName = "<value>";
-
-      if (!MetaVarName.empty()) {
-        OS << '=';
-        OS.write_escaped(MetaVarName);
-      }
-
-      OS << "\n\n";
-
-      std::string HelpText;
-      // The option help text.
-      if (!isa<UnsetInit>(R->getValueInit("HelpText"))) {
-        HelpText = R->getValueAsString("HelpText").trim().str();
-        if (!HelpText.empty() && HelpText.back() != '.')
-          HelpText.push_back('.');
-      }
-
-      if (!isa<UnsetInit>(R->getValueInit("Values"))) {
-        SmallVector<StringRef> Values;
-        SplitString(R->getValueAsString("Values"), Values, ",");
-        HelpText += (" " + MetaVarName + " must be '").str();
-
-        if (Values.size() > 1) {
-          HelpText += join(Values.begin(), Values.end() - 1, "', '");
-          HelpText += "' or '";
-        }
-        HelpText += (Values.back() + "'.").str();
-      }
-
-      if (!HelpText.empty()) {
-        OS << ' ';
-        OS.write_escaped(HelpText);
-        OS << "\n\n";
-      }
-    }
-  }
-}
-
-static TableGen::Emitter::Opt X("gen-opt-rst", EmitOptRST,
-                                "Generate option RST");



More information about the llvm-commits mailing list