Example #1
0
        static SymbolResolverTestCase ParseLine(string line)
        {
            var       elems         = line.Split(commaSeparator);
            const int SYM_RES_INDEX = 4;

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

            var bitness  = NumberConverter.ToInt32(elems[0].Trim());
            var hexBytes = elems[1].Trim();
            var code     = ToEnumConverter.GetCode(elems[2].Trim());

            var options = new List <(OptionsProps property, object value)>();

            foreach (var part in elems[3].Split(spaceSeparator, StringSplitOptions.RemoveEmptyEntries))
            {
                options.Add(OptionsParser.ParseOption(part));
            }

            var symbolResults = new SymbolResultTestCase[elems.Length - SYM_RES_INDEX];

            for (int i = 0; i < symbolResults.Length; i++)
            {
                var symParts = elems[SYM_RES_INDEX + i].Split(semicolonSeparator);
                if (symParts.Length != 5)
                {
                    throw new Exception($"Invalid number of semicolons: {symParts.Length - 1}");
                }

                var address       = NumberConverter.ToUInt64(symParts[0].Trim());
                var symbolAddress = NumberConverter.ToUInt64(symParts[1].Trim());
                var addressSize   = NumberConverter.ToInt32(symParts[2].Trim());
                var symbolParts   = symParts[3].Split(barSeparator);

                MemorySize?memorySize = null;
                var        flags      = SymbolFlags.None;
                foreach (var value in symParts[4].Split(spaceSeparator, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (Dicts.ToSymbolFlags.TryGetValue(value, out var f))
                    {
                        flags |= f;
                    }
                    else
                    {
                        if (!ToEnumConverter.TryMemorySize(value, out var memSize))
                        {
                            throw new Exception($"Invalid value: {value}");
                        }
                        memorySize = memSize;
                    }
                }

                symbolResults[i] = new SymbolResultTestCase(address, symbolAddress, addressSize, flags, memorySize, symbolParts);
            }

            return(new SymbolResolverTestCase(bitness, hexBytes, code, options.ToArray(), symbolResults));
        }
Example #2
0
 static MemorySize ToMemorySize(string value)
 {
     if (!ToEnumConverter.TryMemorySize(value, out var memSize))
     {
         throw new InvalidOperationException($"Invalid MemorySize value: '{value}'");
     }
     return(memSize);
 }
Example #3
0
        static bool AddMemory(int bitness, Dictionary <string, Register> toRegister, string value, OpAccess access, InstructionInfoTestCase testCase)
        {
            var elems = value.Split(semicolonSeparator);

            if (elems.Length != 2)
            {
                return(false);
            }
            var expr = elems[0].Trim();

            if (!ToEnumConverter.TryMemorySize(elems[1].Trim(), out var memorySize))
            {
                return(false);
            }

            if (!TryParseMemExpr(toRegister, expr, out var segReg, out var baseReg, out var indexReg, out int scale, out ulong displ))
            {
                return(false);
            }

            switch (bitness)
            {
            case 16:
                if (!(short.MinValue <= (long)displ && (long)displ <= short.MaxValue) && displ > ushort.MaxValue)
                {
                    return(false);
                }
                displ = (ushort)displ;
                break;

            case 32:
                if (!(int.MinValue <= (long)displ && (long)displ <= int.MaxValue) && displ > uint.MaxValue)
                {
                    return(false);
                }
                displ = (uint)displ;
                break;

            case 64:
                break;

            default:
                throw new InvalidOperationException();
            }

            if (access != OpAccess.NoMemAccess)
            {
                testCase.UsedMemory.Add(new UsedMemory(segReg, baseReg, indexReg, scale, displ, memorySize, access));
            }

            return(true);
        }