diff options
author | Alon Zakai <azakai@google.com> | 2021-10-29 14:38:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-29 14:38:17 -0700 |
commit | 3666cbc74d690f5a062bd45e7ac0df0d58c24636 (patch) | |
tree | 8779610bb91f717226f6750a3d7755f46e97723b /test/binaryen.js/sideffects.js | |
parent | 5b3cc376af95daba7da944842babe47b2b2197d2 (diff) | |
download | binaryen-3666cbc74d690f5a062bd45e7ac0df0d58c24636.tar.gz binaryen-3666cbc74d690f5a062bd45e7ac0df0d58c24636.tar.bz2 binaryen-3666cbc74d690f5a062bd45e7ac0df0d58c24636.zip |
Effects: Differentiate mutable from immutable globals (#4286)
Similar to what we do with structs, if a global is immutable then we know it
cannot interact with calls.
This changes the JS API for getSideEffects(). That was actually broken,
as passing in the optional module param would just pass it along to the
compiled C code, so it was coerced to 0 or 1, and not a pointer to a module.
To fix that, this now does module.ptr to actually get the pointer, and this is
now actually tested as without a module we cannot compute the effects of a
global. This PR also makes the module param mandatory in the JS API,
as again, without a module we can't compute global effects. (The module
param has already been mandatory in the C++ API for some time.)
Diffstat (limited to 'test/binaryen.js/sideffects.js')
-rw-r--r-- | test/binaryen.js/sideffects.js | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/test/binaryen.js/sideffects.js b/test/binaryen.js/sideffects.js index 654c51608..e3187041d 100644 --- a/test/binaryen.js/sideffects.js +++ b/test/binaryen.js/sideffects.js @@ -19,28 +19,32 @@ console.log("SideEffects.Any=" + binaryen.SideEffects.Any); var module = new binaryen.Module(); assert( binaryen.getSideEffects( - module.i32.const(1) + module.i32.const(1), + module ) == binaryen.SideEffects.None ); assert( binaryen.getSideEffects( - module.br("test") + module.br("test"), + module ) == binaryen.SideEffects.Branches ); assert( binaryen.getSideEffects( - module.call("test", [], binaryen.i32) + module.call("test", [], binaryen.i32), + module ) == binaryen.SideEffects.Calls ); assert( binaryen.getSideEffects( - module.local.get("test", binaryen.i32) + module.local.get("test", binaryen.i32), + module ) == binaryen.SideEffects.ReadsLocal @@ -49,21 +53,28 @@ assert( binaryen.getSideEffects( module.local.set("test", module.i32.const(1) - ) + ), + module ) == binaryen.SideEffects.WritesLocal ); + +// Add a global for the test, as computing side effects will look for it. +module.addGlobal('test', binaryen.i32, true, module.i32.const(42)); + assert( binaryen.getSideEffects( - module.global.get("test", binaryen.i32) + module.global.get("test", binaryen.i32), + module ) == binaryen.SideEffects.ReadsGlobal ); assert( binaryen.getSideEffects( - module.global.set("test", module.i32.const(1)) + module.global.set("test", module.i32.const(1)), + module ) == binaryen.SideEffects.WritesGlobal @@ -72,7 +83,8 @@ assert( binaryen.getSideEffects( module.i32.load(0, 0, module.i32.const(0) - ) + ), + module ) == binaryen.SideEffects.ReadsMemory | binaryen.SideEffects.ImplicitTrap @@ -82,7 +94,8 @@ assert( module.i32.store(0, 0, module.i32.const(0), module.i32.const(1) - ) + ), + module ) == binaryen.SideEffects.WritesMemory | binaryen.SideEffects.ImplicitTrap @@ -92,7 +105,8 @@ assert( module.i32.div_s( module.i32.const(1), module.i32.const(0) - ) + ), + module ) == binaryen.SideEffects.ImplicitTrap |