Holds wasm.Code as values on wasm.Module (#1243)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2023-03-14 22:45:54 -07:00
committed by GitHub
parent 12e80b4bc5
commit e17a85146a
36 changed files with 302 additions and 298 deletions

View File

@@ -138,7 +138,7 @@ func setupHostCallBench(requireNoError func(error)) *wasm.ModuleInstance {
hostModule := &wasm.Module{
TypeSection: []wasm.FunctionType{ft},
FunctionSection: []wasm.Index{0, 0},
CodeSection: []*wasm.Code{
CodeSection: []wasm.Code{
{
GoFunc: api.GoModuleFunc(func(_ context.Context, mod api.Module, stack []uint64) {
ret, ok := mod.Memory().ReadUint32Le(uint32(stack[0]))
@@ -194,7 +194,7 @@ func setupHostCallBench(requireNoError func(error)) *wasm.ModuleInstance {
{Name: callGoHostName, Type: wasm.ExternTypeFunc, Index: 3},
{Name: callGoReflectHostName, Type: wasm.ExternTypeFunc, Index: 4},
},
CodeSection: []*wasm.Code{
CodeSection: []wasm.Code{
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeCall, 0, wasm.OpcodeEnd}}, // Calling the index 0 = host.go.
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeCall, 1, wasm.OpcodeEnd}}, // Calling the index 1 = host.go-reflect.
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeCall, 2, wasm.OpcodeEnd}}, // Calling the index 2 = host.wasm.

View File

@@ -492,7 +492,7 @@ func callHostFunctionIndirect(t *testing.T, r wazero.Runtime) {
ImportSection: []wasm.Import{{Module: hostModule, Name: hostFn, Type: wasm.ExternTypeFunc, DescFunc: 0}},
FunctionSection: []wasm.Index{0},
ExportSection: []wasm.Export{{Name: importingWasmModuleFn, Type: wasm.ExternTypeFunc, Index: 1}},
CodeSection: []*wasm.Code{{Body: []byte{wasm.OpcodeCall, 0, wasm.OpcodeEnd}}},
CodeSection: []wasm.Code{{Body: []byte{wasm.OpcodeCall, 0, wasm.OpcodeEnd}}},
NameSection: &wasm.NameSection{ModuleName: importingWasmModule},
}
@@ -501,7 +501,7 @@ func callHostFunctionIndirect(t *testing.T, r wazero.Runtime) {
ImportSection: []wasm.Import{{Module: importingWasmModule, Name: importingWasmModuleFn, Type: wasm.ExternTypeFunc, DescFunc: 0}},
FunctionSection: []wasm.Index{0},
ExportSection: []wasm.Export{{Name: "origin", Type: wasm.ExternTypeFunc, Index: 1}},
CodeSection: []*wasm.Code{{Body: []byte{wasm.OpcodeCall, 0, wasm.OpcodeEnd}}},
CodeSection: []wasm.Code{{Body: []byte{wasm.OpcodeCall, 0, wasm.OpcodeEnd}}},
NameSection: &wasm.NameSection{ModuleName: originWasmModule},
}
@@ -552,7 +552,7 @@ func callReturnImportWasm(t *testing.T, importedModule, importingModule string,
{Name: "call_return_input", Type: wasm.ExternTypeFunc, Index: 1},
},
// (func $call_return_input (param i32) (result i32) local.get 0 call $return_input)
CodeSection: []*wasm.Code{
CodeSection: []wasm.Code{
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeCall, 0, wasm.OpcodeEnd}},
},
NameSection: &wasm.NameSection{
@@ -583,7 +583,7 @@ func callOuterInnerWasm(t *testing.T, importedModule, importingModule string) []
// (export "inner" (func $call_inner))
{Name: "inner", Type: wasm.ExternTypeFunc, Index: 3},
},
CodeSection: []*wasm.Code{
CodeSection: []wasm.Code{
// (func $call_outer (param i32) (result i32) local.get 0 call $outer)
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeCall, 0, wasm.OpcodeEnd}},
// (func $call_inner (param i32) (result i32) local.get 0 call $inner)
@@ -761,7 +761,7 @@ func testMultipleInstantiation(t *testing.T, r wazero.Runtime) {
TypeSection: []wasm.FunctionType{{}},
FunctionSection: []wasm.Index{0},
MemorySection: &wasm.Memory{Min: 1, Cap: 1, Max: 1, IsMaxEncoded: true},
CodeSection: []*wasm.Code{{
CodeSection: []wasm.Code{{
Body: []byte{
wasm.OpcodeI32Const, 1, // i32.const 1 ;; memory offset
wasm.OpcodeI64Const, 0xe8, 0x7, // i64.const 1000 ;; expected value

View File

@@ -179,7 +179,7 @@ func ensureDummyImports(r wazero.Runtime, origin *wasm.Module, requireNoError fu
}
}
body.WriteByte(wasm.OpcodeEnd)
m.CodeSection = append(m.CodeSection, &wasm.Code{Body: body.Bytes()})
m.CodeSection = append(m.CodeSection, wasm.Code{Body: body.Bytes()})
case wasm.ExternTypeGlobal:
index = uint32(len(m.GlobalSection))
var data []byte