Problem
Operation assembly-format handling is spread across multiple emitters. TryParseEmitter, BuildCustomAssemblySyntaxEmitter, and EmitterHelpers.AppendBodySyntaxFields each switch over the same assembly-format element kinds and duplicate pieces of directive semantics.
The generator should lower operation assembly formats once into a reusable intermediate representation, then emit parse/build/write code mechanically from that lowered form.
Current Hotspots
src/MLIR.Generators/Emitters/AssemblyFormat/TryParseEmitter.cs
src/MLIR.Generators/Emitters/AssemblyFormat/BuildCustomAssemblySyntaxEmitter.cs
src/MLIR.Generators/Emitters/Common/EmitterHelpers.cs: AppendBodySyntaxFields
src/MLIR.Generators/Emitters/Common/AssemblyFormatTraversal.cs
src/MLIR.Generators/Emitters/Operations/OperationBodySyntaxEmitter.cs
Proposed Direction
Create a lowering layer that maps ODS assembly-format elements to a shared representation, for example:
public sealed class LoweredFormatElement
{
public IReadOnlyList<BodySyntaxField> Fields { get; }
public CodeTemplate Parse { get; }
public CodeTemplate Build { get; }
public CodeTemplate Write { get; }
public CodeTemplate? PresenceCondition { get; }
}
The lowering layer should own directive semantics for literals, variables, attr-dict, prop-dict, regions, operands, successors, type, qualified, results, functional-type, optional groups, and oilists.
Acceptance Criteria
- Assembly-format directive handling is centralized in one lowering layer.
TryParseEmitter and BuildCustomAssemblySyntaxEmitter no longer independently switch over every directive kind.
- Body syntax field generation consumes the same lowered representation as parse/build emission.
- Unsupported directives are identified during lowering with clear fallback behavior or diagnostics.
- Existing generated operation custom assembly parse/build behavior remains stable.
Suggested Tests
- Generator tests for each supported directive kind.
- Optional group tests with literal, operand, attribute, unit attribute, and region anchors.
- Oilist tests with multiple clauses and repeated-clause rejection.
- Fallback test for an unsupported directive.
Notes
This is the operation-side equivalent of unifying attr/type assembly-format emission. It should make later removal of ad hoc directive hacks much easier.
Problem
Operation assembly-format handling is spread across multiple emitters.
TryParseEmitter,BuildCustomAssemblySyntaxEmitter, andEmitterHelpers.AppendBodySyntaxFieldseach switch over the same assembly-format element kinds and duplicate pieces of directive semantics.The generator should lower operation assembly formats once into a reusable intermediate representation, then emit parse/build/write code mechanically from that lowered form.
Current Hotspots
src/MLIR.Generators/Emitters/AssemblyFormat/TryParseEmitter.cssrc/MLIR.Generators/Emitters/AssemblyFormat/BuildCustomAssemblySyntaxEmitter.cssrc/MLIR.Generators/Emitters/Common/EmitterHelpers.cs:AppendBodySyntaxFieldssrc/MLIR.Generators/Emitters/Common/AssemblyFormatTraversal.cssrc/MLIR.Generators/Emitters/Operations/OperationBodySyntaxEmitter.csProposed Direction
Create a lowering layer that maps ODS assembly-format elements to a shared representation, for example:
The lowering layer should own directive semantics for literals, variables,
attr-dict,prop-dict,regions,operands,successors,type,qualified,results,functional-type, optional groups, and oilists.Acceptance Criteria
TryParseEmitterandBuildCustomAssemblySyntaxEmitterno longer independently switch over every directive kind.Suggested Tests
Notes
This is the operation-side equivalent of unifying attr/type assembly-format emission. It should make later removal of ad hoc directive hacks much easier.