From b76612f357eba107f654b4bfc41497be0584ed8c Mon Sep 17 00:00:00 2001 From: Yunsup Lee Date: Tue, 6 Sep 2016 21:53:55 -0700 Subject: [PATCH] relax contraint on adding AddrMapEntry to AddrMap (#248) now you can add them in any order. there's an explicit check at the end to figure out whether there are overlapping regions. --- src/main/scala/junctions/addrmap.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/scala/junctions/addrmap.scala b/src/main/scala/junctions/addrmap.scala index 095c2da9..aa1ceac7 100644 --- a/src/main/scala/junctions/addrmap.scala +++ b/src/main/scala/junctions/addrmap.scala @@ -77,8 +77,6 @@ class AddrMap( var cacheable = true for (AddrMapEntry(name, r) <- entriesIn) { if (r.start != 0) { - val align = BigInt(1) << log2Ceil(r.size) - require(r.start >= base, s"region $name base address 0x${r.start.toString(16)} overlaps previous base 0x${base.toString(16)}") base = r.start } else { base = (base + r.size - 1) / r.size * r.size @@ -121,6 +119,16 @@ class AddrMap( }.flatten.sortBy(_.region.start) } + // checks to see whether any MemRange overlaps within this AddrMap + flatten.combinations(2) foreach { + case (Seq(AddrMapEntry(an, ar), AddrMapEntry(bn, br))) => + val arEnd = ar.start + ar.size + val brEnd = br.start + br.size + val abOverlaps = ar.start < brEnd && br.start < arEnd + require(!abOverlaps, + "region $an@0x${ar.start.toString(16)} overlaps region $bn@0x${br.start.toString(16)}") + } + def toRange: MemRange = MemRange(start, size, attr) def apply(name: String): MemRegion = mapping(name) def contains(name: String): Boolean = mapping.contains(name)