private IDictionary <Type, List <MemoryUnit> > BuildMemoryUnits(JToken token)
        {
            JArray memories   = (JArray)token;
            var    memoryDict = new Dictionary <Type, List <MemoryUnit> >();

            List <MappedMemoryUnit> memUnits = new List <MappedMemoryUnit>();

            for (int i = 0; i < memories.Count; i++)
            {
                MemoryUnit mem = BuildMemoryUnit(memories[i]);
                try {
                    MappedMemoryUnit mappedMem = MapMemoryToAddresses(memories[i], mem);
                    memUnits.Add(mappedMem);
                }
                catch (MappingException) {
                    //nop
                }

                if (!memoryDict.ContainsKey(mem.GetType()))
                {
                    memoryDict.Add(mem.GetType(), new List <MemoryUnit>());
                }
                memoryDict[mem.GetType()].Add(mem);
            }

            MemoryMapper mapper = new MemoryMapper(memUnits);

            memoryDict.Add(mapper.GetType(), new List <MemoryUnit>());
            memoryDict[mapper.GetType()].Add(mapper);

            return(memoryDict);
        }
Beispiel #2
0
 public MappedMemoryUnit(MemoryUnit memUnit, uint startAddr, uint endAddr, string name = null)
 {
     this.MemUnit   = memUnit;
     this.StartAddr = startAddr;
     this.EndAddr   = endAddr;
     this.Name      = name ?? memUnit?.GetType().Name;
 }
Beispiel #3
0
        public MappedMemoryUnit(MemoryUnit memUnit, string bitmask, string name = null)
        {
            string cleanedBitmask = bitmask.Trim().ToLower().Replace("_", "");

            if (!bitmaskFormat.IsMatch(cleanedBitmask))
            {
                throw new ArgumentException($"Invalid bitmask: \"{bitmask}\", must match regex /{bitmaskFormat.ToString()}/");
            }

            this.MemUnit   = memUnit;
            this.StartAddr = Convert.ToUInt32(cleanedBitmask.Replace("x", "0"), 2);
            this.EndAddr   = Convert.ToUInt32(cleanedBitmask.Replace("x", "1"), 2);
            this.Name      = name ?? memUnit?.GetType().Name;
        }