[Mlir-commits] [mlir] [mlir-tblgen] Render enum keyword alternatives in generated attr/type docs (PR #203677)
Federico Bruzzone
llvmlistbot at llvm.org
Sat Jun 13 05:50:19 PDT 2026
================
@@ -384,6 +384,25 @@ static void emitTypeDoc(const Type &type, raw_ostream &os) {
// TypeDef Documentation
//===----------------------------------------------------------------------===//
+/// If \p param is an EnumParameter, return a string listing the enum's keyword
+/// alternatives (e.g. "`read` | `read_write`"). Otherwise return std::nullopt.
+static std::optional<std::string>
+getEnumParameterDocSyntax(const AttrOrTypeParameter ¶m) {
+ const auto *paramDef = dyn_cast<DefInit>(param.getDef());
+ if (!paramDef || !paramDef->getDef()->isSubClassOf("EnumParameter"))
+ return std::nullopt;
+ const Record *enumRec = paramDef->getDef()->getValueAsDef("enum");
+ EnumInfo enumInfo(enumRec);
+ std::vector<EnumCase> cases = enumInfo.getAllCases();
+ std::string result;
+ for (const auto &caseIt : llvm::enumerate(cases)) {
+ if (caseIt.index() > 0)
+ result += " | ";
+ result += (llvm::Twine("`") + caseIt.value().getStr() + "`").str();
+ }
----------------
FedericoBruzzone wrote:
Maybe we can use something like (as in `AttrOrTypeFormatGen.cpp`):
```cpp
llvm::interleave(cases,
[&](const EnumCase &c) { result += "`" + c.getStr() + "`"; },
[&] { result += " | "; });
```
https://github.com/llvm/llvm-project/pull/203677
More information about the Mlir-commits
mailing list