fix: escape characters within assembly

This commit is contained in:
2025-02-25 17:07:21 +00:00
parent 8558733719
commit 5f8b87221c
2 changed files with 22 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ object asmGenerator {
import microWacc._
import assemblyIR._
import wacc.types._
import lexer.escapedChars
val RAX = Register(RegSize.R64, RegName.AX)
val EAX = Register(RegSize.E32, RegName.AX)
@@ -53,7 +54,7 @@ object asmGenerator {
List(
Directive.Int(str.size),
LabelDef(s".L.str$i"),
Directive.Asciz(str.replace("\"", "\\\""))
Directive.Asciz(str.escaped)
)
}
@@ -387,4 +388,10 @@ object asmGenerator {
// TODO: Might want to actually properly handle this with the LinkedHashMap too
def align(): AsmLine = And(RSP, ImmediateVal(-16))
}
private val escapedCharsMapping = escapedChars.map { case (k, v) => v -> s"\\$k" }
extension (s: String) {
private def escaped: String =
s.flatMap(c => escapedCharsMapping.getOrElse(c, c.toString))
}
}