Documentation ¶
Overview ¶
Package wag provides a high-level WebAssembly compiler API.
See the Compile function's source code for an example of how to use the low-level compiler APIs (implemented in subpackages).
Errors ¶
Some errors returned by wag implement the following interface:
interface { ModuleError() string }
Presence of the ModuleError method indicates that the error is caused by unsupported or malformed WebAssembly module. Other errors returned by compilation functions are either read errors or internal compiler errors. Read errors (such as EOF) are passed though as is.
Errors implementing the following interface indicate that generated code or data doesn't fit in a target buffer:
interface { BufferSizeLimit() string }
(Buffer size limit errors implement also the ModuleError method.)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.5.0
type Config struct { Text compile.CodeBuffer // Defaults to dynamically sized buffer. GlobalsMemory compile.DataBuffer // Defaults to dynamically sized buffer. MemoryAlignment int // Defaults to minimal valid alignment. Entry string // No entry function by default. EntryPolicy EntryPolicy // Defaults to binding.GetMainFunc. EntryArgs []uint64 // Defaults to zeros (subject to policy). }
Config for a single compiler invocation. Zero values are replaced with effective defaults during compilation.
type EntryPolicy ¶ added in v0.8.0
type EntryPolicy func(m *compile.Module, symbol string) (globalIndex uint32, sig wa.FuncType, err error)
EntryPolicy validates an entry function's signature while looking it up from a module's exported functions.
type Object ¶ added in v0.5.0
type Object struct { FuncTypes []wa.FuncType // Signatures for debug output. InitialMemorySize int // Current memory allocation. MemorySizeLimit int // Maximum valid value if not limited. Text []byte // Machine code and read-only data. debug.InsnMap // Stack unwinding and debug metadata. MemoryOffset int // Threshold between globals and memory. GlobalsMemory []byte // Global values and memory contents. StackFrame []byte // Entry function address and arguments. Names section.NameSection // Symbols for debug output. }
Object code with debug information. The fields are roughly in order of appearance during compilation.
Executing the code requires a platform-specific mechanism; it's not supported by this package.
func Compile ¶ added in v0.5.0
func Compile(objectConfig *Config, r compile.Reader, imports binding.ImportResolver) (object *Object, err error)
Compile a WebAssembly binary module into machine code. The Object is constructed incrementally so that populated fields may be inspected on error.
See the source code for examples of how to use the lower-level APIs.
Directories ¶
Path | Synopsis |
---|---|
Package binding contains import and export utilities.
|
Package binding contains import and export utilities. |
Package buffer implements compile.CodeBuffer and compile.DataBuffer.
|
Package buffer implements compile.CodeBuffer and compile.DataBuffer. |
cmd
|
|
wasys
Program wasys implements a standalone toy compiler and runtime.
|
Program wasys implements a standalone toy compiler and runtime. |
Package compile implements a WebAssembly compiler.
|
Package compile implements a WebAssembly compiler. |
internal
|
|
isa
Documented interfaces.
|
Documented interfaces. |
Package object contains ObjectMapper implementations.
|
Package object contains ObjectMapper implementations. |
file
Package file supplies the File type alias, which refers to an OS-dependent implementation.
|
Package file supplies the File type alias, which refers to an OS-dependent implementation. |
stack
Package stack provides runtime call stack manipulation functions.
|
Package stack provides runtime call stack manipulation functions. |
Package section contains binary stream manipulation utilities.
|
Package section contains binary stream manipulation utilities. |
Package trap enumerates trap identifiers.
|
Package trap enumerates trap identifiers. |
Package wa contains miscellaneous WebAssembly-related things.
|
Package wa contains miscellaneous WebAssembly-related things. |
opcode
Package opcode enumerates WebAssembly instructions.
|
Package opcode enumerates WebAssembly instructions. |