refactor: used varargs instead of noOperand

This commit is contained in:
Barf-Vader 2025-02-17 18:07:36 +00:00
parent 7525e523bb
commit 2c281066a8

View File

@ -3,11 +3,6 @@ package wacc
object assemblyIR {
sealed trait Operand
// did not use option because we'd have to wrap each op around Some(). can refactor
case object NoOperand extends Operand {
override def toString = ""
}
sealed trait Src extends Operand // mem location, register and imm value
sealed trait Dest extends Operand // mem location and register
enum RegSize {
@ -63,12 +58,8 @@ object assemblyIR {
}
// TODO Check if dest and src are not both memory locations
abstract class Operation(ins: String, op1: Operand = NoOperand, op2: Operand = NoOperand) {
override def toString: String = if (op2 == NoOperand) {
s"$ins ${op1.toString}"
} else {
s"$ins ${op1.toString}, ${op2.toString}"
}
abstract class Operation(ins: String, ops: Operand*) {
override def toString: String = s"$ins ${ops.mkString(", ")}"
}
case class Add(op1: Dest, op2: Src) extends Operation("add", op1, op2)
case class Subtract(op1: Dest, op2: Src) extends Operation("sub", op1, op2)