Options
All
  • Public
  • Public/Protected
  • All
Menu

Manage relevant components of WASM module, needed for compilation

Note: Could rename to Compiler but too abstract

Hierarchy

  • default

Index

Constructors

Properties

ctx?: default
definedHelpers: Set<string>

Track helper necessary functions generated

definitions: string[] = []

Primarily function exports. Compiled functions and stuff that go in main body of module

functions: FunExportExpr[] = []

Functions to export

imports: {} = {}

Set of imports

Type declaration

  • [k: string]: { importId: string; scopes: string[]; type: ArrowType; typeName: string }[]
noRuntime: boolean

Don't include normal runtime boilerplate

nurserySize: number

Size in bytes of the nursery section of linear memory (see planning/implementation/lm.md)

optLevel: number

Optimization level for compilation (0-3)

stackSize: number

Size in bytes of the references stack section of linear memory (see planning/implementation/lm.md)

staticData: number[] = []

Static data section of linear memory

staticDataConst: boolean[] = []

Indicates if data is const or user modifiyable

tableElems: string[] = []

Function ids to be added to the table

uid: number = 0

Used to generate unique importIds

Methods

  • addHelper(helperId: string): void
  • Define a helper/utility function that we don't really care about If it's already been defined return early

    depricated

    Parameters

    • helperId: string

      identifier for the helper function

    Returns void

  • Add an import

    Parameters

    • scopes: string[]

      env scopes to import from

    • type: ArrowType

      type of imported value

    Returns string | SyntaxError

    • identifier to which the import is assigned
  • addStaticData(data: string | number[] | Uint8Array | Uint16Array | Uint32Array, isConst?: boolean): number
  • Store static data

    Parameters

    • data: string | number[] | Uint8Array | Uint16Array | Uint32Array

      data to save statically

    • isConst: boolean = false

      if true we can check to see if it's already in data section and simply point to it

    Returns number

    • memory address for start of region
  • addToTable(fnName: string): number
  • Add a function to the table

    Parameters

    • fnName: string

      identifier for function to push into the table

    Returns number

    index of the function

  • compile(): string
  • Generate import section of wasm

    Returns string

    • WebAssembly text code
  • genTable(): string
  • Generate code for the table section of the the runtime

    Returns string

    wat code for the table section

  • generateRuntime(USER_IMPORTS: string, USER_CODE_STR: string, STACK_SIZE?: number, NURSERY_SIZE?: number): string
  • Generate a wasm module from a template which includes our runtime

    remark

    see planning/implementation/lm.md for more on memory layout

    Parameters

    • USER_IMPORTS: string
    • USER_CODE_STR: string

      user's function definitions and exports

    • STACK_SIZE: number = ...

      size of the references stack

    • NURSERY_SIZE: number = ...

    Returns string

    wasm module text

  • initialPages(): number
  • Determine the amount of memory to use

    Returns number

    • number of pages to start with
  • setStaticData(address: number, value: number): void
  • Initialize static data to a specific value

    Parameters

    • address: number

      address of static data to set

    • value: number

      value to set static data to

    Returns void

  • staticDataToHexString(): string
  • Generates a hexstring that initializes the start of linear memory

    Returns string

  • toByteArray(d: string | number[] | Uint8Array | Uint16Array | Uint32Array): Uint8Array
  • Convert data to byte array

    Parameters

    • d: string | number[] | Uint8Array | Uint16Array | Uint32Array

      data source

    Returns Uint8Array

    data as array of bytes

Generated using TypeDoc