remove some more dead code

This commit is contained in:
Irmen de Jong 2019-07-18 01:31:12 +02:00
parent b4e1b42cec
commit 2a6b0f5db7
3 changed files with 62 additions and 23 deletions

View File

@ -28,29 +28,17 @@ class IntermediateProgram(val name: String, var loadAddress: Int, val heap: Heap
val memoryPointers: MutableMap<String, Pair<Int, DataType>> = mutableMapOf(),
val labels: MutableMap<String, Instruction> = mutableMapOf(), // names are fully scoped
val force_output: Boolean)
{
val numVariables: Int
get() { return variables.size }
val numInstructions: Int
get() { return instructions.filter { it.opcode!= Opcode.LINE }.size }
val variablesMarkedForZeropage: MutableSet<String> = mutableSetOf() // TODO maybe this can be removed now we have ValueParameters
}
val allocatedZeropageVariables = mutableMapOf<String, Pair<Int, DataType>>()
val blocks = mutableListOf<ProgramBlock>()
val memory = mutableMapOf<Int, List<RuntimeValue>>()
private lateinit var currentBlock: ProgramBlock
val numVariables: Int
get() = blocks.sumBy { it.numVariables }
val numInstructions: Int
get() = blocks.sumBy { it.numInstructions }
fun allocateZeropage(zeropage: Zeropage) {
// allocates all @zp marked variables on the zeropage (for all blocks, as long as there is space in the ZP)
var notAllocated = 0
for(block in blocks) {
val zpVariables = block.variables.filter { it.scopedname in block.variablesMarkedForZeropage }
val zpVariables = block.variables.filter { it.params.zp==ZeropageWish.REQUIRE_ZEROPAGE || it.params.zp==ZeropageWish.PREFER_ZEROPAGE }
if (zpVariables.isNotEmpty()) {
for (variable in zpVariables) {
if(variable.params.zp==ZeropageWish.NOT_IN_ZEROPAGE || variable.params.memberOfStruct!=null)
@ -433,10 +421,6 @@ class IntermediateProgram(val name: String, var loadAddress: Int, val heap: Heap
else -> throw CompilerException("weird datatype")
}
currentBlock.variables.add(Variable(scopedname, value, valueparams))
if(decl.zeropage==ZeropageWish.PREFER_ZEROPAGE)
currentBlock.variablesMarkedForZeropage.add(scopedname)
else if(decl.zeropage==ZeropageWish.REQUIRE_ZEROPAGE)
TODO("REQUIRE_ZEROPAGE not yet implemented")
}
VarDeclType.MEMORY -> {
// note that constants are all folded away, but assembly code may still refer to them

View File

@ -49,7 +49,6 @@ class AsmGen(private val options: CompilationOptions, private val program: Inter
val newblocks = mutableListOf<IntermediateProgram.ProgramBlock>()
for(block in program.blocks) {
val newvars = block.variables.map { IntermediateProgram.Variable(symname(it.scopedname, block), it.value, it.params) }.toMutableList()
val newvarsZeropaged = block.variablesMarkedForZeropage.map{symname(it, block)}.toMutableSet()
val newlabels = block.labels.map { symname(it.key, block) to it.value}.toMap().toMutableMap()
val newinstructions = block.instructions.asSequence().map {
when {
@ -70,8 +69,6 @@ class AsmGen(private val options: CompilationOptions, private val program: Inter
newMempointers,
newlabels,
force_output = block.force_output)
newblock.variablesMarkedForZeropage.clear()
newblock.variablesMarkedForZeropage.addAll(newvarsZeropaged)
newblocks.add(newblock)
}
program.blocks.clear()
@ -253,7 +250,6 @@ class AsmGen(private val options: CompilationOptions, private val program: Inter
val address = zeropage.allocate(sym, variable.value.type, null)
out("${variable.scopedname} = $address\t; auto zp ${variable.value.type}")
// make sure we add the var to the set of zpvars for this block
blk.variablesMarkedForZeropage.add(variable.scopedname)
program.allocatedZeropageVariables[sym] = Pair(address, variable.value.type)
} catch (x: ZeropageDepletedError) {
// leave it as it is.
@ -310,8 +306,9 @@ class AsmGen(private val options: CompilationOptions, private val program: Inter
out("; other variables sorted by type")
val sortedVars = normalVars.sortedBy { it.value.type }
for (variable in sortedVars) {
if(variable.scopedname in block.variablesMarkedForZeropage)
continue // skip the ones that belong in the zero page
val sym = symname(block.name + "." + variable.scopedname, null)
if(sym in program.allocatedZeropageVariables)
continue // skip the ones that already belong in the zero page
vardecl2asm(variable.scopedname, variable.value, variable.params)
}
}

View File

@ -7,11 +7,69 @@
sub start() {
word w1
word w2
word w3
word w4
word w5
word w6
word w7
word w8
word w9
word w10
word w11
word w12
word w13
word w14
word w15
word w16
word w17
word w18
word w19
word @zp w20
word @zp w21
word w22
word w23
word w24
word w25
word w26
word w27
word w28
word w29
word w30
ubyte[] blaat = 10 to 20
for ubyte c in 'a' to 'z' {
c64.CHROUT(blaat[c])
}
word q
q=w26
q+=w27
q+=w28
q+=w29
q+=w30
q+=w10
q+=w11
q+=w12
q+=w13
q+=w14
q+=w15
q+=w16
q+=w17
q+=w18
q+=w19
q+=w20
q+=w21
q+=w22
q+=w23
q+=w24
q+=w25
q+=w26
q+=w27
}
}