WASM: Support for setting an imported function's module name (#455)

* wasm: add support for setting a function's Wasm import module name by using the //go:wasm-module comment.
This commit is contained in:
Phil Kedy
2019-09-12 02:35:43 -04:00
committed by Ron Evans
parent 1dbfc976e8
commit 55144ad608
3 changed files with 20 additions and 1 deletions
+12
View File
@@ -28,6 +28,7 @@ type Program struct {
type Function struct {
*ssa.Function
LLVMFn llvm.Value
module string // go:wasm-module
linkName string // go:linkname, go:export, go:interrupt
exported bool // go:export
nobounds bool // go:nobounds
@@ -229,6 +230,12 @@ func (f *Function) parsePragmas() {
}
f.linkName = parts[1]
f.exported = true
case "//go:wasm-module":
// Alternative comment for setting the import module.
if len(parts) != 2 {
continue
}
f.module = parts[1]
case "//go:inline":
f.inline = InlineHint
case "//go:noinline":
@@ -291,6 +298,11 @@ func (f *Function) Inline() InlineType {
return f.inline
}
// Return the module name if not the default.
func (f *Function) Module() string {
return f.module
}
// Return the link name for this function.
func (f *Function) LinkName() string {
if f.linkName != "" {