fix: escape characters within assembly
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user