[Mlir-commits] [mlir] [MLIR][Python] Add docstring for generated python op classes (PR #158198)
Maksim Levental
llvmlistbot at llvm.org
Thu Sep 11 23:03:09 PDT 2025
================
@@ -1034,9 +1037,31 @@ static void emitValueBuilder(const Operator &op,
}
}
+/// Retrieve the description of the given op and generate a docstring for it.
+static std::string makeDocStringForOp(const Operator &op) {
+ if (!op.hasDescription())
+ return "";
+
+ auto desc = op.getDescription().rtrim(" \t").str();
+ // Replace all """ with \"\"\" to avoid early termination of the literal.
+ desc = std::regex_replace(desc, std::regex(R"(""")"), R"(\"\"\")");
+
+ std::string docString = "\n";
+ llvm::raw_string_ostream os(docString);
+ raw_indented_ostream identedOs(os);
+ os << R"( """)" << "\n";
----------------
makslevental wrote:
```suggestion
os << R"( r""")" << "\n";
```
https://github.com/llvm/llvm-project/pull/158198
More information about the Mlir-commits
mailing list