Ejemplo n.º 1
0
        public void Map(string from, string to)
        {
            var regTo = registers.SingleOrDefault(x => x.Name == to);
            if(regTo.Name == null)
            {
                throw new ArgumentException(string.Format("No register named {0} found.", to));
            }

            var regFrom = new RegisterDescriptor
            {
                Name = from,
                Width = regTo.Width,
                Value = regTo.Value
            };

            registers.Add(regFrom);
        }
        private void InsideEnumHandler(string line)
        {
            if (line.Trim().StartsWith(BeginningOfIfder, StringComparison.CurrentCulture))
            {
                var value = line.Replace(BeginningOfIfder, string.Empty).Trim();
                modes.Push(defines.Contains(value) ? Mode.InsideDefinedIfdef : Mode.InsideUndefinedIfdef);
                return;
            }

            if (line.Trim() == EndOfEnum)
            {
                modes.Pop();
                return;
            }

            // e.g., R_0_32 = 147,
            // X_32 = 155,
            var match = Regex.Match(line, @"^\s*(?<name>[\p{L}0-9]+)(_(?<index>[0-9]+))?_(?<width>[0-9]+)\s*=\s*(?<value>[0-9]+)\s*,?\s*$");

            if (string.IsNullOrEmpty(match.Groups["name"].Value))
            {
                throw new ArgumentException($"Register name was in a wrong format: {line}");
            }

            var regDesc = new RegisterDescriptor
            {
                Name  = match.Groups["name"].Value,
                Width = int.Parse(match.Groups["width"].Value),
                Value = int.Parse(match.Groups["value"].Value)
            };

            if (!string.IsNullOrEmpty(match.Groups["index"].Value))
            {
                if (!groupedRegisters.ContainsKey(regDesc.Name))
                {
                    groupedRegisters[regDesc.Name] = new List <Tuple <RegisterDescriptor, int> >();
                }

                var index = int.Parse(match.Groups["index"].Value);
                groupedRegisters[regDesc.Name].Add(Tuple.Create(regDesc, index));
            }
            else
            {
                registers.Add(regDesc);
            }
        }
        public void Map(string from, string to)
        {
            var regTo = registers.SingleOrDefault(x => x.Name == to);

            if (regTo.Name == null)
            {
                throw new ArgumentException(string.Format("No register named {0} found.", to));
            }

            var regFrom = new RegisterDescriptor
            {
                Name  = from,
                Width = regTo.Width,
                Value = regTo.Value
            };

            registers.Add(regFrom);
        }
Ejemplo n.º 4
0
        private void InsideEnumHanlder(string line)
        {
            if(line.Trim().StartsWith(BeginningOfIfder, StringComparison.CurrentCulture))
            {
                var value = line.Replace(BeginningOfIfder, string.Empty).Trim();
                modes.Push(defines.Contains(value) ? Mode.InsideDefinedIfdef : Mode.InsideUndefinedIfdef);
                return;
            }

            if(line.Trim() == EndOfEnum)
            {
                modes.Pop();
                return;
            }

            // e.g., R_0_32 = 147,
            // X_32 = 155,
            var match = Regex.Match(line, @"^\s*(?<name>[\p{L}0-9]+)(_(?<index>[0-9]+))?_(?<width>[0-9]+)\s*=\s*(?<value>[0-9]+)\s*,?\s*$");
            if(string.IsNullOrEmpty(match.Groups["name"].Value))
            {
                throw new ArgumentException("Register name was in a wrong format");
            }

            var regDesc = new RegisterDescriptor
            {
                Name = match.Groups["name"].Value,
                Width = int.Parse(match.Groups["width"].Value),
                Value = int.Parse(match.Groups["value"].Value)
            };

            if(!string.IsNullOrEmpty(match.Groups["index"].Value))
            {
                if(!groupedRegisters.ContainsKey(regDesc.Name))
                {
                    groupedRegisters[regDesc.Name] = new List<Tuple<RegisterDescriptor,int>>();
                }

                var index = int.Parse(match.Groups["index"].Value);
                groupedRegisters[regDesc.Name].Add(Tuple.Create(regDesc,index));
            }
            else
            {
                registers.Add(regDesc);
            }
        }