mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 03:54:27 +00:00
ir: fix count register uses
This commit is contained in:
parent
e7682119e0
commit
7b722a0001
@ -6,9 +6,9 @@ import prog8.code.core.DataType
|
|||||||
import prog8.code.core.Position
|
import prog8.code.core.Position
|
||||||
import prog8.code.core.SignedDatatypes
|
import prog8.code.core.SignedDatatypes
|
||||||
import prog8.intermediate.IRCodeChunk
|
import prog8.intermediate.IRCodeChunk
|
||||||
|
import prog8.intermediate.IRDataType
|
||||||
import prog8.intermediate.IRInstruction
|
import prog8.intermediate.IRInstruction
|
||||||
import prog8.intermediate.Opcode
|
import prog8.intermediate.Opcode
|
||||||
import prog8.intermediate.IRDataType
|
|
||||||
|
|
||||||
internal class AssignmentGen(private val codeGen: IRCodeGen, private val expressionEval: ExpressionGen) {
|
internal class AssignmentGen(private val codeGen: IRCodeGen, private val expressionEval: ExpressionGen) {
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import prog8.compiler.CompilationResult
|
|||||||
import prog8.compiler.CompilerArguments
|
import prog8.compiler.CompilerArguments
|
||||||
import prog8.compiler.compileProgram
|
import prog8.compiler.compileProgram
|
||||||
import prog8tests.helpers.*
|
import prog8tests.helpers.*
|
||||||
import prog8tests.helpers.compileText
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.absolute
|
import kotlin.io.path.absolute
|
||||||
import kotlin.io.path.exists
|
import kotlin.io.path.exists
|
||||||
|
@ -33,21 +33,9 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
|
|||||||
out.write("</PROGRAM>\n")
|
out.write("</PROGRAM>\n")
|
||||||
out.close()
|
out.close()
|
||||||
|
|
||||||
var usedRegisters = 0
|
val used = irProgram.registersUsed()
|
||||||
|
val numberUsed = (used.inputRegs.keys + used.outputRegs.keys).size + (used.inputFpRegs.keys + used.outputFpRegs.keys).size
|
||||||
fun addUsed(used: RegistersUsed) {
|
println("($numLines lines in $numChunks code chunks, $numberUsed registers)")
|
||||||
used.inputRegs.forEach{ (reg, count) -> usedRegisters+=count }
|
|
||||||
used.outputRegs.forEach{ (reg, count) -> usedRegisters+=count }
|
|
||||||
used.inputFpRegs.forEach{ (reg, count) -> usedRegisters+=count }
|
|
||||||
used.outputFpRegs.forEach{ (reg, count) -> usedRegisters+=count }
|
|
||||||
}
|
|
||||||
|
|
||||||
irProgram.blocks.forEach {
|
|
||||||
it.inlineAssembly.forEach { chunk -> addUsed(chunk.usedRegisters()) }
|
|
||||||
it.subroutines.flatMap { sub->sub.chunks }.forEach { chunk -> addUsed(chunk.usedRegisters()) }
|
|
||||||
it.asmSubroutines.forEach { asmsub -> addUsed(asmsub.usedRegisters()) }
|
|
||||||
}
|
|
||||||
println("($numLines lines in $numChunks code chunks, $usedRegisters registers)")
|
|
||||||
return outfile
|
return outfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,32 @@ class IRProgram(val name: String,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun registersUsed(): RegistersUsed {
|
||||||
|
val inputRegs = mutableMapOf<Int, Int>().withDefault { 0 }
|
||||||
|
val inputFpRegs = mutableMapOf<Int, Int>().withDefault { 0 }
|
||||||
|
val outputRegs = mutableMapOf<Int, Int>().withDefault { 0 }
|
||||||
|
val outputFpRegs = mutableMapOf<Int, Int>().withDefault { 0 }
|
||||||
|
|
||||||
|
fun addUsed(usedRegisters: RegistersUsed) {
|
||||||
|
usedRegisters.inputRegs.forEach{ (reg, count) -> inputRegs[reg] = inputRegs.getValue(reg) + count }
|
||||||
|
usedRegisters.outputRegs.forEach{ (reg, count) -> outputRegs[reg] = outputRegs.getValue(reg) + count }
|
||||||
|
usedRegisters.inputFpRegs.forEach{ (reg, count) -> inputFpRegs[reg] = inputFpRegs.getValue(reg) + count }
|
||||||
|
usedRegisters.outputFpRegs.forEach{ (reg, count) -> outputFpRegs[reg] = outputFpRegs.getValue(reg) + count }
|
||||||
|
}
|
||||||
|
|
||||||
|
globalInits.forEach {
|
||||||
|
if(it is IRInstruction)
|
||||||
|
it.addUsedRegistersCounts(inputRegs, outputRegs, inputFpRegs, outputFpRegs)
|
||||||
|
}
|
||||||
|
blocks.forEach {
|
||||||
|
it.inlineAssembly.forEach { chunk -> addUsed(chunk.usedRegisters()) }
|
||||||
|
it.subroutines.flatMap { sub->sub.chunks }.forEach { chunk -> addUsed(chunk.usedRegisters()) }
|
||||||
|
it.asmSubroutines.forEach { asmsub -> addUsed(asmsub.usedRegisters()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return RegistersUsed(inputRegs, outputRegs, inputFpRegs, outputFpRegs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IRBlock(
|
class IRBlock(
|
||||||
|
@ -2,7 +2,6 @@ import io.kotest.assertions.throwables.shouldThrow
|
|||||||
import io.kotest.assertions.throwables.shouldThrowWithMessage
|
import io.kotest.assertions.throwables.shouldThrowWithMessage
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import io.kotest.matchers.shouldNotBe
|
|
||||||
import prog8.intermediate.*
|
import prog8.intermediate.*
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package prog8.vm
|
package prog8.vm
|
||||||
|
|
||||||
import prog8.code.core.AssemblyError
|
import prog8.code.core.AssemblyError
|
||||||
import java.lang.NumberFormatException
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user