ir: JUMPI instruction added to support indirect jumps

This commit is contained in:
Irmen de Jong
2023-07-07 18:25:05 +02:00
parent 90c4b00f74
commit 334d382bfa
6 changed files with 31 additions and 22 deletions
@@ -147,6 +147,10 @@ class VirtualMachine(irProgram: IRProgram) {
null -> {
if(i.address!=null)
throw IllegalArgumentException("vm program can't jump to system memory address (${i.opcode} ${i.address!!.toHex()})")
else if(i.labelSymbol!=null)
throw IllegalArgumentException("vm program can't jump to system memory address (${i.opcode} ${i.labelSymbol})")
else if(i.reg1!=null)
throw IllegalArgumentException("vm program can't jump to system memory address (${i})")
else
throw IllegalArgumentException("no branchtarget in $i")
}
@@ -174,8 +178,7 @@ class VirtualMachine(irProgram: IRProgram) {
Opcode.STOREZM -> InsSTOREZM(ins)
Opcode.STOREZX -> InsSTOREZX(ins)
Opcode.STOREZI -> InsSTOREZI(ins)
Opcode.JUMP -> InsJUMP(ins)
Opcode.JUMPA -> throw IllegalArgumentException("vm program can't jump to system memory address (JUMPA)")
Opcode.JUMP, Opcode.JUMPI -> InsJUMP(ins)
Opcode.CALL -> InsCALL(ins)
Opcode.SYSCALL -> InsSYSCALL(ins)
Opcode.RETURN -> InsRETURN()
@@ -191,8 +191,6 @@ class VmProgramLoader {
}
}
private val functionCallOpcodes = setOf(Opcode.CALL, Opcode.SYSCALL, Opcode.JUMP, Opcode.JUMPA)
private fun varsToMemory(
program: IRProgram,
allocations: VmVariableAllocator,