Skip to content

Emit concrete OperationBodySyntax subclass per operation with declarative assembly format#9

Merged
jonathanvdc merged 2 commits intomainfrom
copilot/teach-dialectsourceemitter-synthesize-cst
Mar 29, 2026
Merged

Emit concrete OperationBodySyntax subclass per operation with declarative assembly format#9
jonathanvdc merged 2 commits intomainfrom
copilot/teach-dialectsourceemitter-synthesize-cst

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

DialectSourceEmitter previously had no CST representation for operations with declarative assembly formats — only an IOperationAssemblyFormat stub. This adds a generated {ClassName}BodySyntax : OperationBodySyntax class whose fields mirror the token/sub-CST sequence in the operation's AssemblyFormatModel.

Generated class structure

For $lhs ,$rhs attr-dict: type($result), the emitter now produces:

public sealed class MiniArith_AddIOpBodySyntax : OperationBodySyntax
{
    public MiniArith_AddIOpBodySyntax(
        SyntaxToken lhs, SyntaxToken commaToken, SyntaxToken rhs,
        DelimitedSyntaxList<NamedAttributeSyntax> attrDict,
        SyntaxToken colonToken, TypeSyntax resultType) { ... }

    public SyntaxToken Lhs { get; }
    public SyntaxToken CommaToken { get; }
    public SyntaxToken Rhs { get; }
    public DelimitedSyntaxList<NamedAttributeSyntax> AttrDict { get; }
    public SyntaxToken ColonToken { get; }
    public TypeSyntax ResultType { get; }

    public override bool TryGetGenericBody(out GenericOperationBodySyntax? genericBody)
    { genericBody = null; return false; }

    public override void WriteTo(Text.SyntaxWriter writer, int indentLevel,
        System.Action<Text.SyntaxWriter, RegionSyntax, int> writeRegion) { ... }
}

Element-to-field mapping

Format element Generated C# field type
Punctuation/keyword literal SyntaxToken
Operand/result variable SyntaxToken
Attribute variable AttributeValueSyntax
attr-dict / attr-dict-with-keyword / prop-dict DelimitedSyntaxList<NamedAttributeSyntax>
regions IReadOnlyList<RegionSyntax>
type(...) TypeSyntax
successors / operands DelimitedSyntaxList<SyntaxToken>

Complex elements (optional groups, oilist, custom directives) are not stored — WriteTo omits them silently for now.

Related change

NamedAttributeSyntax.WriteTo promoted from internal to public so generated consumer assemblies can call it when serialising attribute dictionaries.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…es for operations with assembly formats

Agent-Logs-Url: https://github.com/jonathanvdc/MLIR.NET/sessions/8c4f0d04-0e04-4697-9f1c-86e836772c76

Co-authored-by: jonathanvdc <9839946+jonathanvdc@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@jonathanvdc jonathanvdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work.

@jonathanvdc jonathanvdc marked this pull request as ready for review March 29, 2026 04:49
Copilot AI changed the title [WIP] Add concrete syntax tree class generation for operations Emit concrete OperationBodySyntax subclass per operation with declarative assembly format Mar 29, 2026
Copilot AI requested a review from jonathanvdc March 29, 2026 04:52
@jonathanvdc jonathanvdc merged commit 9a3c390 into main Mar 29, 2026
1 check passed
@jonathanvdc jonathanvdc deleted the copilot/teach-dialectsourceemitter-synthesize-cst branch March 29, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants