summaryrefslogtreecommitdiff
path: root/test/ctor-eval/globals.wast
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-01-07 08:21:13 -0800
committerGitHub <noreply@github.com>2022-01-07 08:21:13 -0800
commit260b8ee7f2b4f5fb87e72e99b9543eb524d12c7d (patch)
tree57aeea023034ddeb1b83393fcc5c6b0014a81898 /test/ctor-eval/globals.wast
parent8c0f53d236f664086405870321e5887aaed39f3f (diff)
downloadbinaryen-260b8ee7f2b4f5fb87e72e99b9543eb524d12c7d.tar.gz
binaryen-260b8ee7f2b4f5fb87e72e99b9543eb524d12c7d.tar.bz2
binaryen-260b8ee7f2b4f5fb87e72e99b9543eb524d12c7d.zip
[ctor-eval] Eval and store changes to globals (#4430)
This is necessary for being able to optimize real-world code, as it lets us use the stack pointer for example. With this PR we allow changes to globals, and we simply store the final state of the global in the global at the end. Basically the same as we do for memory, but for globals. Remove a test that now fails ("imported2"). Replace it with a nicer test of saving the values of globals. Also add a test for an imported global, which we do not allow (we never did, but I don't see a test for it).
Diffstat (limited to 'test/ctor-eval/globals.wast')
-rw-r--r--test/ctor-eval/globals.wast16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ctor-eval/globals.wast b/test/ctor-eval/globals.wast
new file mode 100644
index 000000000..47a2023e1
--- /dev/null
+++ b/test/ctor-eval/globals.wast
@@ -0,0 +1,16 @@
+(module
+ (global $g1 (mut i32) (i32.const 10))
+ (global $g2 (mut i32) (i32.const 20))
+ (func $test1 (export "test1")
+ (global.set $g1 (i32.const 30))
+ (global.set $g2 (i32.const 40))
+ (global.set $g1 (i32.const 50)) ;; this overrides the previous 30
+ )
+ (func $keepalive (export "keepalive") (result i32)
+ ;; Keep the globals alive so we can see their values.
+ (i32.add
+ (global.get $g1)
+ (global.get $g2)
+ )
+ )
+)