package wasmemitter
- Alphabetic
- Public
- All
Type Members
- class ClassEmitter extends AnyRef
- final class CoreWasmLib extends AnyRef
-
class
CustomJSHelperBuilder extends AnyRef
Toolkit to build custom JS helpers that take Wasm inputs, while trying to optimize them directly as JavaScript trees.
Toolkit to build custom JS helpers that take Wasm inputs, while trying to optimize them directly as JavaScript trees.
The usage scenario for this class is as follows:
val builder = new CustomJSHelperBuilder() // Add inputs that will be evaluated on the Wasm call site, and whose // values are then available as `js.Tree`s in the JS helper: val xRef = builder.addWasmInput(watpe.Int32) { // Wasm code evaluated at call site fb += wa.LocalGet(someLocal) } ... // Build the body of the helper using the above inputs val helperID = builder.build(watpe.Int32) { js.Return(js.BinaryOp(JSBinaryOp.+, xRef, js.IntLiteral(5))) } // Call the helper, which consumes the declared inputs and leaves the result on the stack fb += wa.Call(helperID)
The subclass CustomJSHelperBuilder.WithTreeEval provides even richer capabilities, by allowing to evaluate arbitrary IR
Tree
s as inputs. The builder will optimize the evaluation and transfer from Wasm to JS:- Evaluate some trees entirely on the JS side instead of on the Wasm side. This is notably the case for string literals, which commonly appear as method names, and global refs/external imports, which commonly appear as method receivers.
- For other trees, evaluate them on the Wasm side, but fuse their boxing operation with the Wasm-to-JS interoperability layer, by choosing the best possible Wasm type for the helper function.
When using the
WithTreeEval
subclass, the user must provide a concrete method to evaluateTree
s at call site with a given expected type. In the context ofFunctionEmitter
, that directly translates to thegenTree
method.A typical scenario looks like:
val builder = new CustomJSHelperBuilder.WithTreeEval() { protected def evalTreeAtCallSite(tree: Tree, expectedType: Type): Unit = ??? } // Add inputs that will be evaluated on the JS side if possible, otherwise // evaluated on the Wasm call site, and whose values are then available as // `js.Tree`s in the JS helper: val xRef = builder.addInput(someIRTree) ...
In addition to the input management,
CustomJSHelperBuilder
provides tools for local name management, and generation ofjs.ParamDef
s for inner functions. - final class Emitter extends AnyRef
- final class WasmContext extends AnyRef
Value Members
- object ClassEmitter
- object CustomJSHelperBuilder
-
object
DerivedClasses
Derives
CharacterBox
andLongBox
fromjl.Character
andjl.Long
. - object EmbeddedConstants
- object Emitter
- object FunctionEmitter
-
object
LoaderContent
Contents of the
loader.js
file that we emit in every output.
- object Preprocessor
-
object
SWasmGen
Scala.js-specific Wasm generators that are used across the board.
- object SpecialNames
- object TypeTransformer
-
object
VarGen
Manages generation of non-local IDs.
Manages generation of non-local IDs.
LocalID
s andLabelID
s are directly managed byFunctionBuilder
instead. - object WasmContext
-
object
WasmTransients
Transients generated by the optimizer that only makes sense in Wasm.