feat: almost implemented arrays

This commit is contained in:
Alex Ling
2025-02-26 21:12:50 +00:00
committed by Gleb Koval
parent bdee6ba756
commit 808a59f58a
5 changed files with 75 additions and 19 deletions

View File

@@ -48,7 +48,9 @@ object assemblyIR {
case Scanf,
Fflush,
Exit,
PrintF
PrintF,
Malloc,
Free
private val plt = "@plt"
@@ -57,6 +59,8 @@ object assemblyIR {
case Fflush => "fflush" + plt
case Exit => "exit" + plt
case PrintF => "printf" + plt
case Malloc => "malloc" + plt
case Free => "free" + plt
}
}
@@ -72,13 +76,20 @@ object assemblyIR {
case reg: Register => opSize.toString + s"[$reg]"
}
}
// TODO to string is wacky
case class IndexAddress(
base: Register,
offset: Int | LabelArg,
opSize: SizeDir = SizeDir.Unspecified
indexReg: Register = Register(RegSize.R64, RegName.AX),
scale: Int = 0
) extends Dest
with Src {
override def toString = s"$opSize[$base + $offset]"
override def toString = if (scale != 0) {
s"[$base + $indexReg * $scale + $offset]"
} else {
s"[$base + $offset]"
}
}
case class ImmediateVal(value: Int) extends Src {
@@ -185,7 +196,7 @@ object assemblyIR {
override def toString(): String = this match {
case Byte => "byte " + ptr
case Word => "word " + ptr // TODO check word/doubleword/quadword
case Word => "word " + ptr
case DWord => "dword " + ptr
case Unspecified => ""
}