[Mlir-commits] [mlir] [mlir] add optional type functor to call and function interfaces (PR #146979)
River Riddle
llvmlistbot at llvm.org
Wed Jul 9 09:32:26 PDT 2025
================
@@ -1454,3 +1457,34 @@ test::TestCreateTensorOp::getBufferType(
return cast<mlir::bufferization::BufferLikeType>(test::TestMemrefType::get(
getContext(), type.getShape(), type.getElementType(), nullptr));
}
+
+//===----------------------------------------------------------------------===//
+// CustomTypeFormatFuncOp
+//===----------------------------------------------------------------------===//
+
+ParseResult CustomTypeFormatFuncOp::parse(OpAsmParser &parser,
+ OperationState &result) {
+ auto buildFuncType =
+ [](Builder &builder, ArrayRef<Type> argTypes, ArrayRef<Type> results,
+ function_interface_impl::VariadicFlag,
+ std::string &) { return builder.getFunctionType(argTypes, results); };
+
+ auto typeParser = [&](OpAsmParser &p, Type &ty) {
+ if (p.parseKeyword("type") || p.parseColon())
+ return (ParseResult)failure();
+ return p.parseType(ty);
+ };
----------------
River707 wrote:
```suggestion
auto typeParser = [&](OpAsmParser &p, Type &ty) {
return failure(p.parseKeyword("type") || p.parseColon() || p.parseType(ty));
};
```
?
Or you can do something like:
```
auto typeParser = [&](OpAsmParser &p, Type &ty) -> ParseResult {
if (p.parseKeyword("type") || p.parseColon())
return failure();
return p.parseType(ty);
};
```
https://github.com/llvm/llvm-project/pull/146979
More information about the Mlir-commits
mailing list