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

@@ -83,12 +83,17 @@ const (
ValueTypeF32 ValueType = 0x7d
// ValueTypeF64 is a 64-bit floating point number.
ValueTypeF64 ValueType = 0x7c
// ValueTypeExternref is a externref type.
//
// Note: in wazero, externref type value are opaque raw 64-bit pointers, and the ValueTypeExternref type
// in the signature will be translated as uintptr in wazero's API level.
// For example, the import function `(func (import "env" "f") (param externref) (result externref))` can be defined in Go as:
// Note: in wazero, externref type value are opaque raw 64-bit pointers,
// and the ValueTypeExternref type in the signature will be translated as
// uintptr in wazero's API level.
//
// For example, given the import function:
// (func (import "env" "f") (param externref) (result externref))
//
// This can be defined in Go as:
// r.NewModuleBuilder("env").ExportFunctions(map[string]interface{}{
// "f": func(externref uintptr) (resultExternRef uintptr) { return },
// })
@@ -222,6 +227,13 @@ type FunctionDefinition interface {
// is possible.
ExportNames() []string
// IsHostFunction returns true if the function was implemented by the
// embedder (ex via wazero.ModuleBuilder) instead of a wasm binary.
//
// Note: Host functions can be non-deterministic or cause side effects.
// See https://www.w3.org/TR/wasm-core-1/#host-functions%E2%91%A0
IsHostFunction() bool
// ParamTypes are the possibly empty sequence of value types accepted by a
// function with this signature.
//