ir: fix initial chunk linking

This commit is contained in:
Irmen de Jong 2023-07-07 00:05:07 +02:00
parent ffb2027a19
commit 02e51d8282
6 changed files with 22 additions and 6 deletions

View File

@ -29,7 +29,7 @@ internal class BuiltinFuncGen(private val codeGen: IRCodeGen, private val exprGe
"rsavex",
"rrestore",
"rrestorex" -> ExpressionCodeResult.EMPTY // vm doesn't have registers to save/restore
"callfar" -> throw AssemblyError("callfar() is for cx16 target only")
"callfar" -> funcCallfar(call)
"msb" -> funcMsb(call)
"lsb" -> funcLsb(call)
"memory" -> funcMemory(call)
@ -53,6 +53,18 @@ internal class BuiltinFuncGen(private val codeGen: IRCodeGen, private val exprGe
}
}
private fun funcCallfar(call: PtBuiltinFunctionCall): ExpressionCodeResult {
val result = mutableListOf<IRCodeChunkBase>()
val bankTr = exprGen.translateExpression(call.args[0])
val addressTr = exprGen.translateExpression(call.args[1])
val argumentwordTr = exprGen.translateExpression(call.args[2])
addToResult(result, bankTr, bankTr.resultReg, -1)
addToResult(result, addressTr, addressTr.resultReg, -1)
addToResult(result, argumentwordTr, argumentwordTr.resultReg, -1)
result += codeGen.makeSyscall(IMSyscall.CALLFAR, listOf(IRDataType.BYTE to bankTr.resultReg, IRDataType.WORD to addressTr.resultReg, IRDataType.WORD to argumentwordTr.resultReg), IRDataType.WORD to argumentwordTr.resultReg)
return ExpressionCodeResult(result, IRDataType.WORD, argumentwordTr.resultReg, -1)
}
private fun funcDivmod(call: PtBuiltinFunctionCall, type: IRDataType): ExpressionCodeResult {
val result = mutableListOf<IRCodeChunkBase>()
val number = call.args[0]

View File

@ -1,7 +1,8 @@
TODO
====
- Fix expericodegen errors (examples/cx16/keyboardhandler, rockrunners etc)
- Fix wrong unused subroutines in expericodegen with cx16 shell
- Fix expericodegen errors (chess, assem, musicdemo, rockrunners etc)
...

View File

@ -26,5 +26,6 @@ enum class IMSyscall(val number: Int) {
CLAMP_BYTE(0x1012),
CLAMP_UWORD(0x1013),
CLAMP_WORD(0x1014),
CLAMP_FLOAT(0x1015)
CLAMP_FLOAT(0x1015),
CALLFAR(0x1016),
}

View File

@ -96,9 +96,10 @@ class IRProgram(val name: String,
// link globalinits to subsequent chunk
val firstBlock = blocks.firstOrNull()
if(firstBlock!=null && firstBlock.isNotEmpty()) {
firstBlock.children.forEach { child ->
firstBlock.children.first().let { child ->
when(child) {
is IRAsmSubroutine -> throw AssemblyError("cannot link next to asmsub $child")
is IRAsmSubroutine ->
throw AssemblyError("cannot link next to asmsub $child")
is IRCodeChunk -> globalInits.next = child
is IRInlineAsmChunk -> globalInits.next = child
is IRInlineBinaryChunk -> globalInits.next = child

View File

@ -52,7 +52,7 @@ SYSCALLS:
41 = CLAMP_WORD
42 = CLAMP_UWORD
43 = CLAMP_FLOAT
43 = ATAN
44 = ATAN
*/
enum class Syscall {

View File

@ -124,6 +124,7 @@ class VmProgramLoader {
IMSyscall.CLAMP_WORD.number -> Syscall.CLAMP_WORD
IMSyscall.CLAMP_UWORD.number -> Syscall.CLAMP_UWORD
IMSyscall.CLAMP_FLOAT.number -> Syscall.CLAMP_FLOAT
IMSyscall.CALLFAR.number -> throw IRParseException("vm doesn't support the callfar() syscall")
else -> null
}