1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-18 02:28:57 +00:00

Flow analysis bugfixes

This commit is contained in:
Karol Stasiak 2018-03-09 17:33:39 +01:00
parent a414feedec
commit 871143cc21
3 changed files with 47 additions and 26 deletions

View File

@ -73,8 +73,9 @@ object Status {
val SingleTrue: Status[Boolean] = SingleStatus(true)
val SingleFalse: Status[Boolean] = SingleStatus(false)
val SingleZero: Status[Int] = Status.SingleZero
val SingleFF: Status[Int] = Status.SingleFF
val SingleZero: Status[Int] = SingleStatus(0)
val SingleFF: Status[Int] = SingleStatus(0xff)
@inline
private def wrapBool(b: Boolean) = if (b) SingleTrue else SingleFalse
@ -250,6 +251,20 @@ case class CpuStatus(a: Status[Int] = UnknownStatus,
m: Status[Boolean] = UnknownStatus,
w: Status[Boolean] = UnknownStatus
) {
assert(a ne null)
assert(ah ne null)
assert(x ne null)
assert(y ne null)
assert(iz ne null)
assert(z ne null)
assert(n ne null)
assert(v ne null)
assert(c ne null)
assert(d ne null)
assert(m ne null)
assert(w ne null)
assert(a0 ne null)
assert(a7 ne null)
override def toString: String = s"A=$a,B=$ah,X=$x,Y=$y,Z=$iz; Z=$z,N=$n,C=$c,V=$v,D=$d,M=$m,X=$w; A7=$a7,A0=$a0,NZ:$src"

View File

@ -11,24 +11,24 @@ object FlowAnalyzerForImmediate {
NOP -> ((_, c) => c),
REP -> {(nn, c) =>
var currentStatus = c
if ((nn & 1) != 0) currentStatus.copy(c = Status.SingleFalse)
if ((nn & 2) != 0) currentStatus.copy(z = Status.SingleFalse)
if ((nn & 8) != 0) currentStatus.copy(d = Status.SingleFalse)
if ((nn & 0x10) != 0) currentStatus.copy(w = Status.SingleFalse)
if ((nn & 0x20) != 0) currentStatus.copy(m = Status.SingleFalse)
if ((nn & 0x40) != 0) currentStatus.copy(v = Status.SingleFalse)
if ((nn & 0x80) != 0) currentStatus.copy(n = Status.SingleFalse)
if ((nn & 1) != 0) currentStatus = currentStatus.copy(c = Status.SingleFalse)
if ((nn & 2) != 0) currentStatus = currentStatus.copy(z = Status.SingleFalse)
if ((nn & 8) != 0) currentStatus = currentStatus.copy(d = Status.SingleFalse)
if ((nn & 0x10) != 0) currentStatus = currentStatus.copy(w = Status.SingleFalse)
if ((nn & 0x20) != 0) currentStatus = currentStatus.copy(m = Status.SingleFalse)
if ((nn & 0x40) != 0) currentStatus = currentStatus.copy(v = Status.SingleFalse)
if ((nn & 0x80) != 0) currentStatus = currentStatus.copy(n = Status.SingleFalse)
currentStatus
},
SEP -> {(nn, c) =>
var currentStatus = c
if ((nn & 1) != 0) currentStatus.copy(c = Status.SingleTrue)
if ((nn & 2) != 0) currentStatus.copy(z = Status.SingleTrue)
if ((nn & 8) != 0) currentStatus.copy(d = Status.SingleTrue)
if ((nn & 0x10) != 0) currentStatus.copy(w = Status.SingleTrue)
if ((nn & 0x20) != 0) currentStatus.copy(m = Status.SingleTrue)
if ((nn & 0x40) != 0) currentStatus.copy(v = Status.SingleTrue)
if ((nn & 0x80) != 0) currentStatus.copy(n = Status.SingleTrue)
if ((nn & 1) != 0) currentStatus = currentStatus.copy(c = Status.SingleTrue)
if ((nn & 2) != 0) currentStatus = currentStatus.copy(z = Status.SingleTrue)
if ((nn & 8) != 0) currentStatus = currentStatus.copy(d = Status.SingleTrue)
if ((nn & 0x10) != 0) currentStatus = currentStatus.copy(w = Status.SingleTrue)
if ((nn & 0x20) != 0) currentStatus = currentStatus.copy(m = Status.SingleTrue)
if ((nn & 0x40) != 0) currentStatus = currentStatus.copy(v = Status.SingleTrue)
if ((nn & 0x80) != 0) currentStatus = currentStatus.copy(n = Status.SingleTrue)
currentStatus
},
LDX -> {(nn, currentStatus) =>

View File

@ -17,6 +17,12 @@ object FlowAnalyzerForTheRest {
DISCARD_AF -> identity,
DISCARD_XF -> identity,
DISCARD_YF -> identity,
REP -> (currentStatus => {
currentStatus.copy(c = AnyStatus, d = AnyStatus, n = AnyStatus, z= AnyStatus, v = AnyStatus, m = AnyStatus, w = AnyStatus)
}),
SEP -> (currentStatus => {
currentStatus.copy(c = AnyStatus, d = AnyStatus, n = AnyStatus, z= AnyStatus, v = AnyStatus, m = AnyStatus, w = AnyStatus)
}),
BCC -> (currentStatus => {
currentStatus.copy(c = Status.SingleTrue)
}),
@ -31,17 +37,17 @@ object FlowAnalyzerForTheRest {
}),
BMI -> (c => {
var currentStatus = c
currentStatus.copy(n = Status.SingleFalse)
currentStatus = currentStatus.copy(n = Status.SingleFalse)
if (currentStatus.src.isFromA) {
currentStatus.copy(a7 = Status.SingleTrue)
currentStatus = currentStatus.copy(a7 = Status.SingleTrue)
}
currentStatus
}),
BPL -> (c => {
var currentStatus = c
currentStatus.copy(n = Status.SingleTrue)
currentStatus = currentStatus.copy(n = Status.SingleTrue)
if (currentStatus.src.isFromA) {
currentStatus.copy(a7 = Status.SingleFalse)
currentStatus = currentStatus.copy(a7 = Status.SingleFalse)
}
currentStatus
}),
@ -50,25 +56,25 @@ object FlowAnalyzerForTheRest {
}),
BNE -> (c => {
var currentStatus = c
currentStatus.copy(z = Status.SingleTrue)
currentStatus = currentStatus.copy(z = Status.SingleTrue)
if (currentStatus.src.isFromA) {
currentStatus.copy(a7 = Status.SingleFalse, a0 = Status.SingleFalse, a = Status.SingleZero)
currentStatus = currentStatus.copy(a7 = Status.SingleFalse, a0 = Status.SingleFalse, a = Status.SingleZero)
}
if (currentStatus.src.isFromAW) {
currentStatus.copy(
currentStatus = currentStatus.copy(
a7 = Status.SingleFalse,
a0 = Status.SingleFalse,
a = Status.SingleZero,
ah = Status.SingleZero)
}
if (currentStatus.src.isFromX) {
currentStatus.copy(x = Status.SingleZero)
currentStatus = currentStatus.copy(x = Status.SingleZero)
}
if (currentStatus.src.isFromY) {
currentStatus.copy(y = Status.SingleZero)
currentStatus = currentStatus.copy(y = Status.SingleZero)
}
if (currentStatus.src.isFromIZ) {
currentStatus.copy(iz = Status.SingleZero)
currentStatus = currentStatus.copy(iz = Status.SingleZero)
}
currentStatus
}),