mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-08 22:30:34 +00:00
6809: Fix constant condition compilation
This commit is contained in:
parent
a260d0a806
commit
b1a2be5574
@ -80,10 +80,22 @@ object M6809ExpressionCompiler extends AbstractExpressionCompiler[MLine] {
|
|||||||
}
|
}
|
||||||
env.eval(expr) match {
|
env.eval(expr) match {
|
||||||
case Some(c) =>
|
case Some(c) =>
|
||||||
return target match {
|
return (target match {
|
||||||
case MExpressionTarget.NOTHING => Nil
|
case MExpressionTarget.NOTHING => Nil
|
||||||
case _ => List(MLine.immediate(toLd(target), c))
|
case _ => List(MLine.immediate(toLd(target), c))
|
||||||
}
|
}) ++ (branches match {
|
||||||
|
case BranchIfTrue(l) if c.isProvablyNonZero => List(MLine(JMP, Absolute(false), Label(l).toAddress))
|
||||||
|
case BranchIfTrue(l) =>
|
||||||
|
// TODO: ??
|
||||||
|
if (target == MExpressionTarget.NOTHING) List(MLine.immediate(LDB, c), MLine.longBranch(BNE, l))
|
||||||
|
else List(MLine.longBranch(BNE, l))
|
||||||
|
case BranchIfFalse(l) if c.isProvablyZero => List(MLine(JMP, Absolute(false), Label(l).toAddress))
|
||||||
|
case BranchIfFalse(l) =>
|
||||||
|
// TODO: ??
|
||||||
|
if (target == MExpressionTarget.NOTHING) List(MLine.immediate(LDB, c), MLine.longBranch(BEQ, l))
|
||||||
|
else List(MLine.longBranch(BEQ, l))
|
||||||
|
case NoBranching => Nil
|
||||||
|
})
|
||||||
case None =>
|
case None =>
|
||||||
}
|
}
|
||||||
expr match {
|
expr match {
|
||||||
|
3
src/main/scala/millfork/env/Constant.scala
vendored
3
src/main/scala/millfork/env/Constant.scala
vendored
@ -28,6 +28,7 @@ sealed trait Constant {
|
|||||||
|
|
||||||
def isQuiteNegative: Boolean = false
|
def isQuiteNegative: Boolean = false
|
||||||
def isProvablyZero: Boolean = false
|
def isProvablyZero: Boolean = false
|
||||||
|
def isProvablyNonZero: Boolean = false
|
||||||
def isProvably(value: Int): Boolean = false
|
def isProvably(value: Int): Boolean = false
|
||||||
def isProvablyInRange(startInclusive: Int, endInclusive: Int): Boolean = false
|
def isProvablyInRange(startInclusive: Int, endInclusive: Int): Boolean = false
|
||||||
def isProvablyNonnegative: Boolean = false
|
def isProvablyNonnegative: Boolean = false
|
||||||
@ -183,6 +184,7 @@ case class AssertByte(c: Constant) extends Constant {
|
|||||||
override def isQuiteNegative: Boolean = c.isQuiteNegative
|
override def isQuiteNegative: Boolean = c.isQuiteNegative
|
||||||
override def isProvablyGreaterOrEqualThan(other: Constant): Boolean = c.isProvablyGreaterOrEqualThan(other)
|
override def isProvablyGreaterOrEqualThan(other: Constant): Boolean = c.isProvablyGreaterOrEqualThan(other)
|
||||||
override def isProvablyZero: Boolean = c.isProvablyZero
|
override def isProvablyZero: Boolean = c.isProvablyZero
|
||||||
|
override def isProvablyNonZero: Boolean = c.isProvablyNonZero
|
||||||
override def isProvably(i: Int): Boolean = c.isProvably(i)
|
override def isProvably(i: Int): Boolean = c.isProvably(i)
|
||||||
override def isProvablyNonnegative: Boolean = c.isProvablyNonnegative
|
override def isProvablyNonnegative: Boolean = c.isProvablyNonnegative
|
||||||
override def isProvablyNegative(asType: Type): Boolean = c.isProvablyNegative(asType)
|
override def isProvablyNegative(asType: Type): Boolean = c.isProvablyNegative(asType)
|
||||||
@ -277,6 +279,7 @@ case class NumericConstant(value: Long, requiredSize: Int) extends Constant {
|
|||||||
})
|
})
|
||||||
override def isProvablyInRange(startInclusive: Int, endInclusive: Int): Boolean = value >= startInclusive && value <= endInclusive
|
override def isProvablyInRange(startInclusive: Int, endInclusive: Int): Boolean = value >= startInclusive && value <= endInclusive
|
||||||
override def isProvablyZero: Boolean = value == 0
|
override def isProvablyZero: Boolean = value == 0
|
||||||
|
override def isProvablyNonZero: Boolean = value.&(0x1L.<<(8 * requiredSize - 1)) != 0
|
||||||
override def isProvably(i: Int): Boolean = value == i
|
override def isProvably(i: Int): Boolean = value == i
|
||||||
override def isProvablyNonnegative: Boolean = value >= 0
|
override def isProvablyNonnegative: Boolean = value >= 0
|
||||||
override def isProvablyNegative(asType: Type): Boolean = {
|
override def isProvablyNegative(asType: Type): Boolean = {
|
||||||
|
Loading…
Reference in New Issue
Block a user