Adds function names to host functions and improves logging listener (#697)

This improves the experimental logging listener to show parameter name
and values like so:

```
--> ._start.command_export()
        	--> .__wasm_call_ctors()
        		--> .__wasilibc_initialize_environ()
        			==> wasi_snapshot_preview1.environ_sizes_get(result.environc=1048572,result.environBufSize=1048568)
        			<== ESUCCESS
        		<-- ()
        		==> wasi_snapshot_preview1.fd_prestat_get(fd=3,result.prestat=1048568)
        		<== ESUCCESS
        		--> .dlmalloc(2)
        			--> .sbrk(0)
        			<-- (1114112)
        		<-- (1060080)
--snip--
```

The convention `==>` implies it was a host function call
(def.IsHostFunction). This also improves the lifecycle by creating
listeners during compile. Finally, this backfills param names for
assemblyscript and wasi.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-07-14 16:43:25 +08:00
committed by GitHub
parent 0ae4254f21
commit 040736caac
27 changed files with 1221 additions and 499 deletions

View File

@@ -1,6 +1,7 @@
package wasm
import (
"reflect"
"testing"
"github.com/tetratelabs/wazero/api"
@@ -9,6 +10,7 @@ import (
func TestModule_BuildFunctionDefinitions(t *testing.T) {
nopCode := &Code{nil, []byte{OpcodeEnd}}
fnV := reflect.ValueOf(func() {})
tests := []struct {
name string
m *Module
@@ -26,6 +28,22 @@ func TestModule_BuildFunctionDefinitions(t *testing.T) {
GlobalSection: []*Global{{}},
},
},
{
name: "host func",
m: &Module{
TypeSection: []*FunctionType{v_v},
FunctionSection: []Index{0},
HostFunctionSection: []*reflect.Value{&fnV},
},
expected: []*FunctionDefinition{
{
index: 0,
debugName: ".$0",
isHostFunction: true,
funcType: v_v,
},
},
},
{
name: "without imports",
m: &Module{