v2 / vlib / wasm / tests / patch_test.v
30 lines · 28 sloc · 556 bytes · 3a06b55388559598c05e46ddb776d7443180b56b
Raw
1module main
2
3import wasm
4
5fn test_patch() {
6 mut m := wasm.Module{}
7 vsp := m.new_global('__vsp', false, .i32_t, true, wasm.constexpr_value(10))
8 mut at := m.new_function('add', [], [])
9 {
10 pp := at.patch_pos()
11 at.drop()
12 at.i32_const(10)
13 at.i32_const(10)
14 at.i32_const(10)
15 at.drop()
16 at.drop()
17 at.drop()
18 pps := at.patch_pos()
19 {
20 at.i32_const(10)
21 at.i32_const(10)
22 at.global_set(vsp)
23 at.i32_const(10)
24 at.global_set(vsp)
25 }
26 at.patch(pp, pps) // move to start
27 }
28 m.commit(at, true)
29 validate(m.compile()) or { panic(err) }
30}
31