From 260b8ee7f2b4f5fb87e72e99b9543eb524d12c7d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 7 Jan 2022 08:21:13 -0800 Subject: [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). --- test/ctor-eval/globals.wast | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/ctor-eval/globals.wast (limited to 'test/ctor-eval/globals.wast') 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) + ) + ) +) -- cgit v1.2.3