This commit implements the rest of the unimplemented instructions in the bulk-memory-operations proposal. Notably, this adds support for table.init, table.copy and elem.drop instructions toggled by FeatureBulkMemoryOperations. Given that, now wazero has the complete support for the bulk-memory-operations proposal as described in https://github.com/WebAssembly/spec/blob/main/proposals/bulk-memory-operations/Overview.md fixes #321 Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package binary
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/tetratelabs/wazero/internal/wasm"
|
|
)
|
|
|
|
// decodeTable returns the wasm.Table decoded with the WebAssembly 1.0 (20191205) Binary Format.
|
|
//
|
|
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#binary-table
|
|
func decodeTable(r *bytes.Reader) (*wasm.Table, error) {
|
|
b, err := r.ReadByte()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read leading byte: %v", err)
|
|
}
|
|
|
|
if b != wasm.RefTypeFuncref {
|
|
return nil, fmt.Errorf("invalid element type %#x != funcref(%#x)", b, wasm.RefTypeFuncref)
|
|
}
|
|
|
|
min, max, err := decodeLimitsType(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read limits: %v", err)
|
|
}
|
|
if min > wasm.MaximumFunctionIndex {
|
|
return nil, fmt.Errorf("table min must be at most %d", wasm.MaximumFunctionIndex)
|
|
}
|
|
if max != nil {
|
|
if *max < min {
|
|
return nil, fmt.Errorf("table size minimum must not be greater than maximum")
|
|
} else if *max > wasm.MaximumFunctionIndex {
|
|
return nil, fmt.Errorf("table max must be at most %d", wasm.MaximumFunctionIndex)
|
|
}
|
|
}
|
|
return &wasm.Table{Min: min, Max: max}, nil
|
|
}
|
|
|
|
// encodeTable returns the wasm.Table encoded in WebAssembly 1.0 (20191205) Binary Format.
|
|
//
|
|
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#binary-table
|
|
func encodeTable(i *wasm.Table) []byte {
|
|
return append([]byte{wasm.RefTypeFuncref}, encodeLimitsType(i.Min, i.Max)...)
|
|
}
|