Compiler

compiler/linkname

github.com/gopherjs/gopherjs/compiler/linkname

import "github.com/gopherjs/gopherjs/compiler/linkname"

Functions

func ParseGoLinknames(fset *token.FileSet, pkgPath string, file *ast.File) ([]GoLinkname, error)

Source: compiler/linkname/linkname.go:118

parseGoLinknames processed comments in a source file and extracts //go:linkname compiler directive from the comments.

The following directive format is supported: //go:linkname . //go:linkname .. //go:linkname .<(*type)>.

GopherJS directive support has the following limitations:

  • External linkname must be specified.
  • The directive must be applied to a package-level function or method (variables are not supported).
  • The local function referenced by the directive must have no body (in other words, it can only "import" an external function implementation into the local scope).

Types

type GoLinkname

Source: compiler/linkname/linkname.go:20

GoLinkname describes a go:linkname compiler directive found in the source code.

GopherJS treats these directives in a way that resembles a symbolic link, where for a single given symbol implementation there may be zero or more symbols referencing it. This is subtly different from the upstream Go implementation, which simply overrides symbol name the linker will use.

type GoLinkname struct {
	Implementation symbol.Name
	Reference      symbol.Name
}
Fields
  • Implementation symbol.Name
  • Reference symbol.Name

type GoLinknameSet

Source: compiler/linkname/linkname.go:213

GoLinknameSet is a utility that enables quick lookup of whether a decl is affected by any go:linkname directive in the program.

type GoLinknameSet struct {
	// contains filtered or unexported fields
}

func Add(entries []GoLinkname) error

Source: compiler/linkname/linkname.go:219

Add more GoLinkname directives into the set.

func FindImplementation(sym symbol.Name) (symbol.Name, bool)

Source: compiler/linkname/linkname.go:247

FindImplementation returns a symbol name, which provides the implementation for the given symbol. The second value indicates whether the implementation was found.

func IsImplementation(sym symbol.Name) bool

Source: compiler/linkname/linkname.go:239

IsImplementation returns true if there is a directive referencing this symbol as an implementation.