Skip to content

Commit

Permalink
fix: increment counter first
Browse files Browse the repository at this point in the history
  • Loading branch information
doehyunbaek committed Aug 26, 2024
1 parent 3f2b6c9 commit 65afdbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 9 additions & 7 deletions crates/replay_gen/src/wasmgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ pub fn generate_replay_wasm(
stream,
&format!("(func ${name} (@name \"r3_{name}\") (export \"{name}\") {tystr}\n",),
)?;
write(
stream,
&format!(
"(global.get {global_idx}) (i64.const 1) (i64.add) (global.set {global_idx})\n"
),
)?;
for (i, body) in func.bodys.iter().enumerate() {
if let Some(body) = body {
let mut bodystr = String::new();
Expand Down Expand Up @@ -211,22 +217,18 @@ pub fn generate_replay_wasm(
if memory_writes.len() > 0 {
merge_memory_writes(&mut bodystr, memory_writes, &mut data_segments);
}
// We add 1 to i because on ith iteration, counter is i + 1
let iter_count = i + 1;
write(
stream,
&format!(
"(if
(i64.eq (global.get {global_idx}) (i64.const {i}))
(i64.eq (global.get {global_idx}) (i64.const {iter_count}))
(then {bodystr}))\n"
),
)?;
}
}
write(
stream,
&format!(
"(global.get {global_idx}) (i64.const 1) (i64.add) (global.set {global_idx})\n"
),
)?;
let mut current = 0;
for r in func.results.iter() {
let ty = &code.funcs.get(&funcidx).unwrap().ty;
Expand Down
11 changes: 11 additions & 0 deletions tests/core/circular-call/reference.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
EC;2;func_724;
IC;1
IR;1;
IC;1
EC;2;func_724;
IC;1
IR;1;
IC;1
IR;1;
IR;1;
ER

0 comments on commit 65afdbb

Please sign in to comment.