refactor binary encoding to its own package (#1187)

move binary encoder to its own package

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This commit is contained in:
Edoardo Vacchi
2023-03-03 00:21:22 +01:00
committed by GitHub
parent e2660b3f17
commit 117474c477
56 changed files with 1042 additions and 608 deletions

View File

@@ -13,10 +13,10 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/testing/binaryencoding"
"github.com/tetratelabs/wazero/internal/testing/proxy"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/tetratelabs/wazero/internal/wasm/binary"
"github.com/tetratelabs/wazero/sys"
)
@@ -507,7 +507,7 @@ func callReturnImportWasm(t *testing.T, importedModule, importingModule string,
},
}
require.NoError(t, module.Validate(api.CoreFeaturesV2))
return binary.EncodeModule(module)
return binaryencoding.EncodeModule(module)
}
func callOuterInnerWasm(t *testing.T, importedModule, importingModule string) []byte {
@@ -543,7 +543,7 @@ func callOuterInnerWasm(t *testing.T, importedModule, importingModule string) []
},
}
require.NoError(t, module.Validate(api.CoreFeaturesV2))
return binary.EncodeModule(module)
return binaryencoding.EncodeModule(module)
}
func testCloseInFlight(t *testing.T, r wazero.Runtime) {
@@ -700,7 +700,7 @@ func testMemOps(t *testing.T, r wazero.Runtime) {
}
func testMultipleInstantiation(t *testing.T, r wazero.Runtime) {
bin := binary.EncodeModule(&wasm.Module{
bin := binaryencoding.EncodeModule(&wasm.Module{
TypeSection: []*wasm.FunctionType{{}},
FunctionSection: []wasm.Index{0},
MemorySection: &wasm.Memory{Min: 1, Cap: 1, Max: 1, IsMaxEncoded: true},

View File

@@ -12,8 +12,8 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/testing/binaryencoding"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/tetratelabs/wazero/internal/wasm/binary"
)
// require_no_diff ensures that the behavior is the same between the compiler and the interpreter for any given binary.
@@ -219,7 +219,7 @@ func ensureDummyImports(r wazero.Runtime, origin *wasm.Module, requireNoError fu
}
m.ExportSection = append(m.ExportSection, &wasm.Export{Type: imp.Type, Name: imp.Name, Index: index})
}
_, err := r.Instantiate(context.Background(), binary.EncodeModule(m))
_, err := r.Instantiate(context.Background(), binaryencoding.EncodeModule(m))
requireNoError(err)
}
return

View File

@@ -9,9 +9,9 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/testing/binaryencoding"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/tetratelabs/wazero/internal/wasm/binary"
)
var ctx = context.Background()
@@ -354,7 +354,7 @@ func Test888(t *testing.T) {
// This tests that importing FuncRef type globals and using it as an initialization of the locally-defined
// FuncRef global works fine.
run(t, func(t *testing.T, r wazero.Runtime) {
imported := binary.EncodeModule(&wasm.Module{
imported := binaryencoding.EncodeModule(&wasm.Module{
MemorySection: &wasm.Memory{Min: 0, Max: 5, IsMaxEncoded: true},
GlobalSection: []*wasm.Global{
{