1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-23 23:30:22 +00:00

Do not allocate variables on top of fixed-address vairables and arrays (fixes #26)

This commit is contained in:
Karol Stasiak 2020-01-03 23:08:54 +01:00
parent 6e36166af2
commit df1d5421be
3 changed files with 46 additions and 0 deletions

View File

@ -131,8 +131,12 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
Nil
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 && options.platform.cpuFamily == CpuFamily.I80 =>
Nil
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 && options.platform.cpuFamily == CpuFamily.M6809 =>
Nil
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 2 && options.platform.cpuFamily == CpuFamily.I80 =>
Nil
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 2 && options.platform.cpuFamily == CpuFamily.M6809 =>
Nil
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 3 && options.platform.cpuFamily == CpuFamily.I80 =>
Nil
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 4 && options.platform.cpuFamily == CpuFamily.I80 =>
@ -171,6 +175,7 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
if (forZpOnly || !options.platform.hasZeroPage) {
val addr =
allocators(bank).allocateBytes(bank0, callGraph, vertex, options, m.sizeInBytes, initialized = false, writeable = true, location = AllocationLocation.Zeropage, alignment = m.alignment)
if (log.traceEnabled) log.trace("addr $" + addr.toHexString)
onEachVariable(m.name, bank0.index -> addr)
List(
ConstantThing(m.name.stripPrefix(prefix) + "`", NumericConstant(addr, 2), p)
@ -187,6 +192,7 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
allocators(bank).tryAllocateZeropageBytes(bank0, callGraph, vertex, options, m.sizeInBytes, alignment = m.alignment) match {
case None => Nil
case Some(addr) =>
if (log.traceEnabled) log.trace("addr $" + addr.toHexString)
onEachVariable(m.name, bank0.index -> addr)
List(
ConstantThing(m.name.stripPrefix(prefix) + "`", NumericConstant(addr, 2), p)
@ -197,6 +203,7 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
Nil
} else {
val addr = allocators(bank).allocateBytes(bank0, callGraph, vertex, options, m.sizeInBytes, initialized = false, writeable = true, location = AllocationLocation.Either, alignment = m.alignment)
if (log.traceEnabled) log.trace("addr $" + addr.toHexString)
onEachVariable(m.name, bank0.index -> addr)
List(
ConstantThing(graveName, NumericConstant(addr, 2), p)

View File

@ -223,6 +223,30 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
val potentiallyInlineable: Map[String, Int] = inliningResult.potentiallyInlineableFunctions
var functionsThatCanBeCalledFromInlinedFunctions: Set[String] = inliningResult.nonInlineableFunctions
for(th <- env.things.values) {
th match {
case tim: VariableInMemory =>
tim.toAddress match {
case NumericConstant(n, _) =>
val m = mem.banks(tim.bank(options))
for (i <- 0 until tim.typ.size) {
m.occupied(i + n.toInt) = true
}
case _ =>
}
case arr: MfArray =>
arr.toAddress match {
case NumericConstant(n, _) =>
val m = mem.banks(arr.bank(options))
for (i <- 0 until arr.sizeInBytes) {
m.occupied(i + n.toInt) = true
}
case _ =>
}
case _ =>
}
}
env.allocateVariables(None, mem, callGraph, variableAllocators, options, labelMap.put, 1, forZpOnly = true)
env.allocateVariables(None, mem, callGraph, variableAllocators, options, labelMap.put, 2, forZpOnly = true)
env.allocateVariables(None, mem, callGraph, variableAllocators, options, labelMap.put, 3, forZpOnly = true)

View File

@ -191,6 +191,21 @@ class BasicSymonTest extends FunSuite with Matchers {
}
}
test("Allocation test 2") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos)(
"""
| #use ZPREG_SIZE
| array _crap[$100-ZPREG_SIZE] @$00
| word output @$c000
| word data
| void main () {
| output = data.addr
| }
""".stripMargin){ m =>
m.readWord(0xc000) should be >=(0x100)
}
}
test("Preprocessor test") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""