Ejemplo n.º 1
0
            // There are two expected formats:
            // * hi..lo (hi, lo being integers)
            // * bit (bit being an integer; treated as bit..bit)
            public static bool TryParse(string s, out BitsRange br)
            {
                var x = s.Split(BitRangeSplitPatterns, StringSplitOptions.None);

                if (x.Length == 1)
                {
                    if (int.TryParse(x[0], out var bit))
                    {
                        br = new BitsRange(bit, bit);
                        return(true);
                    }
                }
                else if (x.Length == 2)
                {
                    if (int.TryParse(x[0], out var upperBit) &&
                        int.TryParse(x[1], out var lowerBit))
                    {
                        br = new BitsRange(lowerBit, upperBit);
                        return(true);
                    }
                }

                br = new BitsRange(-1, -1);
                return(false);
            }
Ejemplo n.º 2
0
        private static Tuple <string, string> ParseLine(string lineContent, int opcodeLength = 32)
        {
            var pattern = new StringBuilder(new String('_', opcodeLength));

            var elems = lineContent.Split(LineSplitPatterns, StringSplitOptions.RemoveEmptyEntries);

            if (elems.Length < 2)
            {
                throw new RecoverableException($"Couldn't split line: {lineContent}");
            }

            var instructionName = elems[0];

            foreach (var elem in elems.Skip(1))
            {
                var parts = elem.Split(PartSplitPatterns);
                if (parts.Length != 2)
                {
                    // let's ignore all non-explicit ranges
                    continue;
                }

                if (!BitsRange.TryParse(parts[0], out var range))
                {
                    throw new RecoverableException($"Couldn't parse range: {parts[0]}");
                }

                if (!BitsValue.TryParse(parts[1], out var value))
                {
                    throw new RecoverableException($"Couldn't parse value: {parts[1]}");
                }

                if (!range.TryApply(pattern, value))
                {
                    throw new RecoverableException($"Couldn't apply value {value} in range {range} to pattern {pattern}");
                }
            }

            return(Tuple.Create(instructionName, pattern.ToString()));
        }