YAML serialization of C++ classes

A couple meetings ago, when we were discussing bindings, I believe @mehdi_amini mentioned that one way to export the logic done in mlir-tblgen would be to use some facility to make serializing C++ types to YAML simple. Could someone point me to an example of where this functionality is currently used?

Here’s my most recent sample of it: llvm-project/mlir-linalg-ods-yaml-gen.cpp at main · llvm/llvm-project · GitHub

The docs on the YAML library are good: YAML I/O — LLVM 12 documentation

I found that it is good/sufficient if you are also defining the YAML format and can hold yourself to some simplifications that leave you out of hard mapping territory. In practice, there was one situation that I ran in to where I chose to model the serialization in a simplified fashion in order to aid interop with this library.

1 Like

Thanks for the links! It seems like this API requires l-values which is unfortunate since the interesting accessors on MLIR tablegen types are function return values (like Operator::getOperationName()). It may end up being easier to dump this as JSON similar to how it is done in JSONBackend.cpp.

To clarify: during the meeting I was suggesting writing a schema for ODS in general so that we would always go from ODS->YAML->C++. I believe the mlir-linalg-ods-yaml-gen example is generating ODS though? So that we have YAML->ODS->C++ instead (if I followed the setup).