mirror of
https://github.com/irmen/prog8.git
synced 2024-07-24 06:29:22 +00:00
fix popCpuStack to load values into asmsub register params
This commit is contained in:
parent
988a3e4446
commit
a5ca08f33d
@ -2875,13 +2875,8 @@ $repeatLabel lda $counterVar
|
||||
}
|
||||
}
|
||||
|
||||
internal fun popCpuStack(dt: DataType, target: IPtVariable, scope: IPtSubroutine?) {
|
||||
// note: because A is pushed first so popped last, saving A is often not required here.
|
||||
val parameter = (target as PtNode).definingSub()?.parameters?.singleOrNull { it.name===target.name }
|
||||
if(parameter!=null) {
|
||||
val sub = parameter.definingAsmSub() ?: throw AssemblyError("push/pop arg passing only supported on asmsubs ${target.position}")
|
||||
val shouldKeepA = sub.parameters.any { it.second.registerOrPair==RegisterOrPair.AX || it.second.registerOrPair==RegisterOrPair.AY}
|
||||
val reg = sub.parameters.single { it.first === parameter }.second
|
||||
internal fun popCpuStack(asmsub: PtAsmSub, parameter: PtSubroutineParameter, reg: RegisterOrStatusflag) {
|
||||
val shouldKeepA = asmsub.parameters.any { it.second.registerOrPair==RegisterOrPair.AX || it.second.registerOrPair==RegisterOrPair.AY}
|
||||
if(reg.statusflag!=null) {
|
||||
if(shouldKeepA)
|
||||
out(" sta P8ZP_SCRATCH_REG")
|
||||
@ -2895,7 +2890,7 @@ $repeatLabel lda $counterVar
|
||||
out(" lda P8ZP_SCRATCH_REG")
|
||||
}
|
||||
else {
|
||||
if (dt in ByteDatatypes) {
|
||||
if (parameter.type in ByteDatatypes) {
|
||||
if (isTargetCpu(CpuType.CPU65c02)) {
|
||||
when (reg.registerOrPair) {
|
||||
RegisterOrPair.A -> out(" pla")
|
||||
@ -2950,7 +2945,16 @@ $repeatLabel lda $counterVar
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
internal fun popCpuStack(dt: DataType, target: IPtVariable, scope: IPtSubroutine?) {
|
||||
// note: because A is pushed first so popped last, saving A is often not required here.
|
||||
val targetAsmSub = (target as PtNode).definingAsmSub()
|
||||
if(targetAsmSub != null) {
|
||||
val parameter = targetAsmSub.parameters.first { it.first.name==target.name }
|
||||
popCpuStack(targetAsmSub, parameter.first, parameter.second)
|
||||
return
|
||||
}
|
||||
val scopedName = when(target) {
|
||||
is PtConstant -> target.scopedName
|
||||
is PtMemMapped -> target.scopedName
|
||||
@ -2969,7 +2973,6 @@ $repeatLabel lda $counterVar
|
||||
assignRegister(RegisterOrPair.AY, tgt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun popCpuStack(dt: DataType, targetAsmVarName: String) {
|
||||
when(dt) {
|
||||
|
@ -36,12 +36,12 @@ fun asmsub6502ArgsEvalOrder(sub: PtAsmSub): List<Int> {
|
||||
|
||||
fun asmsub6502ArgsHaveRegisterClobberRisk(
|
||||
args: List<PtExpression>,
|
||||
paramRegisters: List<Pair<PtSubroutineParameter, RegisterOrStatusflag>>
|
||||
params: List<Pair<PtSubroutineParameter, RegisterOrStatusflag>>
|
||||
): Boolean {
|
||||
fun isClobberRisk(expr: PtExpression): Boolean {
|
||||
when (expr) {
|
||||
is PtArrayIndexer -> {
|
||||
return paramRegisters.any {
|
||||
return params.any {
|
||||
it.second.registerOrPair in listOf(RegisterOrPair.Y, RegisterOrPair.AY, RegisterOrPair.XY)
|
||||
}
|
||||
}
|
||||
|
@ -131,9 +131,7 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as
|
||||
}
|
||||
argOrder.forEach {
|
||||
val param = callee.parameters[it]
|
||||
TODO("pop cpu stack into asmsub param ${param.first.name} ${param.second}")
|
||||
// val targetVar = callee.searchParameter(param.name)!!
|
||||
// asmgen.popCpuStack(param.first.type, targetVar, call.definingISub())
|
||||
asmgen.popCpuStack(callee, param.first, param.second)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user