Esempio n. 1
0
        void GenerateOpCodeOperandKindTables(OpCodeHandlers handlers)
        {
            var filename = CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "OpCodeOperandKinds.g.cs");

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(filename))) {
                writer.WriteFileHeader();
                writer.WriteLineNoIndent($"#if {CSharpConstants.OpCodeInfoDefine}");

                writer.WriteLine($"namespace {CSharpConstants.EncoderNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine("static class OpCodeOperandKinds {");
                    using (writer.Indent()) {
                        Generate(writer, "LegacyOpKinds", null, handlers.Legacy);
                        Generate(writer, "VexOpKinds", CSharpConstants.VexDefine, handlers.Vex);
                        Generate(writer, "XopOpKinds", CSharpConstants.XopDefine, handlers.Xop);
                        Generate(writer, "EvexOpKinds", CSharpConstants.EvexDefine, handlers.Evex);
                        Generate(writer, "MvexOpKinds", CSharpConstants.MvexDefine, handlers.Mvex);
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
                writer.WriteLineNoIndent("#endif");
            }

            void Generate(FileWriter writer, string name, string?define, (EnumValue opCodeOperandKind, OpHandlerKind opHandlerKind, object[] args)[] table)
Esempio n. 2
0
        protected override void GenerateRegisters(string[] registers)
        {
            var filename = CSharpConstants.GetFilename(genTypes, CSharpConstants.FormatterNamespace, "RegistersTable.cs");

            new FileUpdater(TargetLanguage.CSharp, "Registers", filename).Generate(writer => {
                writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}");
                writer.WriteLine("static ReadOnlySpan<byte> GetRegistersData() =>");
                writer.WriteLineNoIndent("#else");
                writer.WriteLine("static byte[] GetRegistersData() =>");
                writer.WriteLineNoIndent("#endif");
                int maxLen = 0;
                using (writer.Indent()) {
                    writer.WriteLine("new byte[] {");
                    using (writer.Indent()) {
                        foreach (var register in registers)
                        {
                            maxLen    = Math.Max(maxLen, register.Length);
                            var bytes = Encoding.UTF8.GetBytes(register);
                            writer.Write($"0x{bytes.Length:X2}");
                            foreach (var b in bytes)
                            {
                                writer.Write($", 0x{b:X2}");
                            }
                            writer.Write(",");
                            writer.WriteCommentLine(register);
                        }
                    }
                    writer.WriteLine("};");
                }
                writer.WriteLine($"const int MaxStringLength = {maxLen};");
                writer.WriteLine($"const int StringsCount = {registers.Length};");
            });
        }
        public void Generate()
        {
            var infos    = MemorySizeInfoTable.Data;
            var filename = Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "MemorySizeExtensions.cs");
            var updater  = new FileUpdater(TargetLanguage.CSharp, "MemorySizeInfoTable", filename);

            updater.Generate(writer => WriteTable(writer, infos));
        }
Esempio n. 4
0
        public void Generate()
        {
            var infos    = genTypes.GetObject <TupleTypeTable>(TypeIds.TupleTypeTable).Data;
            var filename = CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "TupleTypeTable.cs");
            var updater  = new FileUpdater(TargetLanguage.CSharp, "TupleTypeTable", filename);

            updater.Generate(writer => WriteTable(writer, infos));
        }
        public void Generate()
        {
            var infos    = generatorContext.Types.GetObject <TupleTypeTable>(TypeIds.TupleTypeTable).Data;
            var filename = Path.Combine(CSharpConstants.GetDirectory(generatorContext, CSharpConstants.IcedNamespace), "TupleTypeTable.cs");
            var updater  = new FileUpdater(TargetLanguage.CSharp, "TupleTypeTable", filename);

            updater.Generate(writer => WriteTable(writer, infos));
        }
        public void Generate()
        {
            var  defs        = genTypes.GetObject <MemorySizeInfoTable>(TypeIds.MemorySizeInfoTable).Data;
            var  filename    = Path.Combine(CSharpConstants.GetDirectory(genTypes, CSharpConstants.IcedNamespace), "MemorySizeExtensions.cs");
            var  sizeToIndex = new Dictionary <uint, uint>();
            uint index       = 0;

            foreach (var size in defs.Select(a => a.Size).Distinct().OrderBy(a => a))
            {
                sizeToIndex[size] = index++;
            }
            const int    SizeBits      = 5;
            const ushort IsSigned      = 0x8000;
            const uint   SizeMask      = (1U << SizeBits) - 1;
            const int    SizeShift     = 0;
            const int    ElemSizeShift = SizeBits;

            if (sizeToIndex.Count > SizeMask)
            {
                throw new InvalidOperationException();
            }
            new FileUpdater(TargetLanguage.CSharp, "MemorySizeInfoTable", filename).Generate(writer => {
                var memSizeName = genTypes[TypeIds.MemorySize].Name(idConverter);
                foreach (var def in defs)
                {
                    byte b0      = checked ((byte)def.ElementType.Value);
                    ushort value = checked ((ushort)((sizeToIndex[def.Size] << SizeShift) | (sizeToIndex[def.ElementSize] << ElemSizeShift)));
                    if ((value & IsSigned) != 0)
                    {
                        throw new InvalidOperationException();
                    }
                    if (def.IsSigned)
                    {
                        value |= IsSigned;
                    }
                    writer.WriteLine($"0x{b0:X2}, 0x{(byte)value:X2}, 0x{(byte)(value >> 8):X2},");
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "ConstData", filename).Generate(writer => {
                writer.WriteLine($"const ushort {idConverter.Constant(nameof(IsSigned))} = {IsSigned};");
                writer.WriteLine($"const uint {idConverter.Constant(nameof(SizeMask))} = {SizeMask};");
                writer.WriteLine($"const int {idConverter.Constant(nameof(SizeShift))} = {SizeShift};");
                writer.WriteLine($"const int {idConverter.Constant(nameof(ElemSizeShift))} = {ElemSizeShift};");
                writer.WriteLine("var sizes = new ushort[] {");
                using (writer.Indent()) {
                    foreach (var size in sizeToIndex.Select(a => a.Key).OrderBy(a => a))
                    {
                        writer.WriteLine($"{size},");
                    }
                }
                writer.WriteLine("};");
            });
        }
Esempio n. 7
0
        void GenerateGas(MemorySizeDef[] defs)
        {
            var icedConstants         = genTypes.GetConstantsType(TypeIds.IcedConstants);
            var broadcastToKindValues = genTypes[TypeIds.BroadcastToKind].Values;
            var filename = CSharpConstants.GetFilename(genTypes, CSharpConstants.GasFormatterNamespace, "MemorySizes.cs");

            new FileUpdater(TargetLanguage.CSharp, "ConstData", filename).Generate(writer => {
                foreach (var bcst in broadcastToKindValues)
                {
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine($"var empty = new FormatterString(\"\");");
                    }
                    else
                    {
                        var name = bcst.RawName;
                        if (!name.StartsWith("b", StringComparison.Ordinal))
                        {
                            throw new InvalidOperationException();
                        }
                        var s = name.Substring(1);
                        writer.WriteLine($"var {name} = new FormatterString(\"{s}\");");
                    }
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "BcstTo", filename).Generate(writer => {
                int first = (int)icedConstants[IcedConstants.FirstBroadcastMemorySizeName].ValueUInt64;
                for (int i = first; i < defs.Length; i++)
                {
                    writer.WriteByte(checked ((byte)defs[i].BroadcastToKind.Value));
                    writer.WriteLine();
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "BroadcastToKindSwitch", filename).Generate(writer => {
                foreach (var bcst in broadcastToKindValues)
                {
                    writer.Write($"0x{bcst.Value:X2} => ");
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine("empty,");
                    }
                    else
                    {
                        writer.WriteLine($"{bcst.RawName},");
                    }
                }
            });
        }
Esempio n. 8
0
        void GenerateFast(MemorySizeDef[] defs)
        {
            var filename = CSharpConstants.GetFilename(genTypes, CSharpConstants.FastFormatterNamespace, "MemorySizes.cs");

            new FileUpdater(TargetLanguage.CSharp, "MemorySizes", filename).Generate(writer => {
                foreach (var def in defs)
                {
                    writer.WriteByte(checked ((byte)def.Fast.Value));
                    writer.WriteLine();
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "Switch", filename).Generate(writer => {
                foreach (var kw in defs.Select(a => a.Fast).Distinct().OrderBy(a => a.Value))
                {
                    var s = (FastMemoryKeywords)kw.Value == FastMemoryKeywords.None ? string.Empty : (kw.RawName + "_").Replace('_', ' ');
                    writer.WriteLine($"{kw.Value} => \"{s}\",");
                }
            });
        }
Esempio n. 9
0
        public CSharpConstantsGenerator(GeneratorOptions generatorOptions)
        {
            idConverter = CSharpIdentifierConverter.Create();
            docWriter   = new CSharpDocCommentWriter(idConverter);

            var baseDir = CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace);

            toFullFileInfo = new Dictionary <TypeId, FullConstantsFileInfo>();
            toFullFileInfo.Add(TypeIds.IcedConstants, new FullConstantsFileInfo(Path.Combine(baseDir, nameof(TypeIds.IcedConstants) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.DecoderConstants, new FullConstantsFileInfo(Path.Combine(generatorOptions.CSharpTestsDir, "Intel", nameof(TypeIds.DecoderConstants) + ".g.cs"), CSharpConstants.IcedUnitTestsNamespace));

            toPartialFileInfo = new Dictionary <TypeId, PartialConstantsFileInfo?>();
            toPartialFileInfo.Add(TypeIds.DecoderTestParserConstants, new PartialConstantsFileInfo("DecoderTestText", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "DecoderTests", "DecoderTestParser.cs")));
            toPartialFileInfo.Add(TypeIds.InstrInfoConstants, new PartialConstantsFileInfo("InstrInfoConstants", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs")));
            toPartialFileInfo.Add(TypeIds.MiscInstrInfoTestConstants, new PartialConstantsFileInfo("MiscConstants", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.InstructionInfoKeys, new PartialConstantsFileInfo("KeysConstants", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.InstructionInfoDecoderOptions, new PartialConstantsFileInfo("DecoderOptionsConstants", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.RflagsBitsConstants, new PartialConstantsFileInfo("RflagsBitsConstants", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.MiscSectionNames, new PartialConstantsFileInfo("MiscSectionNames", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "MiscTestsData.cs")));
            toPartialFileInfo.Add(TypeIds.OpCodeInfoKeys, new PartialConstantsFileInfo("OpCodeInfoKeys", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "EncoderTests", "OpCodeInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.OpCodeInfoFlags, new PartialConstantsFileInfo("OpCodeInfoFlags", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "EncoderTests", "OpCodeInfoConstants.cs")));
        }
Esempio n. 10
0
        public CSharpConstantsGenerator(GeneratorContext generatorContext)
            : base(generatorContext.Types)
        {
            idConverter      = CSharpIdentifierConverter.Create();
            docWriter        = new CSharpDocCommentWriter(idConverter);
            deprecatedWriter = new CSharpDeprecatedWriter(idConverter);

            var dirs = genTypes.Dirs;

            toFullFileInfo = new Dictionary <TypeId, FullConstantsFileInfo>();
            toFullFileInfo.Add(TypeIds.IcedConstants, new FullConstantsFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.IcedConstants) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.DecoderConstants, new FullConstantsFileInfo(dirs.GetCSharpTestFilename("Intel", nameof(TypeIds.DecoderConstants) + ".g.cs"), CSharpConstants.IcedUnitTestsNamespace));

            toPartialFileInfo = new Dictionary <TypeId, PartialConstantsFileInfo?>();
            toPartialFileInfo.Add(TypeIds.DecoderTestParserConstants, new PartialConstantsFileInfo("DecoderTestText", dirs.GetCSharpTestFilename("Intel", "DecoderTests", "DecoderTestParser.cs")));
            toPartialFileInfo.Add(TypeIds.InstrInfoConstants, new PartialConstantsFileInfo("InstrInfoConstants", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs")));
            toPartialFileInfo.Add(TypeIds.MiscInstrInfoTestConstants, new PartialConstantsFileInfo("MiscConstants", dirs.GetCSharpTestFilename("Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.InstructionInfoKeys, new PartialConstantsFileInfo("KeysConstants", dirs.GetCSharpTestFilename("Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.RflagsBitsConstants, new PartialConstantsFileInfo("RflagsBitsConstants", dirs.GetCSharpTestFilename("Intel", "InstructionInfoTests", "InstructionInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.MiscSectionNames, new PartialConstantsFileInfo("MiscSectionNames", dirs.GetCSharpTestFilename("Intel", "InstructionInfoTests", "MiscTestsData.cs")));
            toPartialFileInfo.Add(TypeIds.OpCodeInfoKeys, new PartialConstantsFileInfo("OpCodeInfoKeys", dirs.GetCSharpTestFilename("Intel", "EncoderTests", "OpCodeInfoConstants.cs")));
            toPartialFileInfo.Add(TypeIds.OpCodeInfoFlags, new PartialConstantsFileInfo("OpCodeInfoFlags", dirs.GetCSharpTestFilename("Intel", "EncoderTests", "OpCodeInfoConstants.cs")));
        }
Esempio n. 11
0
        void GenerateGas(MemorySizeDef[] defs)
        {
            var icedConstants         = genTypes.GetConstantsType(TypeIds.IcedConstants);
            var broadcastToKindValues = genTypes[TypeIds.BroadcastToKind].Values;
            var filename = CSharpConstants.GetFilename(genTypes, CSharpConstants.GasFormatterNamespace, "MemorySizes.cs");

            new FileUpdater(TargetLanguage.CSharp, "ConstData", filename).Generate(writer => {
                foreach (var bcst in broadcastToKindValues)
                {
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine($"var empty = new FormatterString(\"\");");
                    }
                    else
                    {
                        var name = bcst.RawName;
                        if (!name.StartsWith("b", StringComparison.Ordinal))
                        {
                            throw new InvalidOperationException();
                        }
                        var s = name[1..];
                        writer.WriteLine($"var {name} = new FormatterString(\"{s}\");");
                    }
Esempio n. 12
0
        public CSharpEnumsGenerator(GeneratorContext generatorContext)
            : base(generatorContext.Types)
        {
            idConverter      = CSharpIdentifierConverter.Create();
            docWriter        = new CSharpDocCommentWriter(idConverter);
            deprecatedWriter = new CSharpDeprecatedWriter(idConverter);

            var dirs = genTypes.Dirs;

            toFullFileInfo = new();
            toFullFileInfo.Add(TypeIds.Code, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.Code) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.CodeSize, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.CodeSize) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.ConditionCode, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.ConditionCode) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.CpuidFeature, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.CpuidFeature) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.CpuidFeatureInternal, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, nameof(TypeIds.CpuidFeatureInternal) + ".g.cs"), CSharpConstants.InstructionInfoNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.DecoderError, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.DecoderError) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderDefine));
            toFullFileInfo.Add(TypeIds.DecoderOptions, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.DecoderOptions) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.DecoderTestOptions, new FullEnumFileInfo(dirs.GetCSharpTestFilename("Intel", "DecoderTests", nameof(TypeIds.DecoderTestOptions) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.EvexOpCodeHandlerKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.EvexOpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderEvexDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.MvexOpCodeHandlerKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.MvexOpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderMvexDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.HandlerFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.HandlerFlags) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.LegacyHandlerFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.LegacyHandlerFlags) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.MemorySize, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MemorySize) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.LegacyOpCodeHandlerKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.LegacyOpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.PseudoOpsKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.FormatterNamespace, nameof(TypeIds.PseudoOpsKind) + ".g.cs"), CSharpConstants.FormatterNamespace, CSharpConstants.AnyFormatterDefine));
            toFullFileInfo.Add(TypeIds.Register, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.Register) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.SerializedDataKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.SerializedDataKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.TupleType, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.TupleType) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderOrOpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.VexOpCodeHandlerKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.DecoderNamespace, nameof(TypeIds.VexOpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderVexOrXopDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.Mnemonic, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.Mnemonic) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.GasCtorKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.GasFormatterNamespace, "CtorKind.g.cs"), CSharpConstants.GasFormatterNamespace, CSharpConstants.GasFormatterDefine));
            toFullFileInfo.Add(TypeIds.IntelCtorKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IntelFormatterNamespace, "CtorKind.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine));
            toFullFileInfo.Add(TypeIds.MasmCtorKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.MasmFormatterNamespace, "CtorKind.g.cs"), CSharpConstants.MasmFormatterNamespace, CSharpConstants.MasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmCtorKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "CtorKind.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.GasSizeOverride, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.GasFormatterNamespace, "SizeOverride.g.cs"), CSharpConstants.GasFormatterNamespace, CSharpConstants.GasFormatterDefine));
            toFullFileInfo.Add(TypeIds.GasInstrOpInfoFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.GasFormatterNamespace, "InstrOpInfoFlags.g.cs"), CSharpConstants.GasFormatterNamespace, CSharpConstants.GasFormatterDefine, "ushort"));
            toFullFileInfo.Add(TypeIds.IntelSizeOverride, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IntelFormatterNamespace, "SizeOverride.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine));
            toFullFileInfo.Add(TypeIds.IntelBranchSizeInfo, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IntelFormatterNamespace, "BranchSizeInfo.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine));
            toFullFileInfo.Add(TypeIds.IntelInstrOpInfoFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IntelFormatterNamespace, "InstrOpInfoFlags.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine, "ushort"));
            toFullFileInfo.Add(TypeIds.MasmInstrOpInfoFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.MasmFormatterNamespace, "InstrOpInfoFlags.g.cs"), CSharpConstants.MasmFormatterNamespace, CSharpConstants.MasmFormatterDefine, "ushort"));
            toFullFileInfo.Add(TypeIds.NasmSignExtendInfo, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "SignExtendInfo.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmSizeOverride, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "SizeOverride.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmBranchSizeInfo, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "BranchSizeInfo.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmInstrOpInfoFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "InstrOpInfoFlags.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine, "uint"));
            toFullFileInfo.Add(TypeIds.FastFmtFlags, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.FastFormatterNamespace, "FastFmtFlags.g.cs"), CSharpConstants.FastFormatterNamespace, CSharpConstants.FastFormatterDefine, "byte"));
            toFullFileInfo.Add(TypeIds.RoundingControl, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.RoundingControl) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.OpKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.OpKind) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.InstrScale, null);
            toFullFileInfo.Add(TypeIds.VectorLength, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.VectorLength) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderDefine));
            toFullFileInfo.Add(TypeIds.MandatoryPrefixByte, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MandatoryPrefixByte) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderDefine, "uint"));            // 'uint' not 'byte' since it gets zx to uint when OR'ing values
            toFullFileInfo.Add(TypeIds.EncodingKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.EncodingKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderOrInstrInfoOrOpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.FlowControl, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.FlowControl) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.OpCodeOperandKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.OpCodeOperandKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.OpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.MvexEHBit, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MvexEHBit) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.MvexDefine));
            toFullFileInfo.Add(TypeIds.MvexInfoFlags1, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MvexInfoFlags1) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.MvexDefine));
            toFullFileInfo.Add(TypeIds.MvexInfoFlags2, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MvexInfoFlags2) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.MvexDefine));
            toFullFileInfo.Add(TypeIds.RflagsBits, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.RflagsBits) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.OpAccess, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.OpAccess) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.MandatoryPrefix, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MandatoryPrefix) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.OpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.OpCodeTableKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.OpCodeTableKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.OpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.FormatterTextKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.FormatterTextKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.AnyFormatterDefine));
            toFullFileInfo.Add(TypeIds.MemorySizeOptions, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MemorySizeOptions) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.AnyFormatterDefine));
            toFullFileInfo.Add(TypeIds.CodeAsmMemoryOperandSize, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Assembler", "MemoryOperandSize.g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.CodeAssemblerDefine));
            toFullFileInfo.Add(TypeIds.MvexConvFn, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MvexConvFn) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.MvexDefine));
            toFullFileInfo.Add(TypeIds.MvexRegMemConv, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MvexRegMemConv) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.MvexDefine));
            toFullFileInfo.Add(TypeIds.MvexTupleTypeLutKind, new FullEnumFileInfo(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, nameof(TypeIds.MvexTupleTypeLutKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.MvexDefine));

            toPartialFileInfo = new();
            toPartialFileInfo.Add(TypeIds.InstrFlags1, new PartialEnumFileInfo("InstrFlags1", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Instruction.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.MvexInstrFlags, new PartialEnumFileInfo("MvexInstrFlags", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Instruction.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.OpSize, new PartialEnumFileInfo("OpSize", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Decoder.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.StateFlags, new PartialEnumFileInfo("StateFlags", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Decoder.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.ImpliedAccess, new PartialEnumFileInfo("ImpliedAccess", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.RflagsInfo, new PartialEnumFileInfo("RflagsInfo", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo0, new PartialEnumFileInfo("OpInfo0", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo1, new PartialEnumFileInfo("OpInfo1", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo2, new PartialEnumFileInfo("OpInfo2", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo3, new PartialEnumFileInfo("OpInfo3", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo4, new PartialEnumFileInfo("OpInfo4", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.InfoFlags1, new PartialEnumFileInfo("InfoFlags1", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.InfoFlags2, new PartialEnumFileInfo("InfoFlags2", CSharpConstants.GetFilename(genTypes, CSharpConstants.InstructionInfoNamespace, "InfoHandlerFlags.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.MemorySizeFlags, new PartialEnumFileInfo("MemorySizeFlags", dirs.GetCSharpTestFilename("Intel", "InstructionInfoTests", "InstructionInfoConstants.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.RegisterFlags, new PartialEnumFileInfo("RegisterFlags", dirs.GetCSharpTestFilename("Intel", "InstructionInfoTests", "InstructionInfoConstants.cs"), "uint"));

            toPartialFileInfo.Add(TypeIds.LegacyOpCodeTable, new PartialEnumFileInfo("LegacyOpCodeTable", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.VexOpCodeTable, new PartialEnumFileInfo("VexOpCodeTable", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.XopOpCodeTable, new PartialEnumFileInfo("XopOpCodeTable", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.EvexOpCodeTable, new PartialEnumFileInfo("EvexOpCodeTable", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.MvexOpCodeTable, new PartialEnumFileInfo("MvexOpCodeTable", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));

            toPartialFileInfo.Add(TypeIds.FormatterFlowControl, new PartialEnumFileInfo("FormatterFlowControl", CSharpConstants.GetFilename(genTypes, CSharpConstants.FormatterNamespace, "FormatterUtils.cs"), null));
            toPartialFileInfo.Add(TypeIds.GasInstrOpKind, new PartialEnumFileInfo("InstrOpKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.GasFormatterNamespace, "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.IntelInstrOpKind, new PartialEnumFileInfo("InstrOpKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.IntelFormatterNamespace, "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.MasmInstrOpKind, new PartialEnumFileInfo("InstrOpKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.MasmFormatterNamespace, "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.MasmSymbolTestFlags, new PartialEnumFileInfo("SymbolTestFlags", dirs.GetCSharpTestFilename("Intel", "FormatterTests", "Masm", "SymbolOptionsTests.cs"), null));
            toPartialFileInfo.Add(TypeIds.NasmInstrOpKind, new PartialEnumFileInfo("InstrOpKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.NasmMemorySizeInfo, new PartialEnumFileInfo("MemorySizeInfo", CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "InstrInfo.cs"), null));
            toPartialFileInfo.Add(TypeIds.NasmFarMemorySizeInfo, new PartialEnumFileInfo("FarMemorySizeInfo", CSharpConstants.GetFilename(genTypes, CSharpConstants.NasmFormatterNamespace, "InstrInfo.cs"), null));
            toPartialFileInfo.Add(TypeIds.NumberBase, new PartialEnumFileInfo("NumberBase", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), null));

            toPartialFileInfo.Add(TypeIds.DisplSize, new PartialEnumFileInfo("DisplSize", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.ImmSize, new PartialEnumFileInfo("ImmSize", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.EncoderFlags, new PartialEnumFileInfo("EncoderFlags", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.EncFlags1, new PartialEnumFileInfo("EncFlags1", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.EncFlags2, new PartialEnumFileInfo("EncFlags2", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.EncFlags3, new PartialEnumFileInfo("EncFlags3", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.OpCodeInfoFlags1, new PartialEnumFileInfo("OpCodeInfoFlags1", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "OpCodeInfosEnums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.OpCodeInfoFlags2, new PartialEnumFileInfo("OpCodeInfoFlags2", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "OpCodeInfosEnums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.DecOptionValue, null);
            toPartialFileInfo.Add(TypeIds.InstrStrFmtOption, new PartialEnumFileInfo("InstrStrFmtOption", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "OpCodeInfosEnums.cs"), null));
            toPartialFileInfo.Add(TypeIds.WBit, new PartialEnumFileInfo("WBit", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.LBit, new PartialEnumFileInfo("LBit", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.LKind, new PartialEnumFileInfo("LKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.EncoderNamespace, "OpCodeFormatter.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.RepPrefixKind, new PartialEnumFileInfo("RepPrefixKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Instruction.Create.cs"), null));
            toPartialFileInfo.Add(TypeIds.RelocKind, new PartialEnumFileInfo("RelocKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "BlockEncoder.cs"), null));
            toPartialFileInfo.Add(TypeIds.BlockEncoderOptions, new PartialEnumFileInfo("BlockEncoderOptions", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "BlockEncoder.cs"), null));
            toPartialFileInfo.Add(TypeIds.FormatMnemonicOptions, new PartialEnumFileInfo("FormatMnemonicOptions", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "Formatter.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.PrefixKind, new PartialEnumFileInfo("PrefixKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOutput.cs"), null));
            toPartialFileInfo.Add(TypeIds.DecoratorKind, new PartialEnumFileInfo("DecoratorKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOutput.cs"), null));
            toPartialFileInfo.Add(TypeIds.NumberKind, new PartialEnumFileInfo("NumberKind", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOutput.cs"), null));
            toPartialFileInfo.Add(TypeIds.SymbolFlags, new PartialEnumFileInfo("SymbolFlags", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "ISymbolResolver.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.CC_b, new PartialEnumFileInfo("CC_b", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_ae, new PartialEnumFileInfo("CC_ae", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_e, new PartialEnumFileInfo("CC_e", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_ne, new PartialEnumFileInfo("CC_ne", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_be, new PartialEnumFileInfo("CC_be", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_a, new PartialEnumFileInfo("CC_a", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_p, new PartialEnumFileInfo("CC_p", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_np, new PartialEnumFileInfo("CC_np", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_l, new PartialEnumFileInfo("CC_l", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_ge, new PartialEnumFileInfo("CC_ge", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_le, new PartialEnumFileInfo("CC_le", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.CC_g, new PartialEnumFileInfo("CC_g", CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, "FormatterOptions.cs"), "byte"));

            toPartialFileInfo.Add(TypeIds.OptionsProps, new PartialEnumFileInfo("OptionsProps", dirs.GetCSharpTestFilename("Intel", "FormatterTests", "OptionsProps.cs"), null));

            toPartialFileInfo.Add(TypeIds.TestInstrFlags, new PartialEnumFileInfo("TestInstrFlags", dirs.GetCSharpTestFilename("Intel", "AssemblerTests", "AssemblerTestsBase.cs"), null));
        }
        public void Generate()
        {
            var          data      = InstructionOpCountsTable.Table;
            const string ClassName = "InstructionOpCounts";

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), ClassName + ".g.cs")))) {
                writer.WriteFileHeader();

                writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine($"static class {ClassName} {{");
                    using (writer.Indent()) {
                        writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}");
                        writer.WriteLine($"internal static System.ReadOnlySpan<byte> OpCount => new byte[{IcedConstantsType.Instance.Name(idConverter)}.{IcedConstantsType.Instance[IcedConstants.NumberOfCodeValuesName].Name(idConverter)}] {{");
                        writer.WriteLineNoIndent("#else");
                        writer.WriteLine($"internal static readonly byte[] OpCount = new byte[{IcedConstantsType.Instance.Name(idConverter)}.{IcedConstantsType.Instance[IcedConstants.NumberOfCodeValuesName].Name(idConverter)}] {{");
                        writer.WriteLineNoIndent("#endif");
                        using (writer.Indent()) {
                            foreach (var d in data)
                            {
                                writer.WriteLine($"{d.count},// {d.codeEnum.Name(idConverter)}");
                            }
                        }
                        writer.WriteLine("};");
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
            }
        }
Esempio n. 14
0
        void GenerateMasm(MemorySizeDef[] defs)
        {
            var  filename     = CSharpConstants.GetFilename(genTypes, CSharpConstants.MasmFormatterNamespace, "MemorySizes.cs");
            var  masmKeywords = genTypes[TypeIds.MasmMemoryKeywords].Values;
            var  sizeToIndex  = new Dictionary <uint, uint>();
            uint index        = 0;

            foreach (var size in defs.Select(a => a.Size).Distinct().OrderBy(a => a))
            {
                sizeToIndex[size] = index++;
            }
            const int SizeKindShift      = 5;
            const int MemoryKeywordsMask = 0x1F;

            new FileUpdater(TargetLanguage.CSharp, "ConstData", filename).Generate(writer => {
                writer.WriteLine($"const int {idConverter.Constant(nameof(SizeKindShift))} = {SizeKindShift};");
                writer.WriteLine($"const int {idConverter.Constant(nameof(MemoryKeywordsMask))} = {MemoryKeywordsMask};");
                var created = new HashSet <string>(StringComparer.Ordinal);
                foreach (var keywords in masmKeywords.Select(a => a.RawName).Concat(new[] { "mmword_ptr" }))
                {
                    if (keywords == nameof(MasmMemoryKeywords.None))
                    {
                        continue;
                    }
                    var parts = keywords.Split('_');
                    foreach (var kw in parts)
                    {
                        if (created.Add(kw))
                        {
                            writer.WriteLine($"var {EscapeKeyword(kw)} = new FormatterString(\"{kw}\");");
                        }
                    }
                    writer.WriteLine($"var {keywords} = new[] {{ {string.Join(", ", parts.Select(a => EscapeKeyword(a)))} }};");
                }
                writer.WriteLine("var sizes = new ushort[] {");
                using (writer.Indent()) {
                    foreach (var size in sizeToIndex.Select(a => a.Key).OrderBy(a => a))
                    {
                        writer.WriteLine($"{size},");
                    }
                }
                writer.WriteLine("};");
            });
            new FileUpdater(TargetLanguage.CSharp, "MemorySizes", filename).Generate(writer => {
                foreach (var def in defs)
                {
                    uint value = def.Masm.Value | (sizeToIndex[def.Size] << SizeKindShift);
                    if (value > 0xFFFF || def.Masm.Value > MemoryKeywordsMask)
                    {
                        throw new InvalidOperationException();
                    }
                    writer.WriteLine($"0x{value:X4},");
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "MemoryKeywordsSwitch", filename).Generate(writer => {
                foreach (var kw in masmKeywords)
                {
                    writer.Write($"0x{kw.Value:X2} => ");
                    if ((MasmMemoryKeywords)kw.Value == MasmMemoryKeywords.None)
                    {
                        writer.WriteLine("Array2.Empty<FormatterString>(),");
                    }
                    else
                    {
                        writer.WriteLine($"{kw.RawName},");
                    }
                }
            });
        }
Esempio n. 15
0
        public void Generate()
        {
            var          data        = InstructionMemorySizesTable.Table;
            const string ClassName   = "InstructionMemorySizes";
            var          memSizeName = MemorySizeEnum.Instance.Name(idConverter);

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), ClassName + ".g.cs")))) {
                writer.WriteFileHeader();

                writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine($"static class {ClassName} {{");
                    using (writer.Indent()) {
                        writer.WriteCommentLine("0 = memory size");
                        writer.WriteCommentLine("1 = broadcast memory size");
                        writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}");
                        writer.WriteLine($"internal static System.ReadOnlySpan<byte> Sizes => new byte[{IcedConstantsType.Instance.Name(idConverter)}.{IcedConstantsType.Instance[IcedConstants.NumberOfCodeValuesName].Name(idConverter)} * 2] {{");
                        writer.WriteLineNoIndent("#else");
                        writer.WriteLine($"internal static readonly byte[] Sizes = new byte[{IcedConstantsType.Instance.Name(idConverter)}.{IcedConstantsType.Instance[IcedConstants.NumberOfCodeValuesName].Name(idConverter)} * 2] {{");
                        writer.WriteLineNoIndent("#endif");
                        using (writer.Indent()) {
                            foreach (var d in data)
                            {
                                if (d.mem.Value > byte.MaxValue)
                                {
                                    throw new InvalidOperationException();
                                }
                                string value;
                                if (d.mem.Value == 0)
                                {
                                    value = "0";
                                }
                                else
                                {
                                    value = $"(byte){memSizeName}.{d.mem.Name(idConverter)}";
                                }
                                writer.WriteLine($"{value},// {d.codeEnum.Name(idConverter)}");
                            }
                            foreach (var d in data)
                            {
                                if (d.bcst.Value > byte.MaxValue)
                                {
                                    throw new InvalidOperationException();
                                }
                                string value;
                                if (d.bcst.Value == 0)
                                {
                                    value = "0";
                                }
                                else
                                {
                                    value = $"(byte){memSizeName}.{d.bcst.Name(idConverter)}";
                                }
                                writer.WriteLine($"{value},// {d.codeEnum.Name(idConverter)}");
                            }
                        }
                        writer.WriteLine("};");
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
            }
        }
Esempio n. 16
0
        public CSharpEnumsGenerator(GeneratorOptions generatorOptions)
        {
            idConverter = CSharpIdentifierConverter.Create();
            docWriter   = new CSharpDocCommentWriter(idConverter);

            toFullFileInfo = new Dictionary <TypeId, FullEnumFileInfo>();
            toFullFileInfo.Add(TypeIds.Code, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.Code) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.CodeSize, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.CodeSize) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.ConditionCode, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.ConditionCode) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.CpuidFeature, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.CpuidFeature) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.CpuidFeatureInternal, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), nameof(TypeIds.CpuidFeatureInternal) + ".g.cs"), CSharpConstants.InstructionInfoNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.DecoderOptions, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.DecoderOptions) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.EvexOpCodeHandlerKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.DecoderNamespace), nameof(TypeIds.EvexOpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.HandlerFlags, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.DecoderNamespace), nameof(TypeIds.HandlerFlags) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.LegacyHandlerFlags, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.DecoderNamespace), nameof(TypeIds.LegacyHandlerFlags) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "uint"));
            toFullFileInfo.Add(TypeIds.MemorySize, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.MemorySize) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.OpCodeHandlerKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.DecoderNamespace), nameof(TypeIds.OpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.PseudoOpsKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.FormatterNamespace), nameof(TypeIds.PseudoOpsKind) + ".g.cs"), CSharpConstants.FormatterNamespace, CSharpConstants.AnyFormatterDefine));
            toFullFileInfo.Add(TypeIds.Register, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.Register) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.SerializedDataKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.DecoderNamespace), nameof(TypeIds.SerializedDataKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.TupleType, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.TupleType) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderDefine));
            toFullFileInfo.Add(TypeIds.VexOpCodeHandlerKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.DecoderNamespace), nameof(TypeIds.VexOpCodeHandlerKind) + ".g.cs"), CSharpConstants.DecoderNamespace, CSharpConstants.DecoderDefine, baseType: "byte"));
            toFullFileInfo.Add(TypeIds.Mnemonic, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.Mnemonic) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.GasCtorKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.GasFormatterNamespace), "CtorKind.g.cs"), CSharpConstants.GasFormatterNamespace, CSharpConstants.GasFormatterDefine));
            toFullFileInfo.Add(TypeIds.IntelCtorKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IntelFormatterNamespace), "CtorKind.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine));
            toFullFileInfo.Add(TypeIds.MasmCtorKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.MasmFormatterNamespace), "CtorKind.g.cs"), CSharpConstants.MasmFormatterNamespace, CSharpConstants.MasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmCtorKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "CtorKind.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.GasSizeOverride, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.GasFormatterNamespace), "SizeOverride.g.cs"), CSharpConstants.GasFormatterNamespace, CSharpConstants.GasFormatterDefine));
            toFullFileInfo.Add(TypeIds.GasInstrOpInfoFlags, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.GasFormatterNamespace), "InstrOpInfoFlags.g.cs"), CSharpConstants.GasFormatterNamespace, CSharpConstants.GasFormatterDefine, "ushort"));
            toFullFileInfo.Add(TypeIds.IntelSizeOverride, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IntelFormatterNamespace), "SizeOverride.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine));
            toFullFileInfo.Add(TypeIds.IntelBranchSizeInfo, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IntelFormatterNamespace), "BranchSizeInfo.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine));
            toFullFileInfo.Add(TypeIds.IntelInstrOpInfoFlags, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IntelFormatterNamespace), "InstrOpInfoFlags.g.cs"), CSharpConstants.IntelFormatterNamespace, CSharpConstants.IntelFormatterDefine, "ushort"));
            toFullFileInfo.Add(TypeIds.MasmInstrOpInfoFlags, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.MasmFormatterNamespace), "InstrOpInfoFlags.g.cs"), CSharpConstants.MasmFormatterNamespace, CSharpConstants.MasmFormatterDefine, "ushort"));
            toFullFileInfo.Add(TypeIds.NasmSignExtendInfo, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "SignExtendInfo.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmSizeOverride, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "SizeOverride.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmBranchSizeInfo, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "BranchSizeInfo.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine));
            toFullFileInfo.Add(TypeIds.NasmInstrOpInfoFlags, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "InstrOpInfoFlags.g.cs"), CSharpConstants.NasmFormatterNamespace, CSharpConstants.NasmFormatterDefine, "uint"));
            toFullFileInfo.Add(TypeIds.RoundingControl, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.RoundingControl) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.OpKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.OpKind) + ".g.cs"), CSharpConstants.IcedNamespace));
            toFullFileInfo.Add(TypeIds.VectorLength, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.VectorLength) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderDefine));
            toFullFileInfo.Add(TypeIds.MandatoryPrefixByte, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.MandatoryPrefixByte) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderDefine, "uint"));            // 'uint' not 'byte' since it gets zx to uint when OR'ing values
            toFullFileInfo.Add(TypeIds.EncodingKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.EncodingKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.DecoderOrEncoderOrInstrInfoDefine));
            toFullFileInfo.Add(TypeIds.FlowControl, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.FlowControl) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.OpCodeOperandKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.OpCodeOperandKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.OpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.RflagsBits, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.RflagsBits) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.OpAccess, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.OpAccess) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.InstructionInfoDefine));
            toFullFileInfo.Add(TypeIds.MandatoryPrefix, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.MandatoryPrefix) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.OpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.OpCodeTableKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.OpCodeTableKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.OpCodeInfoDefine));
            toFullFileInfo.Add(TypeIds.FormatterTextKind, new FullEnumFileInfo(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), nameof(TypeIds.FormatterTextKind) + ".g.cs"), CSharpConstants.IcedNamespace, CSharpConstants.AnyFormatterDefine));

            toPartialFileInfo = new Dictionary <TypeId, PartialEnumFileInfo>();
            toPartialFileInfo.Add(TypeIds.Instruction_MemoryFlags, new PartialEnumFileInfo("MemoryFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Instruction.cs"), "ushort"));
            toPartialFileInfo.Add(TypeIds.Instruction_OpKindFlags, new PartialEnumFileInfo("OpKindFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Instruction.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.Instruction_CodeFlags, new PartialEnumFileInfo("CodeFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Instruction.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.OpSize, new PartialEnumFileInfo("OpSize", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Decoder.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.StateFlags, new PartialEnumFileInfo("StateFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Decoder.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.CodeInfo, new PartialEnumFileInfo("CodeInfo", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.RflagsInfo, new PartialEnumFileInfo("RflagsInfo", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo0, new PartialEnumFileInfo("OpInfo0", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo1, new PartialEnumFileInfo("OpInfo1", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo2, new PartialEnumFileInfo("OpInfo2", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo3, new PartialEnumFileInfo("OpInfo3", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpInfo4, new PartialEnumFileInfo("OpInfo4", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), null));
            toPartialFileInfo.Add(TypeIds.InfoFlags1, new PartialEnumFileInfo("InfoFlags1", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.InfoFlags2, new PartialEnumFileInfo("InfoFlags2", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.InstructionInfoNamespace), "InfoHandlerFlags.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.MemorySizeFlags, new PartialEnumFileInfo("MemorySizeFlags", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "InstructionInfoConstants.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.RegisterFlags, new PartialEnumFileInfo("RegisterFlags", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "InstructionInfoTests", "InstructionInfoConstants.cs"), "uint"));

            toPartialFileInfo.Add(TypeIds.LegacyOpCodeTable, new PartialEnumFileInfo("LegacyOpCodeTable", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.VexOpCodeTable, new PartialEnumFileInfo("VexOpCodeTable", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.XopOpCodeTable, new PartialEnumFileInfo("XopOpCodeTable", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.EvexOpCodeTable, new PartialEnumFileInfo("EvexOpCodeTable", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.Encodable, new PartialEnumFileInfo("Encodable", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.OpCodeHandlerFlags, new PartialEnumFileInfo("OpCodeHandlerFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.LegacyOpKind, new PartialEnumFileInfo("LegacyOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.VexOpKind, new PartialEnumFileInfo("VexOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.XopOpKind, new PartialEnumFileInfo("XopOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.EvexOpKind, new PartialEnumFileInfo("EvexOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "byte"));

            toPartialFileInfo.Add(TypeIds.FormatterFlowControl, new PartialEnumFileInfo("FormatterFlowControl", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "FormatterUtils.cs"), null));
            toPartialFileInfo.Add(TypeIds.GasInstrOpKind, new PartialEnumFileInfo("InstrOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.GasFormatterNamespace), "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.IntelInstrOpKind, new PartialEnumFileInfo("InstrOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IntelFormatterNamespace), "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.MasmInstrOpKind, new PartialEnumFileInfo("InstrOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.MasmFormatterNamespace), "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.MasmSymbolTestFlags, new PartialEnumFileInfo("SymbolTestFlags", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "FormatterTests", "Masm", "SymbolOptionsTests.cs"), null));
            toPartialFileInfo.Add(TypeIds.NasmInstrOpKind, new PartialEnumFileInfo("InstrOpKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "InstrInfo.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.NasmMemorySizeInfo, new PartialEnumFileInfo("MemorySizeInfo", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "InstrInfo.cs"), null));
            toPartialFileInfo.Add(TypeIds.NasmFarMemorySizeInfo, new PartialEnumFileInfo("FarMemorySizeInfo", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.NasmFormatterNamespace), "InstrInfo.cs"), null));
            toPartialFileInfo.Add(TypeIds.NumberBase, new PartialEnumFileInfo("NumberBase", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "FormatterOptions.cs"), null));
            toPartialFileInfo.Add(TypeIds.MemorySizeOptions, new PartialEnumFileInfo("MemorySizeOptions", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "FormatterOptions.cs"), null));

            toPartialFileInfo.Add(TypeIds.OperandSize, new PartialEnumFileInfo("OperandSize", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.AddressSize, new PartialEnumFileInfo("AddressSize", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.VexVectorLength, new PartialEnumFileInfo("VexVectorLength", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.XopVectorLength, new PartialEnumFileInfo("XopVectorLength", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.EvexVectorLength, new PartialEnumFileInfo("EvexVectorLength", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.DisplSize, new PartialEnumFileInfo("DisplSize", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.ImmSize, new PartialEnumFileInfo("ImmSize", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.EncoderFlags, new PartialEnumFileInfo("EncoderFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.EncFlags1, new PartialEnumFileInfo("EncFlags1", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.LegacyFlags3, new PartialEnumFileInfo("LegacyFlags3", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.VexFlags3, new PartialEnumFileInfo("VexFlags3", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.XopFlags3, new PartialEnumFileInfo("XopFlags3", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.EvexFlags3, new PartialEnumFileInfo("EvexFlags3", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.AllowedPrefixes, new PartialEnumFileInfo("AllowedPrefixes", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), null));
            toPartialFileInfo.Add(TypeIds.LegacyFlags, new PartialEnumFileInfo("LegacyFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.VexFlags, new PartialEnumFileInfo("VexFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.XopFlags, new PartialEnumFileInfo("XopFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.EvexFlags, new PartialEnumFileInfo("EvexFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.D3nowFlags, new PartialEnumFileInfo("D3nowFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.WBit, new PartialEnumFileInfo("WBit", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "Enums.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.LKind, new PartialEnumFileInfo("LKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.EncoderNamespace), "OpCodeFormatter.cs"), "byte"));
            toPartialFileInfo.Add(TypeIds.OpCodeFlags, new PartialEnumFileInfo("Flags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "OpCodeInfo.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.RepPrefixKind, new PartialEnumFileInfo("RepPrefixKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Instruction.Create.cs"), null));
            toPartialFileInfo.Add(TypeIds.RelocKind, new PartialEnumFileInfo("RelocKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "BlockEncoder.cs"), null));
            toPartialFileInfo.Add(TypeIds.BlockEncoderOptions, new PartialEnumFileInfo("BlockEncoderOptions", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "BlockEncoder.cs"), null));
            toPartialFileInfo.Add(TypeIds.FormatMnemonicOptions, new PartialEnumFileInfo("FormatMnemonicOptions", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "Formatter.cs"), "uint"));
            toPartialFileInfo.Add(TypeIds.PrefixKind, new PartialEnumFileInfo("PrefixKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "FormatterOutput.cs"), null));
            toPartialFileInfo.Add(TypeIds.DecoratorKind, new PartialEnumFileInfo("DecoratorKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "FormatterOutput.cs"), null));
            toPartialFileInfo.Add(TypeIds.NumberKind, new PartialEnumFileInfo("NumberKind", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "FormatterOutput.cs"), null));
            toPartialFileInfo.Add(TypeIds.SymbolFlags, new PartialEnumFileInfo("SymbolFlags", Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), "ISymbolResolver.cs"), "uint"));

            toPartialFileInfo.Add(TypeIds.OptionsProps, new PartialEnumFileInfo("OptionsProps", Path.Combine(generatorOptions.CSharpTestsDir, "Intel", "FormatterTests", "OptionsTests.cs"), null));
        }
 public string GetFilename(GeneratorContext generatorContext) =>
 Path.Combine(CSharpConstants.GetDirectory(generatorContext, @namespace), "InstrInfos.g.cs");
        public void Generate()
        {
            var          data         = MnemonicsTable.Table;
            const string ClassName    = "MnemonicUtilsData";
            var          mnemonicName = MnemonicEnum.Instance.Name(idConverter);

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(Path.Combine(CSharpConstants.GetDirectory(generatorOptions, CSharpConstants.IcedNamespace), ClassName + ".g.cs")))) {
                writer.WriteFileHeader();

                writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine($"static class {ClassName} {{");
                    using (writer.Indent()) {
                        writer.WriteLine($"internal static readonly ushort[] toMnemonic = new ushort[{IcedConstantsType.Instance.Name(idConverter)}.{IcedConstantsType.Instance[IcedConstants.NumberOfCodeValuesName].Name(idConverter)}] {{");
                        using (writer.Indent()) {
                            foreach (var d in data)
                            {
                                if (d.mnemonicEnum.Value > ushort.MaxValue)
                                {
                                    throw new InvalidOperationException();
                                }
                                writer.WriteLine($"(ushort){mnemonicName}.{d.mnemonicEnum.Name(idConverter)},// {d.codeEnum.Name(idConverter)}");
                            }
                        }
                        writer.WriteLine("};");
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
            }
        }
Esempio n. 19
0
        void GenerateNasm(MemorySizeDef[] defs)
        {
            var icedConstants         = genTypes.GetConstantsType(TypeIds.IcedConstants);
            var broadcastToKindValues = genTypes[TypeIds.BroadcastToKind].Values;
            var filename     = Path.Combine(CSharpConstants.GetDirectory(generatorContext, CSharpConstants.NasmFormatterNamespace), "MemorySizes.cs");
            var nasmKeywords = genTypes[TypeIds.NasmMemoryKeywords].Values;

            new FileUpdater(TargetLanguage.CSharp, "ConstData", filename).Generate(writer => {
                foreach (var kw in nasmKeywords)
                {
                    if ((NasmMemoryKeywords)kw.Value == NasmMemoryKeywords.None)
                    {
                        continue;
                    }
                    writer.WriteLine($"var {EscapeKeyword(kw.RawName)} = new FormatterString(\"{kw.RawName}\");");
                }
                foreach (var bcst in broadcastToKindValues)
                {
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine($"var empty = new FormatterString(\"\");");
                    }
                    else
                    {
                        var name = bcst.RawName;
                        if (!name.StartsWith("b", StringComparison.Ordinal))
                        {
                            throw new InvalidOperationException();
                        }
                        var s = name.Substring(1);
                        writer.WriteLine($"var {name} = new FormatterString(\"{s}\");");
                    }
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "MemorySizes", filename).Generate(writer => {
                foreach (var def in defs)
                {
                    writer.WriteByte(checked ((byte)def.Nasm.Value));
                    writer.WriteLine();
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "BcstTo", filename).Generate(writer => {
                int first = (int)icedConstants[IcedConstants.FirstBroadcastMemorySizeName].ValueUInt64;
                for (int i = first; i < defs.Length; i++)
                {
                    writer.WriteByte(checked ((byte)defs[i].BroadcastToKind.Value));
                    writer.WriteLine();
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "MemoryKeywordsSwitch", filename).Generate(writer => {
                foreach (var kw in nasmKeywords)
                {
                    writer.Write($"0x{kw.Value:X2} => ");
                    if ((NasmMemoryKeywords)kw.Value == NasmMemoryKeywords.None)
                    {
                        writer.WriteLine("empty,");
                    }
                    else
                    {
                        writer.WriteLine($"{EscapeKeyword(kw.RawName)},");
                    }
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "BroadcastToKindSwitch", filename).Generate(writer => {
                foreach (var bcst in broadcastToKindValues)
                {
                    writer.Write($"0x{bcst.Value:X2} => ");
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine("empty,");
                    }
                    else
                    {
                        writer.WriteLine($"{bcst.RawName},");
                    }
                }
            });
        }
 public override string GetFilename(GenTypes genTypes) =>
 CSharpConstants.GetFilename(genTypes, @namespace, "InstrInfos.g.cs");
Esempio n. 21
0
        public void Generate()
        {
            var          icedConstants = genTypes.GetConstantsType(TypeIds.IcedConstants);
            var          defs          = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs;
            const string ClassName     = "InstructionOpCounts";

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, ClassName + ".g.cs")))) {
                writer.WriteFileHeader();

                writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine($"static class {ClassName} {{");
                    using (writer.Indent()) {
                        writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}");
                        writer.WriteLine($"internal static System.ReadOnlySpan<byte> OpCount => new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)}] {{");
                        writer.WriteLineNoIndent("#else");
                        writer.WriteLine($"internal static readonly byte[] OpCount = new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)}] {{");
                        writer.WriteLineNoIndent("#endif");
                        using (writer.Indent()) {
                            foreach (var def in defs)
                            {
                                writer.WriteLine($"{def.OpCount},// {def.Code.Name(idConverter)}");
                            }
                        }
                        writer.WriteLine("};");
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
            }
        }
        public void Generate()
        {
            var          icedConstants = genTypes.GetConstantsType(TypeIds.IcedConstants);
            var          defs          = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs;
            const string ClassName     = "MnemonicUtilsData";
            var          mnemonicName  = genTypes[TypeIds.Mnemonic].Name(idConverter);

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, ClassName + ".g.cs")))) {
                writer.WriteFileHeader();

                writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine($"static class {ClassName} {{");
                    using (writer.Indent()) {
                        writer.WriteLine($"internal static readonly ushort[] toMnemonic = new ushort[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)}] {{");
                        using (writer.Indent()) {
                            foreach (var def in defs)
                            {
                                if (def.Mnemonic.Value > ushort.MaxValue)
                                {
                                    throw new InvalidOperationException();
                                }
                                writer.WriteLine($"(ushort){mnemonicName}.{def.Mnemonic.Name(idConverter)},// {def.Code.Name(idConverter)}");
                            }
                        }
                        writer.WriteLine("};");
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
            }
        }
Esempio n. 23
0
        void GenerateIntel(MemorySizeDef[] defs)
        {
            var       broadcastToKindValues = genTypes[TypeIds.BroadcastToKind].Values;
            var       filename             = CSharpConstants.GetFilename(genTypes, CSharpConstants.IntelFormatterNamespace, "MemorySizes.cs");
            var       intelKeywords        = genTypes[TypeIds.IntelMemoryKeywords].Values;
            const int BroadcastToKindShift = 5;
            const int MemoryKeywordsMask   = 0x1F;

            new FileUpdater(TargetLanguage.CSharp, "ConstData", filename).Generate(writer => {
                writer.WriteLine($"const int {idConverter.Constant(nameof(BroadcastToKindShift))} = {BroadcastToKindShift};");
                writer.WriteLine($"const int {idConverter.Constant(nameof(MemoryKeywordsMask))} = {MemoryKeywordsMask};");
                var created = new HashSet <string>(StringComparer.Ordinal);
                foreach (var keywords in intelKeywords.Select(a => a.RawName))
                {
                    if (keywords == nameof(IntelMemoryKeywords.None))
                    {
                        continue;
                    }
                    var parts = keywords.Split('_');
                    foreach (var kw in parts)
                    {
                        if (created.Add(kw))
                        {
                            writer.WriteLine($"var {EscapeKeyword(kw)} = new FormatterString(\"{kw}\");");
                        }
                    }
                    writer.WriteLine($"var {keywords} = new[] {{ {string.Join(", ", parts.Select(a => EscapeKeyword(a)))} }};");
                }
                foreach (var bcst in broadcastToKindValues)
                {
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine($"var empty = new FormatterString(\"\");");
                    }
                    else
                    {
                        var name = bcst.RawName;
                        if (!name.StartsWith("b", StringComparison.Ordinal))
                        {
                            throw new InvalidOperationException();
                        }
                        var s = name.Substring(1);
                        writer.WriteLine($"var {name} = new FormatterString(\"{s}\");");
                    }
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "MemorySizes", filename).Generate(writer => {
                foreach (var def in defs)
                {
                    uint value = def.Intel.Value | (def.BroadcastToKind.Value << BroadcastToKindShift);
                    if (value > 0xFF || def.Intel.Value > MemoryKeywordsMask)
                    {
                        throw new InvalidOperationException();
                    }
                    writer.WriteByte(checked ((byte)value));
                    writer.WriteLine();
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "MemoryKeywordsSwitch", filename).Generate(writer => {
                foreach (var kw in intelKeywords)
                {
                    writer.Write($"0x{kw.Value:X2} => ");
                    if ((IntelMemoryKeywords)kw.Value == IntelMemoryKeywords.None)
                    {
                        writer.WriteLine("Array2.Empty<FormatterString>(),");
                    }
                    else
                    {
                        writer.WriteLine($"{kw.RawName},");
                    }
                }
            });
            new FileUpdater(TargetLanguage.CSharp, "BroadcastToKindSwitch", filename).Generate(writer => {
                foreach (var bcst in broadcastToKindValues)
                {
                    writer.Write($"0x{bcst.Value:X2} => ");
                    if ((BroadcastToKind)bcst.Value == BroadcastToKind.None)
                    {
                        writer.WriteLine("empty,");
                    }
                    else
                    {
                        writer.WriteLine($"{bcst.RawName},");
                    }
                }
            });
        }
        public void Generate()
        {
            var          icedConstants = genTypes.GetConstantsType(TypeIds.IcedConstants);
            var          defs          = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs;
            const string ClassName     = "InstructionMemorySizes";
            var          memSizeName   = genTypes[TypeIds.MemorySize].Name(idConverter);

            using (var writer = new FileWriter(TargetLanguage.CSharp, FileUtils.OpenWrite(CSharpConstants.GetFilename(genTypes, CSharpConstants.IcedNamespace, ClassName + ".g.cs")))) {
                writer.WriteFileHeader();

                writer.WriteLine($"namespace {CSharpConstants.IcedNamespace} {{");
                using (writer.Indent()) {
                    writer.WriteLine($"static class {ClassName} {{");
                    using (writer.Indent()) {
                        writer.WriteCommentLine("0 = memory size");
                        writer.WriteCommentLine("1 = broadcast memory size");
                        writer.WriteLineNoIndent($"#if {CSharpConstants.HasSpanDefine}");
                        writer.WriteLine($"internal static System.ReadOnlySpan<byte> Sizes => new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)} * 2] {{");
                        writer.WriteLineNoIndent("#else");
                        writer.WriteLine($"internal static readonly byte[] Sizes = new byte[{icedConstants.Name(idConverter)}.{icedConstants[IcedConstants.GetEnumCountName(TypeIds.Code)].Name(idConverter)} * 2] {{");
                        writer.WriteLineNoIndent("#endif");
                        using (writer.Indent()) {
                            foreach (var def in defs)
                            {
                                if (def.Memory.Value > byte.MaxValue)
                                {
                                    throw new InvalidOperationException();
                                }
                                string value;
                                if (def.Memory.Value == 0)
                                {
                                    value = "0";
                                }
                                else
                                {
                                    value = $"(byte){memSizeName}.{def.Memory.Name(idConverter)}";
                                }
                                writer.WriteLine($"{value},// {def.Code.Name(idConverter)}");
                            }
                            foreach (var def in defs)
                            {
                                if (def.MemoryBroadcast.Value > byte.MaxValue)
                                {
                                    throw new InvalidOperationException();
                                }
                                string value;
                                if (def.MemoryBroadcast.Value == 0)
                                {
                                    value = "0";
                                }
                                else
                                {
                                    value = $"(byte){memSizeName}.{def.MemoryBroadcast.Name(idConverter)}";
                                }
                                writer.WriteLine($"{value},// {def.Code.Name(idConverter)}");
                            }
                        }
                        writer.WriteLine("};");
                    }
                    writer.WriteLine("}");
                }
                writer.WriteLine("}");
            }
        }
 public override string GetFilename(GeneratorContext generatorContext) =>
 Path.Combine(CSharpConstants.GetDirectory(generatorContext, @namespace), "FmtData.g.cs");