Skip to content

Commit

Permalink
fix call-imported-from-other
Browse files Browse the repository at this point in the history
We save to local to avoid mutation after entry
  • Loading branch information
doehyunbaek committed Aug 29, 2024
1 parent d1a0fc8 commit 3824127
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/replay_gen/src/wasmgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ pub fn generate_replay_wasm(
let tystr = get_functy_strs(&func.ty);
write(
stream,
&format!("(func ${name} (@name \"r3_{name}\") (export \"{name}\") {tystr}\n",),
&format!("(func ${name} (@name \"r3_{name}\") (export \"{name}\") {tystr} (local $global_onentry i64)\n",),
)?;
write(
stream,
&format!(
"(global.get {global_idx}) (i64.const 1) (i64.add) (global.set {global_idx})\n"
"(global.get {global_idx}) (i64.const 1) (i64.add) (global.set {global_idx})\n
(local.set $global_onentry (global.get {global_idx}))\n",
),
)?;
for (i, body) in func.bodys.iter().enumerate() {
Expand Down Expand Up @@ -223,7 +224,7 @@ pub fn generate_replay_wasm(
stream,
&format!(
"(if
(i64.eq (global.get {global_idx}) (i64.const {iter_count}))
(i64.eq (local.get $global_onentry) (i64.const {iter_count}))
(then {bodystr}))\n"
),
)?;
Expand Down Expand Up @@ -251,8 +252,8 @@ pub fn generate_replay_wasm(
&format!(
" (if
(i32.and
(i64.ge_s (global.get {global_idx}) (i64.const {c1}))
(i64.lt_s (global.get {global_idx}) (i64.const {c2}))
(i64.ge_s (local.get $global_onentry) (i64.const {c1}))
(i64.lt_s (local.get $global_onentry) (i64.const {c2}))
)
(then
{res}
Expand Down

0 comments on commit 3824127

Please sign in to comment.