WebAssembly dialect adapter for MilkIR extension operations
///|
test "map Wasm reference spelling to generic MilkIR references" {
inspect(wasm_funcref_type().to_string(), content="callable_ref")
inspect(wasm_externref_type().to_string(), content="opaque_ref")
}///|
test "build a Wasm memory.size extension instruction" {
let builder = @milkir.FunctionBuilder::FunctionBuilder("memory_size")
let symbols = RuntimeSymbols::with_runtime_prefix("example.runtime")
let vmctx = builder.add_param(I64)
builder.add_result(I32)
let size = memory_size(builder, symbols, vmctx, 0)
builder.return_([size])
let func = builder.get_function()
inspect(func.blocks.length(), content="1")
inspect(func.verify(), content="()")
match func.blocks[0].instructions[1].opcode {
Call(symbol) => inspect(symbol.name, content="example.runtime.memory_size")
_ => inspect(false, content="true")
}
}pub(all) struct RuntimeSymbols {
memory_grow : String
memory_size : String
memory_fill : String
memory_copy : String
memory_init : String
data_drop : String
table_grow : String
table_fill : String
table_copy : String
table_init : String
elem_drop : String
gc_ref_test : String
gc_ref_cast : String
gc_struct_get : String
gc_struct_set : String
gc_array_get : String
gc_array_set : String
gc_array_len : String
gc_array_fill : String
gc_array_copy : String
gc_array_new_data : String
gc_array_new_elem : String
gc_array_init_data : String
gc_array_init_elem : String
gc_type_check_subtype : String
gc_register_struct_inline : String
gc_register_array_inline : String
gc_alloc_struct_slow : String
gc_alloc_array_from_values_slow : String
gc_alloc_array_slow : String
exception_try_begin : String
exception_try_end : String
exception_throw : String
exception_throw_tag : String
exception_throw_ref : String
exception_delegate : String
exception_get_tag : String
exception_get_value : String
exception_get_value_count : String
exception_sigsetjmp : String
exception_spill_locals : String
exception_get_spilled_local : String
} derive(Eq, Debug)pub(all) enum WasmOpcode {
LoadMemBase(Int)
MemoryGrow(Int, Int?)
MemorySize(Int)
MemoryFill(Int)
MemoryCopy(Int, Int)
MemoryInit(Int, Int)
DataDrop(Int)
TableGrow(Int)
TableFill(Int)
TableCopy(Int, Int)
TableInit(Int, Int)
ElemDrop(Int)
WasmCall(Int)
WasmCallIndirect(Int, Int)
CallRef(Int)
ReturnCall(Int)
ReturnCallIndirect(Int, Int)
ReturnCallRef(Int)
GetFuncRef(Int)
StructNew(Int)
StructNewDefault(Int)
StructGet(Int, Int)
StructGetS(Int, Int, Int)
StructGetU(Int, Int, Int)
StructSet(Int, Int)
ArrayNew(Int)
ArrayNewDefault(Int)
ArrayNewFixed(Int, Int)
ArrayGet(Int)
ArrayGetS(Int, Int)
ArrayGetU(Int, Int)
ArraySet(Int)
ArrayLen
ArrayFill(Int)
ArrayCopy(Int, Int)
ArrayNewData(Int, Int)
ArrayNewElem(Int, Int)
ArrayInitData(Int, Int)
ArrayInitElem(Int, Int)
I31New
I31GetS
I31GetU
RefTest(Int, Bool)
RefCast(Int, Bool)
AnyConvertExtern
ExternConvertAny
RefEq
Throw(Int)
ThrowRef
TryTableBegin(Int)
TryTableEnd(Int)
GetExceptionTag
GetExceptionValue(Int)
GetExceptionValueCount
Delegate(Int)
SpillLocalsForThrow(Int)
GetSpilledLocal(Int)
} derive(Eq, Hash, Debug)fn array_fill(builder : FunctionBuilder, type_idx : Int, array_ref : Value, offset : Value, value : Value, count : Value) -> Unitfn array_get(builder : FunctionBuilder, type_idx : Int, array_ref : Value, index : Value, element_type : Type) -> Valuefn array_get_s(builder : FunctionBuilder, type_idx : Int, array_ref : Value, index : Value, element_type : Type, byte_width : Int) -> Valuefn array_get_u(builder : FunctionBuilder, type_idx : Int, array_ref : Value, index : Value, element_type : Type, byte_width : Int) -> Valuefn array_init_data(builder : FunctionBuilder, type_idx : Int, data_idx : Int, array_ref : Value, arr_offset : Value, data_offset : Value, length : Value) -> Unitfn array_init_elem(builder : FunctionBuilder, type_idx : Int, elem_idx : Int, array_ref : Value, arr_offset : Value, elem_offset : Value, length : Value) -> Unitfn array_new(builder : FunctionBuilder, type_idx : Int, init_value : Value, length : Value) -> Valuefn array_new_data(builder : FunctionBuilder, type_idx : Int, data_idx : Int, data_offset : Value, length : Value) -> Valuefn array_new_elem(builder : FunctionBuilder, type_idx : Int, elem_idx : Int, elem_offset : Value, length : Value) -> Valuefn array_new_fixed(builder : FunctionBuilder, type_idx : Int, count : Int, elements : Array[Value]) -> Valuefn array_set(builder : FunctionBuilder, type_idx : Int, array_ref : Value, index : Value, value : Value) -> Unitfn data_drop(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, data_idx : Int) -> Unitfn elem_drop(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, elem_idx : Int) -> Unitfn memory_copy(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, dst_memidx : Int, src_memidx : Int, dst : Value, src : Value, size : Value) -> Unitfn memory_fill(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, memidx : Int, dst : Value, val : Value, size : Value) -> Unitfn memory_grow(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, memidx : Int, delta : Value, max_pages? : Int, is_memory64? : Bool) -> Valuefn memory_init(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, memidx : Int, data_idx : Int, dst : Value, src : Value, size : Value) -> Unitfn memory_size(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, memidx : Int, is_memory64? : Bool) -> Valuefn return_call_indirect_multi(builder : FunctionBuilder, type_idx : Int, table_idx : Int, callee : Value, args : Array[Value]) -> Unitfn return_call_ref_multi(builder : FunctionBuilder, type_idx : Int, func_ref : Value, args : Array[Value]) -> Unitfn struct_get(builder : FunctionBuilder, type_idx : Int, field_idx : Int, struct_ref : Value, field_type : Type) -> Valuefn struct_get_s(builder : FunctionBuilder, type_idx : Int, field_idx : Int, struct_ref : Value, field_type : Type, byte_width : Int) -> Valuefn struct_get_u(builder : FunctionBuilder, type_idx : Int, field_idx : Int, struct_ref : Value, field_type : Type, byte_width : Int) -> Valuefn struct_set(builder : FunctionBuilder, type_idx : Int, field_idx : Int, struct_ref : Value, value : Value) -> Unitfn table_copy(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, dst_table_idx : Int, src_table_idx : Int, dst : Value, src : Value, size : Value) -> Unitfn table_fill(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, table_idx : Int, dst : Value, val : Value, size : Value) -> Unitfn table_grow(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, table_idx : Int, delta : Value, init_value : Value) -> Valuefn table_init(builder : FunctionBuilder, runtime_symbols : RuntimeSymbols, vmctx : Value, table_idx : Int, elem_idx : Int, dst : Value, src : Value, size : Value) -> UnitInstall
Download zipWebAssembly dialect adapter for MilkIR extension operations