Пример #1
0
        public static (OptionsProps property, object value) ParseOption(string keyValue)
        {
            var kv = keyValue.Split(kvseps, 2);

            if (kv.Length != 2)
            {
                throw new InvalidOperationException($"Expected key=value: '{keyValue}'");
            }
            var    valueStr = kv[1].Trim();
            var    prop     = ToEnumConverter.GetOptionsProps(kv[0].Trim());
            object value;

            switch (prop)
            {
            case OptionsProps.AddLeadingZeroToHexNumbers:
            case OptionsProps.AlwaysShowScale:
            case OptionsProps.AlwaysShowSegmentRegister:
            case OptionsProps.BranchLeadingZeroes:
            case OptionsProps.DisplacementLeadingZeroes:
            case OptionsProps.GasNakedRegisters:
            case OptionsProps.GasShowMnemonicSizeSuffix:
            case OptionsProps.GasSpaceAfterMemoryOperandComma:
            case OptionsProps.LeadingZeroes:
            case OptionsProps.MasmAddDsPrefix32:
            case OptionsProps.NasmShowSignExtendedImmediateSize:
            case OptionsProps.PreferST0:
            case OptionsProps.RipRelativeAddresses:
            case OptionsProps.ScaleBeforeIndex:
            case OptionsProps.ShowBranchSize:
            case OptionsProps.ShowSymbolAddress:
            case OptionsProps.ShowZeroDisplacements:
            case OptionsProps.SignedImmediateOperands:
            case OptionsProps.SignedMemoryDisplacements:
            case OptionsProps.SmallHexNumbersInDecimal:
            case OptionsProps.SpaceAfterMemoryBracket:
            case OptionsProps.SpaceAfterOperandSeparator:
            case OptionsProps.SpaceBetweenMemoryAddOperators:
            case OptionsProps.SpaceBetweenMemoryMulOperators:
            case OptionsProps.UppercaseAll:
            case OptionsProps.UppercaseDecorators:
            case OptionsProps.UppercaseHex:
            case OptionsProps.UppercaseKeywords:
            case OptionsProps.UppercaseMnemonics:
            case OptionsProps.UppercasePrefixes:
            case OptionsProps.UppercaseRegisters:
            case OptionsProps.UsePseudoOps:
            case OptionsProps.ShowUselessPrefixes:
                value = NumberConverter.ToBoolean(valueStr);
                break;

            case OptionsProps.BinaryDigitGroupSize:
            case OptionsProps.DecimalDigitGroupSize:
            case OptionsProps.FirstOperandCharIndex:
            case OptionsProps.HexDigitGroupSize:
            case OptionsProps.OctalDigitGroupSize:
            case OptionsProps.TabSize:
                value = NumberConverter.ToInt32(valueStr);
                break;

            case OptionsProps.IP:
                value = NumberConverter.ToUInt64(valueStr);
                break;

            case OptionsProps.BinaryPrefix:
            case OptionsProps.BinarySuffix:
            case OptionsProps.DecimalPrefix:
            case OptionsProps.DecimalSuffix:
            case OptionsProps.DigitSeparator:
            case OptionsProps.HexPrefix:
            case OptionsProps.HexSuffix:
            case OptionsProps.OctalPrefix:
            case OptionsProps.OctalSuffix:
                value = valueStr == "<null>" ? null : valueStr;
                break;

            case OptionsProps.MemorySizeOptions:
                value = ToEnumConverter.GetMemorySizeOptions(valueStr);
                break;

            case OptionsProps.NumberBase:
                value = ToEnumConverter.GetNumberBase(valueStr);
                break;

            case OptionsProps.CC_b:
                value = ToEnumConverter.GetCC_b(valueStr);
                break;

            case OptionsProps.CC_ae:
                value = ToEnumConverter.GetCC_ae(valueStr);
                break;

            case OptionsProps.CC_e:
                value = ToEnumConverter.GetCC_e(valueStr);
                break;

            case OptionsProps.CC_ne:
                value = ToEnumConverter.GetCC_ne(valueStr);
                break;

            case OptionsProps.CC_be:
                value = ToEnumConverter.GetCC_be(valueStr);
                break;

            case OptionsProps.CC_a:
                value = ToEnumConverter.GetCC_a(valueStr);
                break;

            case OptionsProps.CC_p:
                value = ToEnumConverter.GetCC_p(valueStr);
                break;

            case OptionsProps.CC_np:
                value = ToEnumConverter.GetCC_np(valueStr);
                break;

            case OptionsProps.CC_l:
                value = ToEnumConverter.GetCC_l(valueStr);
                break;

            case OptionsProps.CC_ge:
                value = ToEnumConverter.GetCC_ge(valueStr);
                break;

            case OptionsProps.CC_le:
                value = ToEnumConverter.GetCC_le(valueStr);
                break;

            case OptionsProps.CC_g:
                value = ToEnumConverter.GetCC_g(valueStr);
                break;

            case OptionsProps.DecoderOptions:
                value = ToEnumConverter.GetDecoderOptions(valueStr);
                break;

            default:
                throw new InvalidOperationException();
            }
            return(prop, value);
        }
Пример #2
0
        static VirtualAddressTestCase?ParseLine(string line)
        {
            var elems = line.Split(commaSeparator);

            if (elems.Length != 9)
            {
                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 usedMemIndex   = NumberConverter.ToInt32(elems[4].Trim());
            var elementIndex   = NumberConverter.ToInt32(elems[5].Trim());
            var expectedValue  = NumberConverter.ToUInt64(elems[6].Trim());
            var decOptStr      = elems[7].Trim();
            var decoderOptions = decOptStr == string.Empty ? DecoderOptions.None : ToEnumConverter.GetDecoderOptions(decOptStr);

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

            foreach (var tmp in elems[8].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, decoderOptions, operand, usedMemIndex, elementIndex, expectedValue, registerValues.ToArray()));
        }