feat: added runtime errors class and object
This commit is contained in:
16
src/main/wacc/backend/RuntimeErrors.scala
Normal file
16
src/main/wacc/backend/RuntimeErrors.scala
Normal 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")
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package wacc
|
|||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
import cats.data.Chain
|
import cats.data.Chain
|
||||||
import cats.syntax.foldable._
|
import cats.syntax.foldable._
|
||||||
|
import wacc.RuntimeErrors._
|
||||||
|
|
||||||
|
|
||||||
object asmGenerator {
|
object asmGenerator {
|
||||||
import microWacc._
|
import microWacc._
|
||||||
@@ -13,24 +15,6 @@ object asmGenerator {
|
|||||||
import sizeExtensions._
|
import sizeExtensions._
|
||||||
import lexer.escapedChars
|
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 RAX = Register(Q64, AX)
|
||||||
private val EAX = Register(D32, AX)
|
private val EAX = Register(D32, AX)
|
||||||
private val RDI = Register(Q64, DI)
|
private val RDI = Register(Q64, DI)
|
||||||
|
|||||||
Reference in New Issue
Block a user