The buildbot also publishes nightly versions once a day if there have been changes. The latest nightly can be installed through
-
none: Type
The none type, e.g., void
.
-
i32: Type
32-bit integer type.
-
i64: Type
64-bit integer type.
-
f32: Type
32-bit float type.
-
f64: Type
64-bit float (double) type.
-
v128: Type
128-bit vector type. π¦
-
funcref: Type
A function reference. π¦
-
externref: Type
An external (host) reference. π¦
-
anyref: Type
Any (top type) reference. π¦
-
eqref: Type
Equal reference. π¦
-
i31ref: Type
i31 reference. π¦
-
dataref: Type
Data reference. π¦
-
stringref: Type
String reference. π¦
-
stringview_wtf8: Type
View of a string reference in WTF-8 encoding. π¦
-
stringview_wtf16: Type
View of a string reference in WTF-16 encoding. π¦
-
stringview_iter: Type
Iterator over the code points of a string reference. π¦
-
unreachable: Type
Special type indicating unreachable code when obtaining information about an expression.
-
auto: Type
Special type used in Module#block exclusively. Lets the API figure out a block's result type automatically.
-
createType(types: Type[]
): Type
Creates a multi-value type from an array of types.
-
expandType(type: Type
): Type[]
Expands a multi-value type to an array of types.
-
Module#addFunction(name: string
, params: Type
, results: Type
, vars: Type[]
, body: ExpressionRef
): FunctionRef
Adds a function. vars
indicate additional locals, in the given order.
-
Module#getFunction(name: string
): FunctionRef
Gets a function, by name,
-
Module#removeFunction(name: string
): void
Removes a function, by name.
-
Module#getNumFunctions(): number
Gets the number of functions within the module.
-
Module#getFunctionByIndex(index: number
): FunctionRef
Gets the function at the specified index.
-
Module#addFunctionImport(internalName: string
, externalModuleName: string
, externalBaseName: string
, params: Type
, results: Type
): void
Adds a function import.
-
Module#addTableImport(internalName: string
, externalModuleName: string
, externalBaseName: string
): void
Adds a table import. There's just one table for now, using name "0"
.
-
Module#addMemoryImport(internalName: string
, externalModuleName: string
, externalBaseName: string
): void
Adds a memory import. There's just one memory for now, using name "0"
.
-
Module#addGlobalImport(internalName: string
, externalModuleName: string
, externalBaseName: string
, globalType: Type
): void
Adds a global variable import. Imported globals must be immutable.
-
Module#addFunctionExport(internalName: string
, externalName: string
): ExportRef
Adds a function export.
-
Module#addTableExport(internalName: string
, externalName: string
): ExportRef
Adds a table export. There's just one table for now, using name "0"
.
-
Module#addMemoryExport(internalName: string
, externalName: string
): ExportRef
Adds a memory export. There's just one memory for now, using name "0"
.
-
Module#addGlobalExport(internalName: string
, externalName: string
): ExportRef
Adds a global variable export. Exported globals must be immutable.
-
Module#getNumExports(): number
Gets the number of exports witin the module.
-
Module#getExportByIndex(index: number
): ExportRef
Gets the export at the specified index.
-
Module#removeExport(externalName: string
): void
Removes an export, by external name.
-
Module#addGlobal(name: string
, type: Type
, mutable: number
, value: ExpressionRef
): GlobalRef
Adds a global instance variable.
-
Module#getGlobal(name: string
): GlobalRef
Gets a global, by name,
-
Module#removeGlobal(name: string
): void
Removes a global, by name.
-
Module#setMemory(initial: number
, maximum: number
, exportName: string | null
, segments: MemorySegment[]
, shared?: boolean
): void
Sets the memory. There's just one memory for now, using name "0"
. Providing exportName
also creates a memory export.
- MemorySegment#offset:
ExpressionRef
- MemorySegment#data:
Uint8Array
- MemorySegment#passive:
boolean
-
Module#getNumMemorySegments(): number
Gets the number of memory segments within the module.
-
Module#getMemorySegmentInfoByIndex(index: number
): MemorySegmentInfo
Gets information about the memory segment at the specified index.
- MemorySegmentInfo#offset:
number
- MemorySegmentInfo#data:
Uint8Array
- MemorySegmentInfo#passive:
boolean
-
Module#setStart(start: FunctionRef
): void
Sets the start function.
-
Module#getFeatures(): Features
Gets the WebAssembly features enabled for this module.
Note that the return value may be a bitmask indicating multiple features. Possible feature flags are:
- Features.MVP:
Features
- Features.Atomics:
Features
- Features.BulkMemory:
Features
- Features.MutableGlobals:
Features
- Features.NontrappingFPToInt:
Features
- Features.SignExt:
Features
- Features.SIMD128:
Features
- Features.ExceptionHandling:
Features
- Features.TailCall:
Features
- Features.ReferenceTypes:
Features
- Features.Multivalue:
Features
- Features.All:
Features
-
Module#setFeatures(features: Features
): void
Sets the WebAssembly features enabled for this module.
-
Module#addCustomSection(name: string
, contents: Uint8Array
): void
Adds a custom section to the binary.
-
Module#autoDrop(): void
Enables automatic insertion of drop
operations where needed. Lets you not worry about dropping when creating your code.
-
getFunctionInfo(ftype: FunctionRef
: FunctionInfo
Obtains information about a function.
- FunctionInfo#name:
string
- FunctionInfo#module:
string | null
(if imported) - FunctionInfo#base:
string | null
(if imported) - FunctionInfo#params:
Type
- FunctionInfo#results:
Type
- FunctionInfo#vars:
Type
- FunctionInfo#body:
ExpressionRef
-
getGlobalInfo(global: GlobalRef
): GlobalInfo
Obtains information about a global.
- GlobalInfo#name:
string
- GlobalInfo#module:
string | null
(if imported) - GlobalInfo#base:
string | null
(if imported) - GlobalInfo#type:
Type
- GlobalInfo#mutable:
boolean
- GlobalInfo#init:
ExpressionRef
-
getTableInfo(table: TableRef
): TableInfo
Obtains information about a table.
- TableInfo#name:
string
- TableInfo#module:
string | null
(if imported) - TableInfo#base:
string | null
(if imported) - TableInfo#initial:
number
; - TableInfo#max?:
number
;
-
getExportInfo(export_: ExportRef
): ExportInfo
Obtains information about an export.
- ExportInfo#kind:
ExternalKind
- ExportInfo#name:
string
- ExportInfo#value:
string
Possible ExternalKind
values are:
- ExternalFunction:
ExternalKind
- ExternalTable:
ExternalKind
- ExternalMemory:
ExternalKind
- ExternalGlobal:
ExternalKind
- ExternalTag:
ExternalKind
-
getTagInfo(tag: TagRef
): TagInfo
Obtains information about a tag.
- TagInfo#name:
string
- TagInfo#module:
string | null
(if imported) - TagInfo#base:
string | null
(if imported) - TagInfo#params:
Type
- TagInfo#results:
Type
-
getSideEffects(expr: ExpressionRef
, features: FeatureFlags
): SideEffects
Gets the side effects of the specified expression.
- SideEffects.None:
SideEffects
- SideEffects.Branches:
SideEffects
- SideEffects.Calls:
SideEffects
- SideEffects.ReadsLocal:
SideEffects
- SideEffects.WritesLocal:
SideEffects
- SideEffects.ReadsGlobal:
SideEffects
- SideEffects.WritesGlobal:
SideEffects
- SideEffects.ReadsMemory:
SideEffects
- SideEffects.WritesMemory:
SideEffects
- SideEffects.ReadsTable:
SideEffects
- SideEffects.WritesTable:
SideEffects
- SideEffects.ImplicitTrap:
SideEffects
- SideEffects.IsAtomic:
SideEffects
- SideEffects.Throws:
SideEffects
- SideEffects.DanglingPop:
SideEffects
- SideEffects.TrapsNeverHappen:
SideEffects
- SideEffects.Any:
SideEffects
-
Module#optimize(): void
Optimizes the module using the default optimization passes.
-
Module#optimizeFunction(func: FunctionRef | string
): void
Optimizes a single function using the default optimization passes.
-
Module#runPasses(passes: string[]
): void
Runs the specified passes on the module.
-
Module#runPassesOnFunction(func: FunctionRef | string
, passes: string[]
): void
Runs the specified passes on a single function.
-
getOptimizeLevel(): number
Gets the currently set optimize level. 0
, 1
, 2
correspond to -O0
, -O1
, -O2
(default), etc.
-
setOptimizeLevel(level: number
): void
Sets the optimization level to use. 0
, 1
, 2
correspond to -O0
, -O1
, -O2
(default), etc.
-
getShrinkLevel(): number
Gets the currently set shrink level. 0
, 1
, 2
correspond to -O0
, -Os
(default), -Oz
.
-
setShrinkLevel(level: number
): void
Sets the shrink level to use. 0
, 1
, 2
correspond to -O0
, -Os
(default), -Oz
.
-
getDebugInfo(): boolean
Gets whether generating debug information is currently enabled or not.
-
setDebugInfo(on: boolean
): void
Enables or disables debug information in emitted binaries.
-
getLowMemoryUnused(): boolean
Gets whether the low 1K of memory can be considered unused when optimizing.
-
setLowMemoryUnused(on: boolean
): void
Enables or disables whether the low 1K of memory can be considered unused when optimizing.
-
getPassArgument(key: string
): string | null
Gets the value of the specified arbitrary pass argument.
-
setPassArgument(key: string
, value: string | null
): void
Sets the value of the specified arbitrary pass argument. Removes the respective argument if value
is null
.
-
clearPassArguments(): void
Clears all arbitrary pass arguments.
-
getAlwaysInlineMaxSize(): number
Gets the function size at which we always inline.
-
setAlwaysInlineMaxSize(size: number
): void
Sets the function size at which we always inline.
-
getFlexibleInlineMaxSize(): number
Gets the function size which we inline when functions are lightweight.
-
setFlexibleInlineMaxSize(size: number
): void
Sets the function size which we inline when functions are lightweight.
-
getOneCallerInlineMaxSize(): number
Gets the function size which we inline when there is only one caller.
-
setOneCallerInlineMaxSize(size: number
): void
Sets the function size which we inline when there is only one caller.
-
Module#block(label: string | null
, children: ExpressionRef[]
, resultType?: Type
): ExpressionRef
Creates a block. resultType
defaults to none
.
-
Module#if(condition: ExpressionRef
, ifTrue: ExpressionRef
, ifFalse?: ExpressionRef
): ExpressionRef
Creates an if or if/else combination.
-
Module#loop(label: string | null
, body: ExpressionRef
): ExpressionRef
Creates a loop.
-
Module#br(label: string
, condition?: ExpressionRef
, value?: ExpressionRef
): ExpressionRef
Creates a branch (br) to a label.
-
Module#switch(labels: string[]
, defaultLabel: string
, condition: ExpressionRef
, value?: ExpressionRef
): ExpressionRef
Creates a switch (br_table).
-
Module#nop(): ExpressionRef
Creates a no-operation (nop) instruction.
-
Module#return(value?: ExpressionRef
): ExpressionRef
Creates a return.
-
Module#unreachable(): ExpressionRef
Creates an unreachable instruction that will always trap.
-
Module#drop(value: ExpressionRef
): ExpressionRef
Creates a drop of a value.
-
Module#select(condition: ExpressionRef
, ifTrue: ExpressionRef
, ifFalse: ExpressionRef
, type?: Type
): ExpressionRef
Creates a select of one of two values.
Note that these are pseudo instructions enabling Binaryen to reason about multiple values on the stack.
-
new Relooper()
Constructs a relooper instance. This lets you provide an arbitrary CFG, and the relooper will structure it for WebAssembly.
-
Relooper#addBlock(code: ExpressionRef
): RelooperBlockRef
Adds a new block to the CFG, containing the provided code as its body.
-
Relooper#addBranch(from: RelooperBlockRef
, to: RelooperBlockRef
, condition: ExpressionRef
, code: ExpressionRef
): void
Adds a branch from a block to another block, with a condition (or nothing, if this is the default branch to take from the origin - each block must have one such branch), and optional code to execute on the branch (useful for phis).
-
Relooper#addBlockWithSwitch(code: ExpressionRef
, condition: ExpressionRef
): RelooperBlockRef
Adds a new block, which ends with a switch/br_table, with provided code and condition (that determines where we go in the switch).
-
Relooper#addBranchForSwitch(from: RelooperBlockRef
, to: RelooperBlockRef
, indexes: number[]
, code: ExpressionRef
): void
Adds a branch from a block ending in a switch, to another block, using an array of indexes that determine where to go, and optional code to execute on the branch.
-
Relooper#renderAndDispose(entry: RelooperBlockRef
, labelHelper: number
, module: Module
): ExpressionRef
Renders and cleans up the Relooper instance. Call this after you have created all the blocks and branches, giving it the entry block (where control flow begins), a label helper variable (an index of a local we can use, necessary for irreducible control flow), and the module. This returns an expression - normal WebAssembly code - that you can use normally anywhere.