1
0

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.
This commit is contained in:
Yunsup Lee 2016-09-06 21:53:55 -07:00 committed by Andrew Waterman
parent 7504498dff
commit b76612f357

View File

@ -77,8 +77,6 @@ class AddrMap(
var cacheable = true var cacheable = true
for (AddrMapEntry(name, r) <- entriesIn) { for (AddrMapEntry(name, r) <- entriesIn) {
if (r.start != 0) { 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 base = r.start
} else { } else {
base = (base + r.size - 1) / r.size * r.size base = (base + r.size - 1) / r.size * r.size
@ -121,6 +119,16 @@ class AddrMap(
}.flatten.sortBy(_.region.start) }.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 toRange: MemRange = MemRange(start, size, attr)
def apply(name: String): MemRegion = mapping(name) def apply(name: String): MemRegion = mapping(name)
def contains(name: String): Boolean = mapping.contains(name) def contains(name: String): Boolean = mapping.contains(name)