forked from rustwasm/wasm-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the codegen of the
TableGrow
intrinsic
It's not safe for us to arbitrarily modify the instruction stream since wasm isn't guaranteed to be an AST! Instead we resort to a few extra instructions with locals to achieve what we want here. Closes rustwasm#2446
- Loading branch information
1 parent
5442f26
commit 0768860
Showing
3 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
;; @xform export "foo" (externref_owned) | ||
|
||
(module | ||
(import "__wbindgen_externref_xform__" "__wbindgen_externref_table_grow" | ||
(func $grow (param i32) (result i32))) | ||
(func $foo (export "foo") (param i32) | ||
(local i32) | ||
i32.const 0 | ||
local.tee 0 | ||
call $grow | ||
drop) | ||
(func $alloc (export "__externref_table_alloc") (result i32) | ||
i32.const 0) | ||
(func $dealloc (export "__externref_table_dealloc") (param i32)) | ||
) | ||
|
||
(; CHECK-ALL: | ||
(module | ||
(type (;0;) (func (result i32))) | ||
(type (;1;) (func (param i32))) | ||
(type (;2;) (func (param externref))) | ||
(func $foo (type 1) (param i32) | ||
(local i32) | ||
i32.const 0 | ||
local.tee 0 | ||
local.set 1 | ||
ref.null extern | ||
local.get 1 | ||
table.grow 0 | ||
drop) | ||
(func $foo_externref_shim (@name "foo externref shim") (type 2) (param externref) | ||
(local i32) | ||
call $alloc | ||
local.tee 1 | ||
local.get 0 | ||
table.set 0 | ||
local.get 1 | ||
call $foo) | ||
(func $alloc (type 0) (result i32) | ||
i32.const 0) | ||
(table (;0;) 32 externref) | ||
(export "foo" (func $foo_externref_shim))) | ||
;) |