feat: add writer for assembly code

This commit is contained in:
Barf-Vader 2025-02-20 19:47:24 +00:00
parent 2a234f6db8
commit 67f7e64b95
2 changed files with 14 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package wacc
object assemblyIR {
sealed trait AsmLine
sealed trait Operand
sealed trait Src extends Operand // mem location, register and imm value
sealed trait Dest extends Operand // mem location and register
@ -58,7 +59,7 @@ object assemblyIR {
}
// TODO Check if dest and src are not both memory locations
abstract class Operation(ins: String, ops: Operand*) {
abstract class Operation(ins: String, ops: Operand*) extends AsmLine {
override def toString: String = s"\t$ins ${ops.mkString(", ")}"
}
case class Add(op1: Dest, op2: Src) extends Operation("add", op1, op2)
@ -83,7 +84,7 @@ object assemblyIR {
case class Jump(op1: LabelArg, condition: Cond = Cond.Always)
extends Operation(s"j${condition.toString}", op1)
case class LabelDef(name: String) {
case class LabelDef(name: String) extends AsmLine {
override def toString = s"$name:"
}

View File

@ -0,0 +1,11 @@
package wacc
import java.io.PrintStream
object writer {
import assemblyIR._
def writeTo(asmList: List[AsmLine], printStream: PrintStream): Unit = {
asmList.foreach(printStream.println)
}
}