refactor: used varargs instead of noOperand
This commit is contained in:
parent
7525e523bb
commit
2c281066a8
@ -3,11 +3,6 @@ package wacc
|
|||||||
object assemblyIR {
|
object assemblyIR {
|
||||||
|
|
||||||
sealed trait Operand
|
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 Src extends Operand // mem location, register and imm value
|
||||||
sealed trait Dest extends Operand // mem location and register
|
sealed trait Dest extends Operand // mem location and register
|
||||||
enum RegSize {
|
enum RegSize {
|
||||||
@ -63,12 +58,8 @@ object assemblyIR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO Check if dest and src are not both memory locations
|
// TODO Check if dest and src are not both memory locations
|
||||||
abstract class Operation(ins: String, op1: Operand = NoOperand, op2: Operand = NoOperand) {
|
abstract class Operation(ins: String, ops: Operand*) {
|
||||||
override def toString: String = if (op2 == NoOperand) {
|
override def toString: String = s"$ins ${ops.mkString(", ")}"
|
||||||
s"$ins ${op1.toString}"
|
|
||||||
} else {
|
|
||||||
s"$ins ${op1.toString}, ${op2.toString}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case class Add(op1: Dest, op2: Src) extends Operation("add", op1, op2)
|
case class Add(op1: Dest, op2: Src) extends Operation("add", op1, op2)
|
||||||
case class Subtract(op1: Dest, op2: Src) extends Operation("sub", op1, op2)
|
case class Subtract(op1: Dest, op2: Src) extends Operation("sub", op1, op2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user