fixed incorrect removal of certain assignments that are NOT double

This commit is contained in:
Irmen de Jong 2020-10-19 02:16:23 +02:00
parent aec3b82476
commit ec665e0cc1
5 changed files with 19 additions and 9 deletions

View File

@ -415,10 +415,6 @@ open class Assignment(var target: AssignTarget, var value: Expression, override
return if(subCast!=null) subCast.expression isSameAs target else castExpr.expression isSameAs target
}
if(target.identifier!=null) {
return value.referencesIdentifier(*(target.identifier!!.nameInSource.toTypedArray()))
}
return false
}
}

View File

@ -221,7 +221,7 @@ private fun writeAssembly(programAst: Program, errors: ErrorReporter, outputDir:
programAst.processAstBeforeAsmGeneration(errors)
errors.handle()
printAst(programAst) // TODO
// printAst(programAst)
CompilationTarget.instance.machine.initializeZeropage(compilerOptions)
val assembly = CompilationTarget.instance.asmGenerator(

View File

@ -494,9 +494,9 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
swapArrayValues(elementDt, arrayVarName1, firstVar, arrayVarName2, secondVar)
return
} else if(firstNum!=null && secondVar!=null) {
TODO("swap array num/var")
TODO("swap array num/var") // TODO *****************************
} else if(firstVar!=null && secondNum!=null) {
TODO("swap array var/num")
TODO("swap array var/num") // TODO *****************************
}
}

View File

@ -91,8 +91,10 @@ internal class UnusedCodeRemover(private val program: Program, private val error
val assign1 = stmtPairs[0] as? Assignment
val assign2 = stmtPairs[1] as? Assignment
if (assign1 != null && assign2 != null && !assign2.isAugmentable) {
if (assign1.target.isSameAs(assign2.target, program) && assign1.target.isInRegularRAM(program.namespace))
linesToRemove.add(assign1)
if (assign1.target.isSameAs(assign2.target, program) && assign1.target.isInRegularRAM(program.namespace)) {
if(assign2.target.identifier==null || !assign2.value.referencesIdentifier(*(assign2.target.identifier!!.nameInSource.toTypedArray())))
linesToRemove.add(assign1)
}
}
}

View File

@ -12,6 +12,18 @@ main {
ubyte ub
byte bb
uw = 21111
uw >>= 6
txt.print_uwbin(uw as uword, true)
txt.chrout('\n')
uw = 21111
uw >>= 7
txt.print_uwbin(uw as uword, true)
txt.chrout('\n')
uw = 21111
uw >>= 8 ; TODO fix this shift!
txt.print_uwbin(uw as uword, true)
txt.chrout('\n')
uw = 21111
uw >>= 9 ; TODO fix this shift!
txt.print_uwbin(uw as uword, true)