|
| 1 | +namespace MLIR.Generators.Emitters; |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using MLIR.ODS.Model; |
| 6 | + |
| 7 | +internal sealed class OperationBodySyntaxConstructionPlan |
| 8 | +{ |
| 9 | + public OperationBodySyntaxConstructionPlan( |
| 10 | + IReadOnlyList<string> regionFields, |
| 11 | + IReadOnlyDictionary<string, string> attributeFields, |
| 12 | + string? attrDictField, |
| 13 | + string? attrDictWithKeywordField, |
| 14 | + string? propDictField, |
| 15 | + IReadOnlyDictionary<string, string> operandFields, |
| 16 | + IReadOnlyDictionary<string, string> resultFields, |
| 17 | + string? typeField, |
| 18 | + string? successorsField, |
| 19 | + string? operandsField) |
| 20 | + { |
| 21 | + RegionFields = regionFields; |
| 22 | + AttributeFields = attributeFields; |
| 23 | + AttrDictField = attrDictField; |
| 24 | + AttrDictWithKeywordField = attrDictWithKeywordField; |
| 25 | + PropDictField = propDictField; |
| 26 | + OperandFields = operandFields; |
| 27 | + ResultFields = resultFields; |
| 28 | + TypeField = typeField; |
| 29 | + SuccessorsField = successorsField; |
| 30 | + OperandsField = operandsField; |
| 31 | + } |
| 32 | + |
| 33 | + public IReadOnlyList<string> RegionFields { get; } |
| 34 | + public IReadOnlyDictionary<string, string> AttributeFields { get; } |
| 35 | + public string? AttrDictField { get; } |
| 36 | + public string? AttrDictWithKeywordField { get; } |
| 37 | + public string? PropDictField { get; } |
| 38 | + public IReadOnlyDictionary<string, string> OperandFields { get; } |
| 39 | + public IReadOnlyDictionary<string, string> ResultFields { get; } |
| 40 | + public string? TypeField { get; } |
| 41 | + public string? SuccessorsField { get; } |
| 42 | + public string? OperandsField { get; } |
| 43 | +} |
| 44 | + |
| 45 | +internal static class OperationBodySyntaxDescriptor |
| 46 | +{ |
| 47 | + public static OperationBodySyntaxConstructionPlan Describe(OperationBodySyntaxMetadata metadata) |
| 48 | + { |
| 49 | + var regionFields = new List<string>(); |
| 50 | + var attributeFields = new Dictionary<string, string>(StringComparer.Ordinal); |
| 51 | + var operandFields = new Dictionary<string, string>(StringComparer.Ordinal); |
| 52 | + var resultFields = new Dictionary<string, string>(StringComparer.Ordinal); |
| 53 | + string? attrDictField = null; |
| 54 | + string? attrDictWithKeywordField = null; |
| 55 | + string? propDictField = null; |
| 56 | + string? successorsField = null; |
| 57 | + string? operandsField = null; |
| 58 | + string? typeField = null; |
| 59 | + |
| 60 | + foreach (var component in metadata.ComponentFields) |
| 61 | + { |
| 62 | + switch (component.Kind) |
| 63 | + { |
| 64 | + case BodyComponentKind.Regions: |
| 65 | + regionFields.Add(component.FieldName); |
| 66 | + break; |
| 67 | + case BodyComponentKind.Attribute: |
| 68 | + attributeFields[component.ComponentName] = component.FieldName; |
| 69 | + break; |
| 70 | + case BodyComponentKind.Operand: |
| 71 | + operandFields[component.ComponentName] = component.FieldName; |
| 72 | + break; |
| 73 | + case BodyComponentKind.Result: |
| 74 | + resultFields[component.ComponentName] = component.FieldName; |
| 75 | + break; |
| 76 | + case BodyComponentKind.AttrDict: |
| 77 | + attrDictField ??= component.FieldName; |
| 78 | + break; |
| 79 | + case BodyComponentKind.AttrDictWithKeyword: |
| 80 | + attrDictWithKeywordField ??= component.FieldName; |
| 81 | + break; |
| 82 | + case BodyComponentKind.PropDict: |
| 83 | + propDictField ??= component.FieldName; |
| 84 | + break; |
| 85 | + case BodyComponentKind.Successors: |
| 86 | + successorsField ??= component.FieldName; |
| 87 | + break; |
| 88 | + case BodyComponentKind.Operands: |
| 89 | + operandsField ??= component.FieldName; |
| 90 | + break; |
| 91 | + case BodyComponentKind.Type: |
| 92 | + typeField ??= component.FieldName; |
| 93 | + break; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + return new OperationBodySyntaxConstructionPlan( |
| 98 | + regionFields, |
| 99 | + attributeFields, |
| 100 | + attrDictField, |
| 101 | + attrDictWithKeywordField, |
| 102 | + propDictField, |
| 103 | + operandFields, |
| 104 | + resultFields, |
| 105 | + typeField, |
| 106 | + successorsField, |
| 107 | + operandsField); |
| 108 | + } |
| 109 | +} |
0 commit comments