Skip to content

Commit 2e46d24

Browse files
committed
Added return instruction, removed bug with literal expression conversion
1 parent e99b029 commit 2e46d24

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/main/kotlin/deep/decaf/low/amd64/IRToLow.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ fun irExprToLow(expr: IRExpr): List<Instruction> {
1010
return when (expr) {
1111
is IRIntLiteral -> {
1212
instructions.add(MoveInstruction(ImmediateVal(expr.lit), Register.r10()))
13-
Register.r10()
13+
val tmp = Label(getUUID())
14+
instructions.add(MoveInstruction(Register.r10(), tmp))
15+
tmp
1416
}
1517
is IRBoolLiteral -> {
1618
instructions.add(MoveInstruction(ImmediateVal(if (expr.lit) 1 else 0), Register.r10()))
17-
Register.r10()
19+
val tmp = Label(getUUID())
20+
instructions.add(MoveInstruction(Register.r10(), tmp))
21+
tmp
1822
}
1923
is IRMethodCallExpr -> {
2024
val argLocations = expr.argList.map { traverse(it) }
@@ -294,8 +298,12 @@ fun irMethodToLow(method: IRMethodDeclaration): List<Block> {
294298
blocks.add(loopEndBlock)
295299
loopEndBlock
296300
}
297-
is IRReturnStatement -> TODO()
298-
is IRBlockStatement -> TODO()
301+
is IRReturnStatement -> {
302+
block.instructions.add(LeaveInstruction)
303+
block.instructions.add(ReturnInstruction)
304+
block
305+
}
306+
is IRBlockStatement -> convert(ir.block, block)
299307
}
300308
}
301309
is IRBlock -> {

0 commit comments

Comments
 (0)