@@ -173,6 +173,13 @@ static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) {
173
173
}
174
174
}
175
175
176
+ static StringRef resolveAttrDescription (const Attribute &attr) {
177
+ StringRef description = attr.getDescription ();
178
+ if (description.empty ())
179
+ return attr.getBaseAttr ().getDescription ();
180
+ return description;
181
+ }
182
+
176
183
static void emitOpDoc (const Operator &op, raw_ostream &os) {
177
184
std::string classNameStr = op.getQualCppClassName ();
178
185
StringRef className = classNameStr;
@@ -192,16 +199,35 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
192
199
193
200
// Emit attributes.
194
201
if (op.getNumAttributes () != 0 ) {
195
- // TODO: Attributes are only documented by TableGen name, with no further
196
- // info. This should be improved.
197
202
os << " \n #### Attributes:\n\n " ;
198
- os << " | Attribute | MLIR Type | Description |\n "
199
- << " | :-------: | :-------: | ----------- |\n " ;
203
+ // Note: This table is HTML rather than markdown so the attribute's
204
+ // description can appear in an expandable region. The description may be
205
+ // multiple lines, which is not supported in a markdown table cell.
206
+ os << " <table>\n " ;
207
+ // Header.
208
+ os << " <tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr>\n " ;
200
209
for (const auto &it : op.getAttributes ()) {
201
210
StringRef storageType = it.attr .getStorageType ();
202
- os << " | `" << it.name << " ` | " << storageType << " | "
203
- << it.attr .getSummary () << " \n " ;
211
+ // Name and storage type.
212
+ os << " <tr>" ;
213
+ os << " <td><code>" << it.name << " </code></td><td>" << storageType
214
+ << " </td><td>" ;
215
+ StringRef description = resolveAttrDescription (it.attr );
216
+ if (!description.empty ()) {
217
+ // Expandable description.
218
+ // This appears as just the summary, but when clicked shows the full
219
+ // description.
220
+ os << " <details>"
221
+ << " <summary>" << it.attr .getSummary () << " </summary>"
222
+ << " {{% markdown %}}" << description << " {{% /markdown %}}"
223
+ << " </details>" ;
224
+ } else {
225
+ // Fallback: Single-line summary.
226
+ os << it.attr .getSummary ();
227
+ }
228
+ os << " </td></tr>\n " ;
204
229
}
230
+ os << " <table>\n " ;
205
231
}
206
232
207
233
// Emit each of the operands.
0 commit comments