Packages

package wasmemitter

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. class ClassEmitter extends AnyRef
  2. final class CoreWasmLib extends AnyRef
  3. 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 Trees 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 evaluate Trees at call site with a given expected type. In the context of FunctionEmitter, that directly translates to the genTree 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 of js.ParamDefs for inner functions.

  4. final class Emitter extends AnyRef
  5. final class WasmContext extends AnyRef

Value Members

  1. object ClassEmitter
  2. object CustomJSHelperBuilder
  3. object DerivedClasses

    Derives CharacterBox and LongBox from jl.Character and jl.Long.

  4. object EmbeddedConstants
  5. object Emitter
  6. object FunctionEmitter
  7. object LoaderContent

    Contents of the loader.js file that we emit in every output.

  8. object Preprocessor
  9. object SWasmGen

    Scala.js-specific Wasm generators that are used across the board.

  10. object SpecialNames
  11. object TypeTransformer
  12. object VarGen

    Manages generation of non-local IDs.

    Manages generation of non-local IDs.

    LocalIDs and LabelIDs are directly managed by FunctionBuilder instead.

  13. object WasmContext
  14. object WasmTransients

    Transients generated by the optimizer that only makes sense in Wasm.

Ungrouped