6809: Fix constant condition compilation

This commit is contained in:
Karol Stasiak 2021-11-22 01:58:09 +01:00
parent a260d0a806
commit b1a2be5574
2 changed files with 17 additions and 2 deletions

View File

@ -80,10 +80,22 @@ object M6809ExpressionCompiler extends AbstractExpressionCompiler[MLine] {
}
env.eval(expr) match {
case Some(c) =>
return target match {
return (target match {
case MExpressionTarget.NOTHING => Nil
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 =>
}
expr match {

View File

@ -28,6 +28,7 @@ sealed trait Constant {
def isQuiteNegative: Boolean = false
def isProvablyZero: Boolean = false
def isProvablyNonZero: Boolean = false
def isProvably(value: Int): Boolean = false
def isProvablyInRange(startInclusive: Int, endInclusive: Int): 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 isProvablyGreaterOrEqualThan(other: Constant): Boolean = c.isProvablyGreaterOrEqualThan(other)
override def isProvablyZero: Boolean = c.isProvablyZero
override def isProvablyNonZero: Boolean = c.isProvablyNonZero
override def isProvably(i: Int): Boolean = c.isProvably(i)
override def isProvablyNonnegative: Boolean = c.isProvablyNonnegative
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 isProvablyZero: Boolean = value == 0
override def isProvablyNonZero: Boolean = value.&(0x1L.<<(8 * requiredSize - 1)) != 0
override def isProvably(i: Int): Boolean = value == i
override def isProvablyNonnegative: Boolean = value >= 0
override def isProvablyNegative(asType: Type): Boolean = {