1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-31 18:41:30 +00:00
millfork/src/test/scala/millfork/test/WarningSuite.scala
Karol Stasiak 90e5360bfd Related to #119:
– Detection of simple byte overflow cases.
– Optimization of 8×8→16 multiplication on 6809.
– Multiplication optimizations on Z80.
2021-08-06 21:01:03 +02:00

91 lines
2.3 KiB
Scala

package millfork.test
import millfork.Cpu
import millfork.test.emu.EmuUnoptimizedCrossPlatformRun
import org.scalatest.{FunSuite, Matchers}
/**
* @author Karol Stasiak
*/
class WarningSuite extends FunSuite with Matchers {
test("Various warnings") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
| void putstrz(pointer p) {}
| byte output@0xc000
| byte main (byte x) {
| putstrz("a")
| byte a
| a
| 5
| a *= 0
| a <<= 0
| output = 4
| }
""".stripMargin) { m =>
m.readByte(0xc000) should equal(4)
}
}
test("Loop over non-volatile variables") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
| byte flag
| volatile byte vflag
| void main () {
| flag = 0
| vflag = 0
| while (flag != 0) {}
| while (vflag != 0) {}
| }
""".stripMargin) { m =>
}
}
test("Warn about byte to pointer comparisons") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
| volatile byte b @$cfff
| noinline void f(){}
| void main () {
| if b == "h" { f() }
| if b == b.pointer { f() }
| if b == b.addr { f() }
| }
""".stripMargin) { m =>
}
}
test("Warn about unintended byte overflow") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos)(
"""
| import zp_reg
| const word screenOffset = (10*40)+5
| noinline void func(byte x, byte y) {
| word screenOffset
| screenOffset = (x*40) + y
| }
| noinline word getNESScreenOffset(byte x, byte y) {
| word temp
| temp = (y << 5) +x
| }
| noinline word getSomeFunc(byte x, byte y, byte z) {
| word temp
| temp = ((x + z) << 2) + (y << 5)
| temp = byte((x + z) << 2) + (y << 5)
| }
|
| noinline byte someFunc(byte x, byte y) {
| return (x*y)-24
| }
| void main() {
| func(0,0)
| getNESScreenOffset(0,0)
| getSomeFunc(0,screenOffset.lo,5)
| someFunc(0,0)
| }
""".stripMargin) { m =>
}
}
}