mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
compiler checks for conflicting register usage in sub arguments vs target parameter registers
This commit is contained in:
parent
d7a6b20028
commit
34aa6cc8a2
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user