mirror of
https://github.com/KarolS/millfork.git
synced 2025-08-15 19:27:22 +00:00
6502: Pointers should have priority when allocating to the zeropage
This commit is contained in:
11
src/main/scala/millfork/env/Environment.scala
vendored
11
src/main/scala/millfork/env/Environment.scala
vendored
@@ -186,7 +186,13 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
|||||||
} else Nil
|
} else Nil
|
||||||
case VariableAllocationMethod.Auto | VariableAllocationMethod.Register | VariableAllocationMethod.Static =>
|
case VariableAllocationMethod.Auto | VariableAllocationMethod.Register | VariableAllocationMethod.Static =>
|
||||||
if (m.alloc == VariableAllocationMethod.Register && options.flag(CompilationFlag.FallbackValueUseWarning)) {
|
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 {
|
if (m.sizeInBytes == 0) Nil else {
|
||||||
val graveName = m.name.stripPrefix(prefix) + "`"
|
val graveName = m.name.stripPrefix(prefix) + "`"
|
||||||
@@ -1471,7 +1477,8 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
|||||||
stmt.assemblyParamPassingConvention match {
|
stmt.assemblyParamPassingConvention match {
|
||||||
case ByVariable(name) =>
|
case ByVariable(name) =>
|
||||||
val zp = pointies(name) // TODO
|
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)
|
addThing(v, stmt.position)
|
||||||
registerAddressConstant(v, stmt.position, options, Some(typ))
|
registerAddressConstant(v, stmt.position, options, Some(typ))
|
||||||
val addr = v.toAddress
|
val addr = v.toAddress
|
||||||
|
@@ -453,4 +453,26 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
|
|||||||
m.readWord(0xc000) should be <(256)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user