Browse Source

wasm: implement the //go:wasmimport directive

It is implemented upstream and looks pretty stable.
pull/3589/head
Ayke van Laethem 2 years ago
committed by Ron Evans
parent
commit
62e1c3ebb7
  1. 9
      compiler/symbol.go
  2. 6
      src/runtime/runtime_tinygowasm.go
  3. 12
      src/runtime/runtime_wasm_wasi.go

9
compiler/symbol.go

@ -288,6 +288,15 @@ func (info *functionInfo) parsePragmas(f *ssa.Function) {
continue continue
} }
info.module = parts[1] info.module = parts[1]
case "//go:wasmimport":
// Import a WebAssembly function, for example a WASI function.
// For details, see: https://github.com/golang/go/issues/38248
if len(parts) != 3 {
continue
}
info.exported = true
info.module = parts[1]
info.importName = parts[2]
case "//go:inline": case "//go:inline":
info.inline = inlineHint info.inline = inlineHint
case "//go:noinline": case "//go:noinline":

6
src/runtime/runtime_tinygowasm.go

@ -12,15 +12,13 @@ type __wasi_iovec_t struct {
bufLen uint bufLen uint
} }
//go:wasm-module wasi_snapshot_preview1 //go:wasmimport wasi_snapshot_preview1 fd_write
//export fd_write
func fd_write(id uint32, iovs *__wasi_iovec_t, iovs_len uint, nwritten *uint) (errno uint) func fd_write(id uint32, iovs *__wasi_iovec_t, iovs_len uint, nwritten *uint) (errno uint)
// See: // See:
// https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#-proc_exitrval-exitcode // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#-proc_exitrval-exitcode
// //
//go:wasm-module wasi_snapshot_preview1 //go:wasmimport wasi_snapshot_preview1 proc_exit
//export proc_exit
func proc_exit(exitcode uint32) func proc_exit(exitcode uint32)
const ( const (

12
src/runtime/runtime_wasm_wasi.go

@ -101,20 +101,16 @@ func ticks() timeUnit {
// Implementations of WASI APIs // Implementations of WASI APIs
//go:wasm-module wasi_snapshot_preview1 //go:wasmimport wasi_snapshot_preview1 args_get
//export args_get
func args_get(argv *unsafe.Pointer, argv_buf unsafe.Pointer) (errno uint16) func args_get(argv *unsafe.Pointer, argv_buf unsafe.Pointer) (errno uint16)
//go:wasm-module wasi_snapshot_preview1 //go:wasmimport wasi_snapshot_preview1 args_sizes_get
//export args_sizes_get
func args_sizes_get(argc *uint32, argv_buf_size *uint32) (errno uint16) func args_sizes_get(argc *uint32, argv_buf_size *uint32) (errno uint16)
//go:wasm-module wasi_snapshot_preview1 //go:wasmimport wasi_snapshot_preview1 clock_time_get
//export clock_time_get
func clock_time_get(clockid uint32, precision uint64, time *uint64) (errno uint16) func clock_time_get(clockid uint32, precision uint64, time *uint64) (errno uint16)
//go:wasm-module wasi_snapshot_preview1 //go:wasmimport wasi_snapshot_preview1 poll_oneoff
//export poll_oneoff
func poll_oneoff(in *__wasi_subscription_t, out *__wasi_event_t, nsubscriptions uint32, nevents *uint32) (errno uint16) func poll_oneoff(in *__wasi_subscription_t, out *__wasi_event_t, nsubscriptions uint32, nevents *uint32) (errno uint16)
type __wasi_eventtype_t = uint8 type __wasi_eventtype_t = uint8

Loading…
Cancel
Save