feat: added runtime errors class and object

This commit is contained in:
Jonny
2025-02-27 19:13:17 +00:00
parent 9b9f0a80cb
commit 332c00b15b
2 changed files with 18 additions and 18 deletions

View File

@@ -0,0 +1,16 @@
package wacc
import cats.data.Chain
import wacc.assemblyIR._
case class RuntimeError(strLabel: String, errStr: String, errLabel: String) {
def stringDef: Chain[AsmLine] = Chain(
Directive.Int(errStr.size),
LabelDef(strLabel),
Directive.Asciz(errStr)
)
}
object RuntimeErrors {
val zeroDivError = RuntimeError(".L._errDivZero_str0", "fatal error: division or modulo by zero", ".L._errDivZero")
}

View File

@@ -3,6 +3,8 @@ package wacc
import scala.collection.mutable.ListBuffer
import cats.data.Chain
import cats.syntax.foldable._
import wacc.RuntimeErrors._
object asmGenerator {
import microWacc._
@@ -13,24 +15,6 @@ object asmGenerator {
import sizeExtensions._
import lexer.escapedChars
abstract case class Error() {
def strLabel: String
def errStr: String
def errLabel: String
def stringDef: Chain[AsmLine] = Chain(
Directive.Int(errStr.size),
LabelDef(strLabel),
Directive.Asciz(errStr)
)
}
object zeroDivError extends Error {
// TODO: is this bad? Can we make an error case class/some other structure?
def strLabel = ".L._errDivZero_str0"
def errStr = "fatal error: division or modulo by zero"
def errLabel = ".L._errDivZero"
}
private val RAX = Register(Q64, AX)
private val EAX = Register(D32, AX)
private val RDI = Register(Q64, DI)