Skip to content

Commit

Permalink
fix riscv codegen bug
Browse files Browse the repository at this point in the history
  • Loading branch information
glyh committed Oct 22, 2024
1 parent ab2871a commit 6bcafec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/riscv/codegen.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,6 @@ fn CodegenBlock::resolve_loop(
}
for item in args_regs_list {
let (val, reg_detect) = item
guard let Var(_) = val else {
_ => {
self.cur_fn.val.body.push(
Comment("pull immediate \{val} on to \{reg_detect}"),
)
let pulled_reg = match val.get_type() {
Double => F(self.pull_val_f(val))
_ => I(self.pull_val_i(val))
}
self.mov_reg(reg_detect, pulled_reg)
continue
}
}
if in_place.contains(reg_detect) {
continue
}
Expand Down Expand Up @@ -400,6 +387,22 @@ fn CodegenBlock::resolve_loop(
}
}
}
// writing to cur reg still may affect other regs that needs value on us, so
// we do this after chain is done
guard let Var(_) = val else {
_ => {
self.cur_fn.val.body.push(
Comment("pull immediate \{val} on to \{reg_detect}"),
)
let pulled_reg = match val.get_type() {
Double => F(self.pull_val_f(val))
_ => I(self.pull_val_i(val))
}
self.mov_reg(reg_detect, pulled_reg)
continue
}
}

}
}

Expand Down Expand Up @@ -810,7 +813,7 @@ fn CodegenBlock::codegen(self : CodegenBlock) -> Unit {
[
Sub(reg, reg_lhs, reg_rhs),
Addi(reg, reg, -1),
Srai(reg, reg, 63), // take sign bit
Srli(reg, reg, 63), // take sign bit
]
},
)
Expand Down
1 change: 1 addition & 0 deletions test/run_js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash

node ../js_rt/runtime.mjs $1.js

0 comments on commit 6bcafec

Please sign in to comment.