Alex Crichton 8e56cdacc5
Rewrite wasm-bindgen with updated interface types proposal (#1882)
This commit is a pretty large scale rewrite of the internals of wasm-bindgen. No user-facing changes are expected as a result of this PR, but due to the scale of changes here it's likely inevitable that at least something will break. I'm hoping to get more testing in though before landing!

The purpose of this PR is to update wasm-bindgen to the current state of the interface types proposal. The wasm-bindgen tool was last updated when it was still called "WebIDL bindings" so it's been awhile! All support is now based on https://github.com/bytecodealliance/wasm-interface-types which defines parsers/binary format/writers/etc for wasm-interface types.

This is a pretty massive PR and unfortunately can't really be split up any more afaik. I don't really expect realistic review of all the code here (or commits), but some high-level changes are:

* Interface types now consists of a set of "adapter functions". The IR in wasm-bindgen is modeled the same way not.
* Each adapter function has a list of instructions, and these instructions work at a higher level than wasm itself, for example with strings.
* The wasm-bindgen tool has a suite of instructions which are specific to it and not present in the standard. (like before with webidl bindings)
* The anyref/multi-value transformations are now greatly simplified. They're simply "optimization passes" over adapter functions, removing instructions that are otherwise present. This way we don't have to juggle so much all over the place, and instructions always have the same meaning.
2019-12-03 11:16:44 -06:00

94 lines
1.9 KiB
Plaintext

;; @xform export "i32" (i32)
;; @xform export "i64" (i64)
;; @xform export "f32" (f32)
;; @xform export "f64" (f64)
(module
(global (mut i32) (i32.const 0))
(memory 1)
(func $i32 (export "i32") (param i32))
(func $i64 (export "i64") (param i32))
(func $f32 (export "f32") (param i32))
(func $f64 (export "f64") (param i32))
)
(; CHECK-ALL:
(module
(type (;0;) (func (result i32)))
(type (;1;) (func (result i64)))
(type (;2;) (func (result f32)))
(type (;3;) (func (result f64)))
(type (;4;) (func (param i32)))
(func $i32 multivalue shim (type 0) (result i32)
(local i32)
global.get 0
i32.const 16
i32.sub
local.tee 0
global.set 0
local.get 0
call $i32
local.get 0
i32.load
local.get 0
i32.const 16
i32.add
global.set 0)
(func $i64 multivalue shim (type 1) (result i64)
(local i32)
global.get 0
i32.const 16
i32.sub
local.tee 0
global.set 0
local.get 0
call $i64
local.get 0
i64.load
local.get 0
i32.const 16
i32.add
global.set 0)
(func $f32 multivalue shim (type 2) (result f32)
(local i32)
global.get 0
i32.const 16
i32.sub
local.tee 0
global.set 0
local.get 0
call $f32
local.get 0
f32.load
local.get 0
i32.const 16
i32.add
global.set 0)
(func $f64 multivalue shim (type 3) (result f64)
(local i32)
global.get 0
i32.const 16
i32.sub
local.tee 0
global.set 0
local.get 0
call $f64
local.get 0
f64.load
local.get 0
i32.const 16
i32.add
global.set 0)
(func $i32 (type 4) (param i32))
(func $i64 (type 4) (param i32))
(func $f32 (type 4) (param i32))
(func $f64 (type 4) (param i32))
(memory (;0;) 1)
(global (;0;) (mut i32) (i32.const 0))
(export "i32" (func $i32 multivalue shim))
(export "i64" (func $i64 multivalue shim))
(export "f32" (func $f32 multivalue shim))
(export "f64" (func $f64 multivalue shim)))
;)