compiler checks for conflicting register usage in sub arguments vs target parameter registers

This commit is contained in:
Irmen de Jong 2021-02-07 05:25:50 +01:00
parent d7a6b20028
commit 34aa6cc8a2
2 changed files with 22 additions and 6 deletions

View File

@ -1039,6 +1039,28 @@ internal class AstChecker(private val program: Program,
if (!argIDt.isKnown)
return
}
// check that cx16 virtual registers aren't used as arguments in a conflicting way
val params = target.asmParameterRegisters.withIndex().toList()
for(arg in args.withIndex()) {
var ident: IdentifierReference? = null
if(arg.value is IdentifierReference)
ident = arg.value as IdentifierReference
else if(arg.value is FunctionCall) {
val fcall = arg.value as FunctionCall
if(fcall.target.nameInSource == listOf("lsb") || fcall.target.nameInSource == listOf("msb"))
ident = fcall.args[0] as? IdentifierReference
}
if(ident!=null && ident.nameInSource[0] == "cx16" && ident.nameInSource[1].startsWith("r")) {
val reg = RegisterOrPair.valueOf(ident.nameInSource[1].toUpperCase())
val same = params.filter { it.value.registerOrPair==reg }
for(s in same) {
if(s.index!=arg.index) {
errors.err("conflicting register $reg used as argument but is also a target register for another parameter", ident.position)
}
}
}
}
}
}
}

View File

@ -4,12 +4,6 @@
main {
sub start() {
ubyte bank
; TODO give error that a register is used as an argument value and at the same time is a register parameter taking a new value.
; (note: this is OK if the register is used as an argument for a register param that is the same register)
cx16.vaddr(lsb(cx16.r1), cx16.r0, 0, 1)
txt.print("hello")
}
}