mirror of
https://github.com/irmen/prog8.git
synced 2024-05-29 01:41:32 +00:00
41 lines
1.4 KiB
Kotlin
41 lines
1.4 KiB
Kotlin
package prog8.codegen.cpu6502
|
|
|
|
import prog8.code.ast.IPtSubroutine
|
|
import prog8.code.ast.PtAsmSub
|
|
import prog8.code.ast.PtSub
|
|
import prog8.code.core.*
|
|
|
|
|
|
internal fun IPtSubroutine.returnsWhatWhere(): List<Pair<RegisterOrStatusflag, DataType>> {
|
|
when(this) {
|
|
is PtAsmSub -> {
|
|
return returns
|
|
}
|
|
is PtSub -> {
|
|
// for non-asm subroutines, determine the return registers based on the type of the return value
|
|
return if(returntype==null)
|
|
emptyList()
|
|
else {
|
|
val register = when (returntype!!) {
|
|
in ByteDatatypes -> RegisterOrStatusflag(RegisterOrPair.A, null)
|
|
in WordDatatypes -> RegisterOrStatusflag(RegisterOrPair.AY, null)
|
|
DataType.FLOAT -> RegisterOrStatusflag(RegisterOrPair.FAC1, null)
|
|
else -> RegisterOrStatusflag(RegisterOrPair.AY, null)
|
|
}
|
|
listOf(Pair(register, returntype!!))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
internal fun PtSub.returnRegister(): RegisterOrStatusflag? {
|
|
return when(returntype) {
|
|
in ByteDatatypes -> RegisterOrStatusflag(RegisterOrPair.A, null)
|
|
in WordDatatypes -> RegisterOrStatusflag(RegisterOrPair.AY, null)
|
|
DataType.FLOAT -> RegisterOrStatusflag(RegisterOrPair.FAC1, null)
|
|
null -> null
|
|
else -> RegisterOrStatusflag(RegisterOrPair.AY, null)
|
|
}
|
|
}
|