From 32e19fc4397142b743646ff8a526d07c126bf89b Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Thu, 5 Dec 2024 12:04:35 -0500 Subject: [PATCH] cmd/compile: document wasmexport directive, update permitted types for wasmimport For #65199, #66984. Change-Id: I9b651a00265fa7d3438d8a73ff04ddca7c4bed99 Reviewed-on: https://go-review.googlesource.com/c/go/+/633776 LUCI-TryBot-Result: Go LUCI Reviewed-by: Johan Brandhorst-Satzkorn Reviewed-by: Michael Knyszek --- src/cmd/compile/doc.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cmd/compile/doc.go b/src/cmd/compile/doc.go index 507899e222eb1c..f45df3f86a671d 100644 --- a/src/cmd/compile/doc.go +++ b/src/cmd/compile/doc.go @@ -309,13 +309,33 @@ The types of parameters and return values to the Go function are translated to Wasm according to the following table: Go types Wasm types + bool i32 int32, uint32 i32 int64, uint64 i64 float32 f32 float64 f64 unsafe.Pointer i32 + pointer i32 (more restrictions below) + string (i32, i32) (only permitted as a parameters, not a result) + +For a pointer type, its element type must be a bool, int8, uint8, int16, uint16, +int32, uint32, int64, uint64, float32, float64, an array whose element type is +a permitted pointer element type, or a struct, which, if non-empty, embeds +structs.HostLayout, and contains only fields whose types are permitted pointer +element types. Any other parameter types are disallowed by the compiler. + //go:wasmexport exportname + +The //go:wasmexport directive is wasm-only and must be followed by a +function definition. +It specifies that the function is exported to the wasm host as ``exportname``. + + //go:wasmexport f + func g() + +The types of parameters and return values to the Go function are permitted and +translated to Wasm in the same way as //go:wasmimport functions. */ package main