18 Parsing And Printing
Parsing converts MLIR text or bytecode into in-memory IR; printing serializes that IR for people, tests, diagnostics, or another tool. They are not cosmetic: a parser must construct verified objects and a printer must preserve all semantically relevant information.
18.1 Generic Form Is The Ground Truth
Every operation has a generic form that exposes its name, operands, result types, attributes, successors, and regions. Custom assembly may hide redundant pieces for readability. When debugging a parse failure or an unfamiliar operation, print generic form first; it reveals what the custom syntax is abbreviating.
A parser may build an operation successfully and still fail verification. Syntax answers whether text has a valid grammar; verification answers whether fields agree semantically. Good diagnostics distinguish these failures.
18.2 Round-Tripping And Stable Text
Readable syntax is valuable for tests, but pass tests should avoid depending on irrelevant printer choices. Test semantic structure, generic forms where necessary, and only the custom spelling that a dialect intentionally promises. A custom printer must emit enough information for its parser to reconstruct the same IR or deliberately use a documented canonical form.