blob: d735a5a41a020d1a68441102ab5b5016c9616731 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
(module
(memory 256 256)
(data (i32.const 10) "waka waka waka waka waka")
;; stack imports are special
(import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
(import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32))
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
(global $tempDoublePtrMut (mut i32) (get_global $tempDoublePtr))
(export "test1" $test1)
(export "test2" $test2)
(export "test3" $test3)
;; ok to modify a global, if we keep it the same value
(global $mine (mut i32) (i32.const 1))
;; stack imports are ok to use. their uses are the same as other
;; globals - must keep the same value (which means, unwind the stack)
;; here the global names are "minified"
(global $global0 (mut i32) (get_global $STACKTOP$asm2wasm$import))
(global $global1 (mut i32) (get_global $STACK_MAX$asm2wasm$import))
;; a global initialized by an import, so bad, but ok if not used
(global $do-not-use (mut i32) (get_global $tempDoublePtr))
(func $test1
(local $temp i32)
(set_global $mine (i32.const 1))
(set_local $temp (get_global $global0))
(set_global $global0 (i32.const 1337)) ;; bad
(set_global $global0 (get_local $temp)) ;; save us
(set_global $global1 (i32.const 913370)) ;; bad
(set_global $global1 (get_local $temp)) ;; save us
;; use the stack memory
(i32.store (get_local $temp) (i32.const 1337))
(if
(i32.ne
(i32.load (get_local $temp))
(i32.const 1337)
)
(unreachable) ;; they should be equal, never get here
)
;; finally, do a valid store
(i32.store8 (i32.const 12) (i32.const 115))
)
(func $test2
(i32.store8 (i32.const 13) (i32.const 115))
)
(func $test3
(i32.store8 (i32.const 14) (i32.const 115))
)
)
|