示例#1
0
        static DecoderMemoryTestCase ReadTestCase(int bitness, string line, int lineNumber)
        {
            var parts = line.Split(colSep, StringSplitOptions.None);

            if (parts.Length != 11 && parts.Length != 12)
            {
                throw new InvalidOperationException();
            }
            var tc = new DecoderMemoryTestCase();

            tc.LineNumber       = lineNumber;
            tc.Bitness          = bitness;
            tc.HexBytes         = parts[0].Trim();
            tc.Code             = ToEnumConverter.GetCode(parts[1].Trim());
            tc.Register         = ToEnumConverter.GetRegister(parts[2].Trim());
            tc.SegmentPrefix    = ToEnumConverter.GetRegister(parts[3].Trim());
            tc.SegmentRegister  = ToEnumConverter.GetRegister(parts[4].Trim());
            tc.BaseRegister     = ToEnumConverter.GetRegister(parts[5].Trim());
            tc.IndexRegister    = ToEnumConverter.GetRegister(parts[6].Trim());
            tc.Scale            = (int)ParseUInt32(parts[7].Trim());
            tc.Displacement     = ParseUInt32(parts[8].Trim());
            tc.DisplacementSize = (int)ParseUInt32(parts[9].Trim());
            var coStr = parts[10].Trim();

            if (!DecoderTestParser.TryParseConstantOffsets(coStr, out tc.ConstantOffsets))
            {
                throw new InvalidOperationException($"Invalid ConstantOffsets: '{coStr}'");
            }
            tc.EncodedHexBytes = parts.Length > 11 ? parts[11].Trim() : tc.HexBytes;
            tc.DecoderOptions  = DecoderOptions.None;
            tc.CanEncode       = true;
            return(tc);
        }
示例#2
0
        static RegisterInfoTestCase ParseLine(string line, int lineNo)
        {
            Static.Assert(MiscInstrInfoTestConstants.RegisterElemsPerLine == 7 ? 0 : -1);
            var elems = line.Split(commaSeparator, MiscInstrInfoTestConstants.RegisterElemsPerLine);

            if (elems.Length != MiscInstrInfoTestConstants.RegisterElemsPerLine)
            {
                throw new Exception($"Expected {MiscInstrInfoTestConstants.RegisterElemsPerLine - 1} commas");
            }

            var tc = new RegisterInfoTestCase();

            tc.LineNumber     = lineNo;
            tc.Register       = ToEnumConverter.GetRegister(elems[0].Trim());
            tc.Number         = NumberConverter.ToInt32(elems[1].Trim());
            tc.BaseRegister   = ToEnumConverter.GetRegister(elems[2].Trim());
            tc.FullRegister   = ToEnumConverter.GetRegister(elems[3].Trim());
            tc.FullRegister32 = ToEnumConverter.GetRegister(elems[4].Trim());
            tc.Size           = NumberConverter.ToInt32(elems[5].Trim());
            foreach (var value in elems[6].Split(spaceSeparator, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!InstructionInfoDicts.RegisterFlagsTable.TryGetValue(value, out var flags))
                {
                    throw new InvalidOperationException($"Invalid flags value: {value}");
                }
                tc.Flags |= flags;
            }
            return(tc);
        }
示例#3
0
        static VirtualAddressTestCase?ParseLine(string line)
        {
            var elems = line.Split(commaSeparator);

            if (elems.Length != 7)
            {
                throw new Exception($"Invalid number of commas: {elems.Length - 1}");
            }

            var bitness = NumberConverter.ToInt32(elems[0].Trim());

            if (CodeUtils.IsIgnored(elems[1].Trim()))
            {
                return(null);
            }
            var hexBytes      = elems[2].Trim();
            var operand       = NumberConverter.ToInt32(elems[3].Trim());
            var elementIndex  = NumberConverter.ToInt32(elems[4].Trim());
            var expectedValue = NumberConverter.ToUInt64(elems[5].Trim());

            var registerValues = new List <(Register register, int elementIndex, int elementSize, ulong value)>();

            foreach (var tmp in elems[6].Split(spaceSeparator, StringSplitOptions.RemoveEmptyEntries))
            {
                var kv = tmp.Split(equalSeparator);
                if (kv.Length != 2)
                {
                    throw new Exception($"Expected key=value: {tmp}");
                }
                var key      = kv[0];
                var valueStr = kv[1];

                Register register;
                int      expectedElementIndex;
                int      expectedElementSize;
                if (key.IndexOf(';') >= 0)
                {
                    var parts = key.Split(semicolonSeparator);
                    if (parts.Length != 3)
                    {
                        throw new Exception($"Invalid number of semicolons: {parts.Length - 1}");
                    }
                    register             = ToEnumConverter.GetRegister(parts[0]);
                    expectedElementIndex = NumberConverter.ToInt32(parts[1]);
                    expectedElementSize  = NumberConverter.ToInt32(parts[2]);
                }
                else
                {
                    register             = ToEnumConverter.GetRegister(key);
                    expectedElementIndex = 0;
                    expectedElementSize  = 0;
                }
                ulong value = NumberConverter.ToUInt64(valueStr);
                registerValues.Add((register, expectedElementIndex, expectedElementSize, value));
            }

            return(new VirtualAddressTestCase(bitness, hexBytes, operand, elementIndex, expectedValue, registerValues.ToArray()));
        }
        static DecoderMemoryTestCase ReadTestCase(int bitness, string line, int lineNumber)
        {
            var parts = line.Split(colSep, StringSplitOptions.None);

            if (parts.Length != 11 && parts.Length != 12)
            {
                throw new InvalidOperationException();
            }
            var tc = new DecoderMemoryTestCase();

            tc.LineNumber = lineNumber;
            tc.Bitness    = bitness;
            tc.IP         = bitness switch {
                16 => DecoderConstants.DEFAULT_IP16,
                32 => DecoderConstants.DEFAULT_IP32,
                64 => DecoderConstants.DEFAULT_IP64,
                _ => throw new InvalidOperationException(),
            };
            tc.HexBytes = parts[0].Trim();
            var code = parts[1].Trim();

            if (CodeUtils.IsIgnored(code))
            {
                return(null);
            }
            tc.Code             = ToEnumConverter.GetCode(code);
            tc.Register         = ToEnumConverter.GetRegister(parts[2].Trim());
            tc.SegmentPrefix    = ToEnumConverter.GetRegister(parts[3].Trim());
            tc.SegmentRegister  = ToEnumConverter.GetRegister(parts[4].Trim());
            tc.BaseRegister     = ToEnumConverter.GetRegister(parts[5].Trim());
            tc.IndexRegister    = ToEnumConverter.GetRegister(parts[6].Trim());
            tc.Scale            = (int)NumberConverter.ToUInt32(parts[7].Trim());
            tc.Displacement     = NumberConverter.ToUInt64(parts[8].Trim());
            tc.DisplacementSize = (int)NumberConverter.ToUInt32(parts[9].Trim());
            var coStr = parts[10].Trim();

            if (!DecoderTestParser.TryParseConstantOffsets(coStr, out tc.ConstantOffsets))
            {
                throw new InvalidOperationException($"Invalid ConstantOffsets: '{coStr}'");
            }
            tc.EncodedHexBytes = parts.Length > 11 ? parts[11].Trim() : tc.HexBytes;
            tc.DecoderOptions  = DecoderOptions.None;
            tc.TestOptions     = DecoderTestOptions.None;
            return(tc);
        }