示例#1
0
        public static void AddComments(GenTypes genTypes, string unitTestDir)
        {
            var        removed      = genTypes.GetObject <HashSet <EnumValue> >(TypeIds.RemovedCodeValues).Select(a => a.RawName).ToHashSet();
            var        docs         = new Dictionary <string, string>(StringComparer.Ordinal);
            bool       checkedIt    = false;
            const char sepChar      = '|';
            var        defs         = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs;
            var        toInstrInfo  = defs.ToDictionary(a => a.OpCodeInfo.Code.RawName, a => a.InstrInfo, StringComparer.Ordinal);
            var        toOpCodeInfo = defs.ToDictionary(a => a.OpCodeInfo.Code.RawName, a => a.OpCodeInfo, StringComparer.Ordinal);
            var        sb           = new StringBuilder();

            foreach (var line in File.ReadLines(Path.Combine(unitTestDir, "Encoder", "OpCodeInfos.txt")))
            {
                if (line.Length == 0 || line[0] == '#')
                {
                    continue;
                }
                var parts = line.Split(',');
                if (parts.Length != 8)
                {
                    throw new InvalidOperationException("Invalid file");
                }
                var name = parts[0].Trim();
                if (removed.Contains(name))
                {
                    continue;
                }
                var opCodeStr      = parts[5].Trim();
                var instructionStr = parts[6].Trim();
                if (name == "Add_rm8_r8")
                {
                    // Verify that we read the correct columns, in case someone reorders them...
                    if (opCodeStr != "00 /r" || instructionStr != $"ADD r/m8{sepChar} r8")
                    {
                        throw new InvalidOperationException("Wrong columns!");
                    }
                    checkedIt = true;
                }
                instructionStr = instructionStr.Replace(sepChar, ',');
                var docStr = $"#(c:{instructionStr})##(p:)##(c:{opCodeStr})##(p:)##(c:{GetCpuid(toInstrInfo[name])})##(p:)##(c:{GetMode(sb, toOpCodeInfo[name])})#";
                docs.Add(name, docStr);
            }
            if (!checkedIt)
            {
                throw new InvalidOperationException();
            }

            foreach (var enumValue in genTypes[TypeIds.Code].Values)
            {
                if (!string.IsNullOrEmpty(enumValue.Documentation))
                {
                    continue;
                }
                if (!docs.TryGetValue(enumValue.RawName, out var doc))
                {
                    throw new InvalidOperationException($"Couldn't find enum {enumValue.RawName}");
                }
                enumValue.Documentation = doc;
            }
        }
        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("}");
            }
        }
示例#3
0
文件: CtorInfos.cs 项目: wtf3505/iced
        void ICreatedInstructions.OnCreatedInstructions(GenTypes genTypes, HashSet <EnumValue> filteredCodeValues)
        {
            var defs = genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs;

            infos    = defs.Select(a => a.Masm).ToArray();
            filtered = true;
        }
示例#4
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("}");
            }
        }
示例#5
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  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("};");
            });
        }
示例#7
0
        public static void AddComments(GenTypes genTypes)
        {
            var sb = new StringBuilder();

            foreach (var def in genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs)
            {
                var cpuidDocs = string.Join(" and ", def.CpuidFeatureStrings);
                var docStr    = $"#(c:{def.InstructionString})##(p:)##(c:{def.OpCodeString})##(p:)##(c:{cpuidDocs})##(p:)##(c:{GetMode(sb, def)})#";
                if (!def.Code.Documentation.HasDefaultComment)
                {
                    def.Code.Documentation = new(docStr);
                }
            }
        }
示例#8
0
        public InstructionGroups(GenTypes genTypes, bool splitRegMem)
        {
            this.genTypes    = genTypes;
            this.splitRegMem = splitRegMem;
            ignoredCodes     = new HashSet <EnumValue>();

            foreach (var def in genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs)
            {
                if ((def.Flags1 & InstructionDefFlags1.NoInstruction) != 0)
                {
                    ignoredCodes.Add(def.Code);
                }
                foreach (var opKind in def.OpKindDefs)
                {
                    switch (opKind.OperandEncoding)
                    {
                    case OperandEncoding.None:
                    case OperandEncoding.NearBranch:
                    case OperandEncoding.Xbegin:
                    case OperandEncoding.AbsNearBranch:
                    case OperandEncoding.FarBranch:
                    case OperandEncoding.SegRSI:
                    case OperandEncoding.SegRDI:
                    case OperandEncoding.ESRDI:
                        ignoredCodes.Add(def.Code);
                        break;

                    case OperandEncoding.Immediate:
                    case OperandEncoding.ImpliedConst:
                    case OperandEncoding.ImpliedRegister:
                    case OperandEncoding.SegRBX:
                    case OperandEncoding.RegImm:
                    case OperandEncoding.RegOpCode:
                    case OperandEncoding.RegModrmReg:
                    case OperandEncoding.RegModrmRm:
                    case OperandEncoding.RegMemModrmRm:
                    case OperandEncoding.RegVvvvv:
                    case OperandEncoding.MemModrmRm:
                    case OperandEncoding.MemOffset:
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
            }
        }
示例#9
0
        public ImpliedAccessParser(GenTypes genTypes)
        {
            toMemorySize      = CreateEnumDict(genTypes[TypeIds.MemorySize]);
            uintToRegister    = genTypes[TypeIds.Register].Values.ToDictionary(a => a.Value, a => a);
            toRegisterImplAcc = CreateEnumDict(genTypes[TypeIds.Register], ignoreCase: true);
            toRegisterDef     = genTypes.GetObject <RegisterDefs>(TypeIds.RegisterDefs).Defs.ToDictionary(a => a.Register, a => a);

            uint vmmFirst = IcedConstantsType.Get_VMM_first(genTypes).Value;
            uint vmmLast  = IcedConstantsType.Get_VMM_last(genTypes).Value;
            uint vmmCount = vmmLast - vmmFirst + 1;
            var  tmmLast  = IcedConstantsType.Get_TMM_last(genTypes);

            toRegisterImplAcc.Add("tmm_last", tmmLast);
            for (uint ri = 0; ri < vmmCount; ri++)
            {
                var reg = uintToRegister[vmmFirst + ri];
                toRegisterImplAcc.Add("vmm" + ri, reg);
            }
        }
示例#10
0
        public InstructionGroup[] GetGroups()
        {
            var groups = new Dictionary <InstructionOperand[], InstructionGroup>(new OpComparer());

            foreach (var def in genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs)
            {
                if (ignoredCodes.Contains(def.Code))
                {
                    continue;
                }

                foreach (var ops in GetOperands(def.OpKindDefs))
                {
                    if (!groups.TryGetValue(ops, out var group))
                    {
                        groups.Add(ops, group = new InstructionGroup(ops));
                    }
                    group.Defs.Add(def);
                }
            }

            var result = groups.Values.ToArray();

            Array.Sort(result, (a, b) => {
                int c = a.Operands.Length - b.Operands.Length;
                if (c != 0)
                {
                    return(c);
                }
                for (int i = 0; i < a.Operands.Length; i++)
                {
                    c = GetOrder(a.Operands[i]) - GetOrder(b.Operands[i]);
                    if (c != 0)
                    {
                        return(c);
                    }
                }
                return(0);
            });
            return(result);
示例#11
0
        public InstructionGroups(GenTypes genTypes)
        {
            this.genTypes = genTypes;
            ignoredCodes  = new HashSet <EnumValue>();

            foreach (var def in genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs)
            {
                if ((def.Flags1 & InstructionDefFlags1.NoInstruction) != 0)
                {
                    ignoredCodes.Add(def.Code);
                }
                foreach (var opKind in def.OpKinds)
                {
                    switch (opKind)
                    {
                    case OpCodeOperandKind.None:
                    case OpCodeOperandKind.farbr2_2:
                    case OpCodeOperandKind.farbr4_2:
                    case OpCodeOperandKind.seg_rSI:
                    case OpCodeOperandKind.es_rDI:
                    case OpCodeOperandKind.seg_rDI:
                    case OpCodeOperandKind.br16_1:
                    case OpCodeOperandKind.br32_1:
                    case OpCodeOperandKind.br64_1:
                    case OpCodeOperandKind.br16_2:
                    case OpCodeOperandKind.br32_4:
                    case OpCodeOperandKind.br64_4:
                    case OpCodeOperandKind.xbegin_2:
                    case OpCodeOperandKind.xbegin_4:
                    case OpCodeOperandKind.brdisp_2:
                    case OpCodeOperandKind.brdisp_4:
                        ignoredCodes.Add(def.Code);
                        break;
                    }
                }
            }
        }
示例#12
0
        public InstructionGroups(GenTypes genTypes)
        {
            this.genTypes = genTypes;
            var encoderTypes = genTypes.GetObject <EncoderTypes>(TypeIds.EncoderTypes);

            legacyToOpKind = encoderTypes.LegacyOpHandlers.ToDictionary(a => (LegacyOpKind)a.legacyOpKind.Value, a => (OpCodeOperandKind)a.opCodeOperandKind.Value);
            vexToOpKind    = encoderTypes.VexOpHandlers.ToDictionary(a => (VexOpKind)a.vexOpKind.Value, a => (OpCodeOperandKind)a.opCodeOperandKind.Value);
            xopToOpKind    = encoderTypes.XopOpHandlers.ToDictionary(a => (XopOpKind)a.xopOpKind.Value, a => (OpCodeOperandKind)a.opCodeOperandKind.Value);
            evexToOpKind   = encoderTypes.EvexOpHandlers.ToDictionary(a => (EvexOpKind)a.evexOpKind.Value, a => (OpCodeOperandKind)a.opCodeOperandKind.Value);
            d3nowOps       = new OpCodeOperandKind[] {
                OpCodeOperandKind.mm_reg,
                OpCodeOperandKind.mm_or_mem,
            };
            var code = genTypes[TypeIds.Code];

            ignoredCodes = new HashSet <EnumValue> {
                code[nameof(Code.INVALID)],
                code[nameof(Code.DeclareByte)],
                code[nameof(Code.DeclareWord)],
                code[nameof(Code.DeclareDword)],
                code[nameof(Code.DeclareQword)],
                code[nameof(Code.Jo_rel8_16)],
                code[nameof(Code.Jo_rel8_32)],
                code[nameof(Code.Jo_rel8_64)],
                code[nameof(Code.Jno_rel8_16)],
                code[nameof(Code.Jno_rel8_32)],
                code[nameof(Code.Jno_rel8_64)],
                code[nameof(Code.Jb_rel8_16)],
                code[nameof(Code.Jb_rel8_32)],
                code[nameof(Code.Jb_rel8_64)],
                code[nameof(Code.Jae_rel8_16)],
                code[nameof(Code.Jae_rel8_32)],
                code[nameof(Code.Jae_rel8_64)],
                code[nameof(Code.Je_rel8_16)],
                code[nameof(Code.Je_rel8_32)],
                code[nameof(Code.Je_rel8_64)],
                code[nameof(Code.Jne_rel8_16)],
                code[nameof(Code.Jne_rel8_32)],
                code[nameof(Code.Jne_rel8_64)],
                code[nameof(Code.Jbe_rel8_16)],
                code[nameof(Code.Jbe_rel8_32)],
                code[nameof(Code.Jbe_rel8_64)],
                code[nameof(Code.Ja_rel8_16)],
                code[nameof(Code.Ja_rel8_32)],
                code[nameof(Code.Ja_rel8_64)],
                code[nameof(Code.Js_rel8_16)],
                code[nameof(Code.Js_rel8_32)],
                code[nameof(Code.Js_rel8_64)],
                code[nameof(Code.Jns_rel8_16)],
                code[nameof(Code.Jns_rel8_32)],
                code[nameof(Code.Jns_rel8_64)],
                code[nameof(Code.Jp_rel8_16)],
                code[nameof(Code.Jp_rel8_32)],
                code[nameof(Code.Jp_rel8_64)],
                code[nameof(Code.Jnp_rel8_16)],
                code[nameof(Code.Jnp_rel8_32)],
                code[nameof(Code.Jnp_rel8_64)],
                code[nameof(Code.Jl_rel8_16)],
                code[nameof(Code.Jl_rel8_32)],
                code[nameof(Code.Jl_rel8_64)],
                code[nameof(Code.Jge_rel8_16)],
                code[nameof(Code.Jge_rel8_32)],
                code[nameof(Code.Jge_rel8_64)],
                code[nameof(Code.Jle_rel8_16)],
                code[nameof(Code.Jle_rel8_32)],
                code[nameof(Code.Jle_rel8_64)],
                code[nameof(Code.Jg_rel8_16)],
                code[nameof(Code.Jg_rel8_32)],
                code[nameof(Code.Jg_rel8_64)],
                code[nameof(Code.Jo_rel16)],
                code[nameof(Code.Jo_rel32_32)],
                code[nameof(Code.Jo_rel32_64)],
                code[nameof(Code.Jno_rel16)],
                code[nameof(Code.Jno_rel32_32)],
                code[nameof(Code.Jno_rel32_64)],
                code[nameof(Code.Jb_rel16)],
                code[nameof(Code.Jb_rel32_32)],
                code[nameof(Code.Jb_rel32_64)],
                code[nameof(Code.Jae_rel16)],
                code[nameof(Code.Jae_rel32_32)],
                code[nameof(Code.Jae_rel32_64)],
                code[nameof(Code.Je_rel16)],
                code[nameof(Code.Je_rel32_32)],
                code[nameof(Code.Je_rel32_64)],
                code[nameof(Code.Jne_rel16)],
                code[nameof(Code.Jne_rel32_32)],
                code[nameof(Code.Jne_rel32_64)],
                code[nameof(Code.Jbe_rel16)],
                code[nameof(Code.Jbe_rel32_32)],
                code[nameof(Code.Jbe_rel32_64)],
                code[nameof(Code.Ja_rel16)],
                code[nameof(Code.Ja_rel32_32)],
                code[nameof(Code.Ja_rel32_64)],
                code[nameof(Code.Js_rel16)],
                code[nameof(Code.Js_rel32_32)],
                code[nameof(Code.Js_rel32_64)],
                code[nameof(Code.Jns_rel16)],
                code[nameof(Code.Jns_rel32_32)],
                code[nameof(Code.Jns_rel32_64)],
                code[nameof(Code.Jp_rel16)],
                code[nameof(Code.Jp_rel32_32)],
                code[nameof(Code.Jp_rel32_64)],
                code[nameof(Code.Jnp_rel16)],
                code[nameof(Code.Jnp_rel32_32)],
                code[nameof(Code.Jnp_rel32_64)],
                code[nameof(Code.Jl_rel16)],
                code[nameof(Code.Jl_rel32_32)],
                code[nameof(Code.Jl_rel32_64)],
                code[nameof(Code.Jge_rel16)],
                code[nameof(Code.Jge_rel32_32)],
                code[nameof(Code.Jge_rel32_64)],
                code[nameof(Code.Jle_rel16)],
                code[nameof(Code.Jle_rel32_32)],
                code[nameof(Code.Jle_rel32_64)],
                code[nameof(Code.Jg_rel16)],
                code[nameof(Code.Jg_rel32_32)],
                code[nameof(Code.Jg_rel32_64)],
                code[nameof(Code.Loopne_rel8_16_CX)],
                code[nameof(Code.Loopne_rel8_32_CX)],
                code[nameof(Code.Loopne_rel8_16_ECX)],
                code[nameof(Code.Loopne_rel8_32_ECX)],
                code[nameof(Code.Loopne_rel8_64_ECX)],
                code[nameof(Code.Loopne_rel8_16_RCX)],
                code[nameof(Code.Loopne_rel8_64_RCX)],
                code[nameof(Code.Loope_rel8_16_CX)],
                code[nameof(Code.Loope_rel8_32_CX)],
                code[nameof(Code.Loope_rel8_16_ECX)],
                code[nameof(Code.Loope_rel8_32_ECX)],
                code[nameof(Code.Loope_rel8_64_ECX)],
                code[nameof(Code.Loope_rel8_16_RCX)],
                code[nameof(Code.Loope_rel8_64_RCX)],
                code[nameof(Code.Loop_rel8_16_CX)],
                code[nameof(Code.Loop_rel8_32_CX)],
                code[nameof(Code.Loop_rel8_16_ECX)],
                code[nameof(Code.Loop_rel8_32_ECX)],
                code[nameof(Code.Loop_rel8_64_ECX)],
                code[nameof(Code.Loop_rel8_16_RCX)],
                code[nameof(Code.Loop_rel8_64_RCX)],
                code[nameof(Code.Jcxz_rel8_16)],
                code[nameof(Code.Jcxz_rel8_32)],
                code[nameof(Code.Jecxz_rel8_16)],
                code[nameof(Code.Jecxz_rel8_32)],
                code[nameof(Code.Jecxz_rel8_64)],
                code[nameof(Code.Jrcxz_rel8_16)],
                code[nameof(Code.Jrcxz_rel8_64)],
                code[nameof(Code.Call_rel16)],
                code[nameof(Code.Call_rel32_32)],
                code[nameof(Code.Call_rel32_64)],
                code[nameof(Code.Jmp_rel16)],
                code[nameof(Code.Jmp_rel32_32)],
                code[nameof(Code.Jmp_rel32_64)],
                code[nameof(Code.Jmp_rel8_16)],
                code[nameof(Code.Jmp_rel8_32)],
                code[nameof(Code.Jmp_rel8_64)],
                code[nameof(Code.Jmpe_disp16)],
                code[nameof(Code.Jmpe_disp32)],
                code[nameof(Code.Call_ptr1616)],
                code[nameof(Code.Call_ptr1632)],
                code[nameof(Code.Jmp_ptr1616)],
                code[nameof(Code.Jmp_ptr1632)],
                code[nameof(Code.Xbegin_rel16)],
                code[nameof(Code.Xbegin_rel32)],
                code[nameof(Code.Insb_m8_DX)],
                code[nameof(Code.Insw_m16_DX)],
                code[nameof(Code.Insd_m32_DX)],
                code[nameof(Code.Outsb_DX_m8)],
                code[nameof(Code.Outsw_DX_m16)],
                code[nameof(Code.Outsd_DX_m32)],
                code[nameof(Code.Stosb_m8_AL)],
                code[nameof(Code.Stosw_m16_AX)],
                code[nameof(Code.Stosd_m32_EAX)],
                code[nameof(Code.Stosq_m64_RAX)],
                code[nameof(Code.Lodsb_AL_m8)],
                code[nameof(Code.Lodsw_AX_m16)],
                code[nameof(Code.Lodsd_EAX_m32)],
                code[nameof(Code.Lodsq_RAX_m64)],
                code[nameof(Code.Scasb_AL_m8)],
                code[nameof(Code.Scasw_AX_m16)],
                code[nameof(Code.Scasd_EAX_m32)],
                code[nameof(Code.Scasq_RAX_m64)],
                code[nameof(Code.Movsb_m8_m8)],
                code[nameof(Code.Movsw_m16_m16)],
                code[nameof(Code.Movsd_m32_m32)],
                code[nameof(Code.Movsq_m64_m64)],
                code[nameof(Code.Cmpsb_m8_m8)],
                code[nameof(Code.Cmpsw_m16_m16)],
                code[nameof(Code.Cmpsd_m32_m32)],
                code[nameof(Code.Cmpsq_m64_m64)],
                code[nameof(Code.Maskmovq_rDI_mm_mm)],
                code[nameof(Code.Maskmovdqu_rDI_xmm_xmm)],
                code[nameof(Code.VEX_Vmaskmovdqu_rDI_xmm_xmm)],
            };
        }
示例#13
0
 public PyiGen(GeneratorContext generatorContext)
 {
     genTypes            = generatorContext.Types;
     exportedPythonTypes = genTypes.GetObject <ExportedPythonTypes>(TypeIds.ExportedPythonTypes);
 }
        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("}");
            }
        }
示例#15
0
        public static void AddComments(GenTypes genTypes)
        {
            var cpuid       = genTypes[TypeIds.CpuidFeature];
            var toCpuidName = cpuid.Values.ToDictionary(a => a, a => a.RawName);

            toCpuidName[cpuid[nameof(CpuidFeature.INTEL8086)]]        = "8086+";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL8086_ONLY)]]   = "8086";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL186)]]         = "186+";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL286)]]         = "286+";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL286_ONLY)]]    = "286";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL386)]]         = "386+";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL386_ONLY)]]    = "386";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL386_A0_ONLY)]] = "386 A0";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL486)]]         = "486+";
            toCpuidName[cpuid[nameof(CpuidFeature.INTEL486_A_ONLY)]]  = "486 A";
            toCpuidName[cpuid[nameof(CpuidFeature.SMM)]]              = "386+";
            toCpuidName[cpuid[nameof(CpuidFeature.UMOV)]]             = "386/486";
            toCpuidName[cpuid[nameof(CpuidFeature.MOV_TR)]]           = "386/486/Cyrix/Geode";
            toCpuidName[cpuid[nameof(CpuidFeature.IA64)]]             = "IA-64";
            toCpuidName[cpuid[nameof(CpuidFeature.FPU)]]              = "8087+";
            toCpuidName[cpuid[nameof(CpuidFeature.FPU287)]]           = "287+";
            toCpuidName[cpuid[nameof(CpuidFeature.FPU287XL_ONLY)]]    = "287 XL";
            toCpuidName[cpuid[nameof(CpuidFeature.FPU387)]]           = "387+";
            toCpuidName[cpuid[nameof(CpuidFeature.FPU387SL_ONLY)]]    = "387 SL";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_D3NOW)]]      = "AMD Geode GX/LX";
            toCpuidName[cpuid[nameof(CpuidFeature.HLE_or_RTM)]]       = "HLE or RTM";
            toCpuidName[cpuid[nameof(CpuidFeature.SEV_ES)]]           = "SEV-ES";
            toCpuidName[cpuid[nameof(CpuidFeature.SEV_SNP)]]          = "SEV-SNP";
            toCpuidName[cpuid[nameof(CpuidFeature.SKINIT_or_SVM)]]    = "SKINIT or SVM";
            toCpuidName[cpuid[nameof(CpuidFeature.INVEPT)]]           = "IA32_VMX_EPT_VPID_CAP[bit 20]";
            toCpuidName[cpuid[nameof(CpuidFeature.INVVPID)]]          = "IA32_VMX_EPT_VPID_CAP[bit 32]";
            toCpuidName[cpuid[nameof(CpuidFeature.MULTIBYTENOP)]]     = "CPUID.01H.EAX[Bits 11:8] = 0110B or 1111B";
            toCpuidName[cpuid[nameof(CpuidFeature.PAUSE)]]            = "Pentium 4 or later";
            toCpuidName[cpuid[nameof(CpuidFeature.RDPMC)]]            = "Pentium MMX or later, or Pentium Pro or later";
            toCpuidName[cpuid[nameof(CpuidFeature.D3NOW)]]            = "3DNOW";
            toCpuidName[cpuid[nameof(CpuidFeature.D3NOWEXT)]]         = "3DNOWEXT";
            toCpuidName[cpuid[nameof(CpuidFeature.SSE4_1)]]           = "SSE4.1";
            toCpuidName[cpuid[nameof(CpuidFeature.SSE4_2)]]           = "SSE4.2";
            toCpuidName[cpuid[nameof(CpuidFeature.AMX_BF16)]]         = "AMX-BF16";
            toCpuidName[cpuid[nameof(CpuidFeature.AMX_TILE)]]         = "AMX-TILE";
            toCpuidName[cpuid[nameof(CpuidFeature.AMX_INT8)]]         = "AMX-INT8";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_FPU)]]        = "Cyrix, AMD Geode GX/LX";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_SMM)]]        = "Cyrix, AMD Geode GX/LX";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_SMINT)]]      = "Cyrix 6x86MX+, AMD Geode GX/LX";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_SMINT_0F7E)]] = "Cyrix 6x86 or earlier";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_SHR)]]        = "Cyrix 6x86MX, M II, III";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_DDI)]]        = "Cyrix MediaGX, GXm, GXLV, GX1";
            toCpuidName[cpuid[nameof(CpuidFeature.CYRIX_DMI)]]        = "AMD Geode GX/LX";
            toCpuidName[cpuid[nameof(CpuidFeature.CENTAUR_AIS)]]      = "Centaur AIS";
            toCpuidName[cpuid[nameof(CpuidFeature.AVX_VNNI)]]         = "AVX-VNNI";

            var sb = new StringBuilder();

            foreach (var def in genTypes.GetObject <InstructionDefs>(TypeIds.InstructionDefs).Defs)
            {
                var docStr = $"#(c:{def.InstructionString})##(p:)##(c:{def.OpCodeString})##(p:)##(c:{GetCpuid(toCpuidName, def)})##(p:)##(c:{GetMode(sb, def)})#";
                if (string.IsNullOrEmpty(def.Code.Documentation))
                {
                    def.Code.Documentation = docStr;
                }
            }
        }