1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-29 02:31:45 +00:00

6502: Pointers should have priority when allocating to the zeropage

This commit is contained in:
Karol Stasiak 2020-03-26 18:52:46 +01:00
parent 78070c115f
commit dfe33c9b7a
2 changed files with 31 additions and 2 deletions

View File

@ -186,7 +186,13 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
} else Nil
case VariableAllocationMethod.Auto | VariableAllocationMethod.Register | VariableAllocationMethod.Static =>
if (m.alloc == VariableAllocationMethod.Register && options.flag(CompilationFlag.FallbackValueUseWarning)) {
log.warn(s"Failed to inline variable `${m.name}` into a register", None)
options.platform.cpuFamily match {
case CpuFamily.M6502 if m.sizeInBytes == 1 =>
log.warn(s"Failed to inline variable `${m.name}` into a register", None)
case CpuFamily.I80 | CpuFamily.I80 | CpuFamily.I86 | CpuFamily.M6809 if m.sizeInBytes <= 2 =>
log.warn(s"Failed to inline variable `${m.name}` into a register", None)
case _ =>
}
}
if (m.sizeInBytes == 0) Nil else {
val graveName = m.name.stripPrefix(prefix) + "`"
@ -1471,7 +1477,8 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
stmt.assemblyParamPassingConvention match {
case ByVariable(name) =>
val zp = pointies(name) // TODO
val v = UninitializedMemoryVariable(prefix + name, typ, if (zp) VariableAllocationMethod.Zeropage else VariableAllocationMethod.Auto, None, defaultVariableAlignment(options, 2), isVolatile = false)
val allocationMethod = if (pointies(name)) VariableAllocationMethod.Zeropage else if (typ.isPointy) VariableAllocationMethod.Register else VariableAllocationMethod.Auto
val v = UninitializedMemoryVariable(prefix + name, typ, allocationMethod, None, defaultVariableAlignment(options, 2), isVolatile = false)
addThing(v, stmt.position)
registerAddressConstant(v, stmt.position, options, Some(typ))
val addr = v.toAddress

View File

@ -453,4 +453,26 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
m.readWord(0xc000) should be <(256)
}
test ("Pointers should have priority when allocating to the zeropage") {
val m = EmuUnoptimizedRun(
"""
| word output1 @$c000
| word output2 @$c000
|
| array arr [252]
|
| noinline word f(pointer p, pointer q) {
| output1 = p.addr
| output2 = q.addr
| return p + q
| }
|
| void main () {
| f(0,1)
| }
|""".stripMargin)
m.readWord(0xc000) should be <(256)
m.readWord(0xc002) should be <(256)
}
}