Sign in

    wasm_isa_lower

    WebAssembly MilkIR dialect adapter for MachV lowering

    wasm
    compiler
    lowering
    jit
    Download zip
    Author
    Version
    0.2.2
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    56

    Milky2018/wasm_isa_lower does not have a README file

    WasmContextSlots

    pub(all) struct WasmContextSlots {
    memory0_base : Int
    function_table : Int
    table0_base : Int
    table_directory : Int
    memory_directory : Int
    pointer_stride : Int
    }

    Context slot roles required by reusable Wasm-to-MachV lowering.

    The numeric ids are embedding-defined handles into the generic MachV embedding context layout. Product-specific runtimes own the concrete ids.

    WasmLoweringOptions

    type WasmLoweringOptions

    context_slot_cache_key

    fn context_slot_cache_key(slot_id : Int) -> Int

    external_helper_symbols

    fn external_helper_symbols(symbols :
    RuntimeSymbols
    ) -> Map[String, String]

    load_context_slot_pointer_from_pinned_context

    fn load_context_slot_pointer_from_pinned_context(ctx :
    LoweringContext
    , block :
    Block
    , slot_id : Int) ->
    VReg

    lower_array_copy

    fn lower_array_copy(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , _dst_type : Int, _src_type : Int) -> Unit

    Lower array.copy: Copy elements between arrays Uses runtime libcall: gc_array_copy_impl(dst_ref, dst_off, src_ref, src_off, count)

    lower_array_fill

    Lower array.fill: Fill array elements with a value Uses runtime libcall: gc_array_fill_impl(ref, offset, value, count)

    lower_array_get

    Lower array.get: Get array element Uses runtime libcall: gc_array_get_impl(ref, type_idx, idx) -> value

    lower_array_get_s

    fn lower_array_get_s(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, byte_width : Int) -> Unit

    Lower array.get_s: Get array element with sign extension Uses runtime libcall then sign extends based on byte_width

    lower_array_get_u

    fn lower_array_get_u(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, byte_width : Int) -> Unit

    Lower array.get_u: Get array element with zero extension Uses runtime libcall then zero extends based on byte_width

    lower_array_init_data

    fn lower_array_init_data(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, data_idx : Int) -> Unit

    Lower array.init_data instruction Initializes array elements from a data segment

    lower_array_init_elem

    fn lower_array_init_elem(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, elem_idx : Int) -> Unit

    Lower array.init_elem instruction Initializes array elements from an element segment

    lower_array_len

    Lower array.len: Get array length Uses runtime libcall: gc_array_len_impl(ref) -> length

    lower_array_new

    Lower array.new: Allocate array with init value and length Uses runtime libcall: gc_alloc_array_slow(vmctx, type_idx, length, init_value, safepoint_id) -> array_ref

    lower_array_new_data

    fn lower_array_new_data(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, data_idx : Int) -> Unit

    Lower array.new_data instruction Creates an array from a data segment

    lower_array_new_default

    Lower array.new_default: Allocate array with default values Uses runtime libcall: gc_alloc_array_slow(vmctx, type_idx, length, init_value=0, safepoint_id) -> array_ref

    lower_array_new_elem

    fn lower_array_new_elem(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, elem_idx : Int) -> Unit

    Lower array.new_elem instruction Creates an array from an element segment

    lower_array_new_fixed

    Lower array.new_fixed: Allocate fixed-size array with element values Uses runtime libcalls: gc_alloc_array_slow and gc_array_set_impl

    lower_array_set

    Lower array.set: Set array element Uses runtime libcall: gc_array_set_impl(ref, type_idx, idx, value)

    lower_call

    Lower a direct function call Cranelift-aligned strategy: use direct call fixups (CallDirect) for both defined and imported functions. Imported targets are resolved from vmctx->func_table when call fixups are applied at module load time.

    lower_call_indirect

    fn lower_call_indirect(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , expected_type_idx : Int, table_idx : Int, options : WasmLoweringOptions) -> Unit

    Lower an indirect function call (call_indirect) The callee is already on the stack as a function table index

    lower_call_ref

    Lower call_ref instruction call_ref calls through a function reference (tagged function pointer) The func_ref is a tagged pointer (func_ptr | FUNCREF_TAG where FUNCREF_TAG = 0x2000000000000000) The null check is already done in IR, so we just need to:
    1. Strip the FUNCREF_TAG to get the raw function pointer
    2. Call through the function pointer

    lower_delegate

    Lower Delegate(depth) instruction Calls exception_delegate(ctx, depth)

    lower_function

    fn lower_function(func :
    Function
    , context_slots : WasmContextSlots, isa? :
    ISA
    , embedding_abi? :
    EmbeddingABI
    ?, runtime_symbols? :
    RuntimeSymbols
    , num_imports? : Int, run_ir_opt? : Bool, trap_payload_resolver? : (String) -> Int, use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int]) ->
    Function

    lower_gc_convert

    Lower GC type conversions (any.convert_extern, extern.convert_any) These are no-ops in the JIT - just pass the reference through

    lower_get_exception_tag

    Lower GetExceptionTag instruction Calls exception_get_tag(ctx) -> tag

    lower_get_exception_value

    Lower GetExceptionValue(idx) instruction Calls exception_get_value(ctx, idx) -> value

    lower_get_exception_value_count

    Lower GetExceptionValueCount instruction Calls exception_get_value_count(ctx) -> count

    lower_get_func_ref

    fn lower_get_func_ref(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , func_idx : Int, context_slots : WasmContextSlots) -> Unit

    Lower GetFuncRef - get tagged function pointer for storing in tables Returns func_ptr | FUNCREF_TAG (bit 61) for ref.test detection

    lower_get_spilled_local

    Lower GetSpilledLocal(idx) instruction Calls exception_get_spilled_local(ctx, idx) -> value

    lower_i31_get_s

    Lower i31.get_s: Sign-extend 31 bits to i32 Encoding is (value << 1) | 1, so:
    1. Check for null (0) and trap
    2. Shift right by 1 to decode (removes the tag bit)
    3. Sign-extend from 31 bits

    lower_i31_get_u

    Lower i31.get_u: Zero-extend 31 bits Encoding is (value << 1) | 1, so:
    1. Check for null (0) and trap
    2. Shift right by 1 to decode (removes the tag bit)
    3. Mask with 0x7FFFFFFF for 31 bits

    lower_i31_new

    Lower i31.new: Convert i32 to i31ref Encoding: (value << 1) | 1 (positive odd for i31)

    lower_load_mem_base

    Lower memory-base access to generic pointer loads from the runtime context. memidx: memory index for multi-memory support

    lower_ref_cast

    fn lower_ref_cast(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, nullable : Bool) -> Unit

    Lower ref.cast: Cast reference to type (traps on failure) Uses runtime libcall: gc_ref_cast_impl(ref, type_idx, nullable) -> ref or trap

    lower_ref_eq

    Lower ref.eq: Compare two references for equality Returns 1 if equal, 0 otherwise

    lower_ref_test

    fn lower_ref_test(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, nullable : Bool) -> Unit

    Lower ref.test: Test if reference matches type Uses runtime libcall: gc_ref_test_impl(ref, type_idx, nullable) -> 0 or 1

    lower_return_call

    Lower direct return_call (tail call optimization) Note: parameters are handled in lowering phase
    • Overflow args: StoreToStack instructions
    • Register args: Fixed register constraints via add_use_fixed
    • ReturnCallIndirect instruction only contains func_ptr use

    lower_return_call_indirect

    fn lower_return_call_indirect(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, table_idx : Int, options : WasmLoweringOptions) -> Unit

    Lower return_call_indirect (indirect tail call) Note: parameters handled in lowering via StoreToStack and add_use_fixed

    lower_return_call_ref

    Lower return_call_ref (tail call through function reference) The func_ref is a tagged pointer (func_ptr | FUNCREF_TAG where FUNCREF_TAG = 0x2000000000000000) Note: parameters handled in lowering

    lower_spill_locals_for_throw

    Lower SpillLocalsForThrow(count) instruction Calls exception_spill_locals(ctx, locals_ptr, count) This saves all locals to memory so catch handlers can see throw-time values

    lower_struct_get

    fn lower_struct_get(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, field_idx : Int) -> Unit

    Lower struct.get: Get struct field value Uses runtime libcall: gc_struct_get_impl(ref, type_idx, field_idx) -> value

    lower_struct_get_s

    fn lower_struct_get_s(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, field_idx : Int, byte_width : Int) -> Unit

    Lower struct.get_s: Get struct field value with sign extension Uses runtime libcall then sign extends based on byte_width

    lower_struct_get_u

    fn lower_struct_get_u(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, field_idx : Int, byte_width : Int) -> Unit

    Lower struct.get_u: Get struct field value with zero extension Uses runtime libcall then zero extends based on byte_width

    lower_struct_new

    Lower struct.new: Allocate struct with field values Uses runtime libcall: gc_alloc_struct_slow(vmctx, type_idx, fields_ptr, num_fields, safepoint_id) -> struct_ref

    lower_struct_new_default

    Lower struct.new_default: Allocate struct with default values Uses runtime libcall: gc_alloc_struct_slow(vmctx, type_idx, null, 0, safepoint_id) -> struct_ref

    lower_struct_set

    fn lower_struct_set(ctx :
    LoweringContext
    , inst :
    Inst
    , block :
    Block
    , type_idx : Int, field_idx : Int) -> Unit

    Lower struct.set: Set struct field value Uses runtime libcall: gc_struct_set_impl(ref, type_idx, field_idx, value)

    lower_throw

    Lower Throw(tag_idx) instruction Calls exception_throw(ctx, tag_idx, values_ptr, count)

    lower_throw_ref

    Lower ThrowRef instruction Calls exception_throw_ref(ctx, exnref)

    lower_try_table_begin

    Lower TryTableBegin(handler_id) instruction Calls exception_try_begin(ctx, handler_id) -> jmp_buf ptr Then calls sigsetjmp(jmp_buf_ptr, 0) -> result

    The TryTableBegin IR instruction returns 0 normally, or handler_id on catch. This is the result of sigsetjmp.

    lower_try_table_end

    Lower TryTableEnd(handler_id) instruction Calls exception_try_end(ctx, handler_id)

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io