From b72d00251a8c002481d2a2b3f3d08b410eb8f191 Mon Sep 17 00:00:00 2001 From: Cr0a3 <127748753+Cr0a3@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:23:59 +0000 Subject: [PATCH] [FIX] fixing add lowering for x64 + [FIX] upsi i forgot that return codes are u8s and not u32 ... so the top bytes would be cut off that was why i got wrong results --- src/Target/x64/lower.rs | 7 +++++-- tests/IR/add1.yl | 2 +- tests/IR/add2.yl | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Target/x64/lower.rs b/src/Target/x64/lower.rs index 39d2f03e..f514f2d8 100644 --- a/src/Target/x64/lower.rs +++ b/src/Target/x64/lower.rs @@ -71,8 +71,11 @@ fn x64_lower_add(sink: &mut Vec, instr: &MachineInstr) { }, }; - sink.push( X64MCInstr::with2(Mnemonic::Mov, out.clone(), op1).into() ); - sink.push( X64MCInstr::with2(Mnemonic::Add, out, op2).into() ); + let tmp = || Operand::Reg(x64Reg::Rax.sub_ty(instr.meta)); + + sink.push( X64MCInstr::with2(Mnemonic::Mov, tmp(), op1).into() ); + sink.push( X64MCInstr::with2(Mnemonic::Add, tmp(), op2).into() ); + sink.push( X64MCInstr::with2(Mnemonic::Mov, out, tmp()).into() ); } diff --git a/tests/IR/add1.yl b/tests/IR/add1.yl index b6340533..62bf3421 100644 --- a/tests/IR/add1.yl +++ b/tests/IR/add1.yl @@ -1,5 +1,5 @@ # RUN: -cargo run -p ylc -- -in=%s -o=out.o -asm-clr +cargo run -p ylc -- -in=%s -o=out.o gcc out.o -o a.exe ./a.exe # IN: diff --git a/tests/IR/add2.yl b/tests/IR/add2.yl index ce4d902d..f9a6e398 100644 --- a/tests/IR/add2.yl +++ b/tests/IR/add2.yl @@ -6,9 +6,9 @@ gcc out.o -o a.exe define i32 @main() { entry: %0 = i32 134 - %1 = add i32 %0, 523 + %1 = add i32 %0, 23 ret i32 %1 } -# EXIT_CODE=657 \ No newline at end of file +# EXIT_CODE=157 \ No newline at end of file