#![allow(missing_docs)]
use eyre::Result;
use wasm_encoder::Instruction;
pub trait Rebind {
fn function(&self, index: u32) -> u32 {
index
}
fn global(&self, index: u32) -> u32 {
index
}
fn memory(&self, index: u32) -> u32 {
index
}
fn table(&self, index: u32) -> u32 {
index
}
fn ty(&self, index: u32) -> u32 {
index
}
fn data(&self, index: u32) -> u32 {
index
}
fn elem(&self, index: u32) -> u32 {
index
}
fn tag(&self, index: u32) -> u32 {
index
}
}
pub fn translate_memory_type(t: wasmparser::MemoryType) -> wasm_encoder::MemoryType {
wasm_encoder::MemoryType {
minimum: t.initial,
maximum: t.maximum,
memory64: t.memory64,
shared: t.shared,
page_size_log2: t.page_size_log2,
}
}
pub fn translate_table_type<R: Rebind>(
t: wasmparser::TableType,
rebinder: &R,
) -> wasm_encoder::TableType {
wasm_encoder::TableType {
element_type: translate_ref_type(t.element_type, rebinder),
minimum: t.initial,
maximum: t.maximum,
shared: t.shared,
table64: t.table64,
}
}
pub fn translate_global_type<R: Rebind>(
t: wasmparser::GlobalType,
rebinder: &R,
) -> wasm_encoder::GlobalType {
wasm_encoder::GlobalType {
val_type: translate_val_type(t.content_type, rebinder),
mutable: t.mutable,
shared: false,
}
}
pub fn translate_tag_type(t: wasmparser::TagType) -> wasm_encoder::TagType {
wasm_encoder::TagType {
kind: match t.kind {
wasmparser::TagKind::Exception => wasm_encoder::TagKind::Exception,
},
func_type_idx: t.func_type_idx,
}
}
pub fn translate_ref_type<R: Rebind>(
r: wasmparser::RefType,
rebinder: &R,
) -> wasm_encoder::RefType {
wasm_encoder::RefType {
nullable: r.is_nullable(),
heap_type: translate_heap_type(r.heap_type(), rebinder),
}
}
pub fn translate_heap_type<R: Rebind>(
h: wasmparser::HeapType,
rebinder: &R,
) -> wasm_encoder::HeapType {
match h {
wasmparser::HeapType::Abstract { shared, ty } => wasm_encoder::HeapType::Abstract {
shared,
ty: translate_abstract_heap_type(ty),
},
wasmparser::HeapType::Concrete(wasmparser::UnpackedIndex::Module(idx)) => {
wasm_encoder::HeapType::Concrete(rebinder.ty(idx))
}
wasmparser::HeapType::Concrete(_) => {
unimplemented!("Concrete heap type other than Module not supported yet")
}
wasmparser::HeapType::Exact(wasmparser::UnpackedIndex::Module(idx)) => {
wasm_encoder::HeapType::Exact(rebinder.ty(idx))
}
wasmparser::HeapType::Exact(_) => {
unimplemented!("Exact heap type other than Module not supported yet")
}
}
}
pub fn translate_sub_type<R: Rebind>(
sub_ty: &wasmparser::SubType,
rebinder: &R,
) -> wasm_encoder::SubType {
let composite_type = match &sub_ty.composite_type.inner {
wasmparser::CompositeInnerType::Func(f) => {
let params = f
.params()
.iter()
.copied()
.map(|t| translate_val_type(t, rebinder))
.collect::<Vec<_>>();
let results = f
.results()
.iter()
.copied()
.map(|t| translate_val_type(t, rebinder))
.collect::<Vec<_>>();
wasm_encoder::CompositeType {
inner: wasm_encoder::CompositeInnerType::Func(wasm_encoder::FuncType::new(
params, results,
)),
shared: sub_ty.composite_type.shared,
descriptor: sub_ty
.composite_type
.descriptor_idx
.map(|idx| rebinder.ty(idx.as_module_index().unwrap())),
describes: sub_ty
.composite_type
.describes_idx
.map(|idx| rebinder.ty(idx.as_module_index().unwrap())),
}
}
_ => unimplemented!("translate_sub_type: {:?}", sub_ty),
};
wasm_encoder::SubType {
is_final: sub_ty.is_final,
supertype_idx: sub_ty
.supertype_idx
.map(|idx| rebinder.ty(idx.as_module_index().unwrap())),
composite_type,
}
}
pub fn translate_abstract_heap_type(
t: wasmparser::AbstractHeapType,
) -> wasm_encoder::AbstractHeapType {
match t {
wasmparser::AbstractHeapType::Func => wasm_encoder::AbstractHeapType::Func,
wasmparser::AbstractHeapType::Extern => wasm_encoder::AbstractHeapType::Extern,
wasmparser::AbstractHeapType::Any => wasm_encoder::AbstractHeapType::Any,
wasmparser::AbstractHeapType::None => wasm_encoder::AbstractHeapType::None,
wasmparser::AbstractHeapType::NoExtern => wasm_encoder::AbstractHeapType::NoExtern,
wasmparser::AbstractHeapType::NoFunc => wasm_encoder::AbstractHeapType::NoFunc,
wasmparser::AbstractHeapType::Eq => wasm_encoder::AbstractHeapType::Eq,
wasmparser::AbstractHeapType::Struct => wasm_encoder::AbstractHeapType::Struct,
wasmparser::AbstractHeapType::Array => wasm_encoder::AbstractHeapType::Array,
wasmparser::AbstractHeapType::I31 => wasm_encoder::AbstractHeapType::I31,
wasmparser::AbstractHeapType::Exn => wasm_encoder::AbstractHeapType::Exn,
wasmparser::AbstractHeapType::NoExn => wasm_encoder::AbstractHeapType::NoExn,
_ => unimplemented!("translate_abstract_heap_type: {:?}", t),
}
}
pub struct DefaultRebinder;
impl Rebind for DefaultRebinder {}
pub fn translate<'a, R: Rebind>(op: &wasmparser::Operator<'a>, rebinder: &R) -> Instruction<'a> {
match op {
wasmparser::Operator::Unreachable => Instruction::Unreachable,
wasmparser::Operator::Nop => Instruction::Nop,
wasmparser::Operator::Block { blockty } => {
Instruction::Block(translate_block_type(*blockty, rebinder))
}
wasmparser::Operator::Loop { blockty } => {
Instruction::Loop(translate_block_type(*blockty, rebinder))
}
wasmparser::Operator::If { blockty } => {
Instruction::If(translate_block_type(*blockty, rebinder))
}
wasmparser::Operator::Else => Instruction::Else,
wasmparser::Operator::End => Instruction::End,
wasmparser::Operator::Br { relative_depth } => Instruction::Br(*relative_depth),
wasmparser::Operator::BrIf { relative_depth } => Instruction::BrIf(*relative_depth),
wasmparser::Operator::BrTable { targets } => {
let t: Vec<u32> = targets.targets().collect::<Result<Vec<_>, _>>().unwrap();
Instruction::BrTable(std::borrow::Cow::Owned(t), targets.default())
}
wasmparser::Operator::Return => Instruction::Return,
wasmparser::Operator::Call { function_index } => {
Instruction::Call(rebinder.function(*function_index))
}
wasmparser::Operator::CallIndirect {
type_index,
table_index,
..
} => Instruction::CallIndirect {
type_index: rebinder.ty(*type_index),
table_index: rebinder.table(*table_index),
},
wasmparser::Operator::Drop => Instruction::Drop,
wasmparser::Operator::Select => Instruction::Select,
wasmparser::Operator::LocalGet { local_index } => Instruction::LocalGet(*local_index),
wasmparser::Operator::LocalSet { local_index } => Instruction::LocalSet(*local_index),
wasmparser::Operator::LocalTee { local_index } => Instruction::LocalTee(*local_index),
wasmparser::Operator::GlobalGet { global_index } => {
Instruction::GlobalGet(rebinder.global(*global_index))
}
wasmparser::Operator::GlobalSet { global_index } => {
Instruction::GlobalSet(rebinder.global(*global_index))
}
wasmparser::Operator::I32Load { memarg } => {
Instruction::I32Load(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load { memarg } => {
Instruction::I64Load(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::F32Load { memarg } => {
Instruction::F32Load(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::F64Load { memarg } => {
Instruction::F64Load(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Load8S { memarg } => {
Instruction::I32Load8S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Load8U { memarg } => {
Instruction::I32Load8U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Load16S { memarg } => {
Instruction::I32Load16S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Load16U { memarg } => {
Instruction::I32Load16U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load8S { memarg } => {
Instruction::I64Load8S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load8U { memarg } => {
Instruction::I64Load8U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load16S { memarg } => {
Instruction::I64Load16S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load16U { memarg } => {
Instruction::I64Load16U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load32S { memarg } => {
Instruction::I64Load32S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Load32U { memarg } => {
Instruction::I64Load32U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Store { memarg } => {
Instruction::I32Store(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Store { memarg } => {
Instruction::I64Store(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::F32Store { memarg } => {
Instruction::F32Store(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::F64Store { memarg } => {
Instruction::F64Store(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Store8 { memarg } => {
Instruction::I32Store8(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32Store16 { memarg } => {
Instruction::I32Store16(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Store8 { memarg } => {
Instruction::I64Store8(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Store16 { memarg } => {
Instruction::I64Store16(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64Store32 { memarg } => {
Instruction::I64Store32(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::MemorySize { mem } => Instruction::MemorySize(rebinder.memory(*mem)),
wasmparser::Operator::MemoryGrow { mem } => Instruction::MemoryGrow(rebinder.memory(*mem)),
wasmparser::Operator::I32Const { value } => Instruction::I32Const(*value),
wasmparser::Operator::I64Const { value } => Instruction::I64Const(*value),
wasmparser::Operator::F32Const { value } => {
Instruction::F32Const(f32::from_bits(value.bits()).into())
}
wasmparser::Operator::F64Const { value } => {
Instruction::F64Const(f64::from_bits(value.bits()).into())
}
wasmparser::Operator::I32Eqz => Instruction::I32Eqz,
wasmparser::Operator::I32Eq => Instruction::I32Eq,
wasmparser::Operator::I32Ne => Instruction::I32Ne,
wasmparser::Operator::I32LtS => Instruction::I32LtS,
wasmparser::Operator::I32LtU => Instruction::I32LtU,
wasmparser::Operator::I32GtS => Instruction::I32GtS,
wasmparser::Operator::I32GtU => Instruction::I32GtU,
wasmparser::Operator::I32LeS => Instruction::I32LeS,
wasmparser::Operator::I32LeU => Instruction::I32LeU,
wasmparser::Operator::I32GeS => Instruction::I32GeS,
wasmparser::Operator::I32GeU => Instruction::I32GeU,
wasmparser::Operator::I64Eqz => Instruction::I64Eqz,
wasmparser::Operator::I64Eq => Instruction::I64Eq,
wasmparser::Operator::I64Ne => Instruction::I64Ne,
wasmparser::Operator::I64LtS => Instruction::I64LtS,
wasmparser::Operator::I64LtU => Instruction::I64LtU,
wasmparser::Operator::I64GtS => Instruction::I64GtS,
wasmparser::Operator::I64GtU => Instruction::I64GtU,
wasmparser::Operator::I64LeS => Instruction::I64LeS,
wasmparser::Operator::I64LeU => Instruction::I64LeU,
wasmparser::Operator::I64GeS => Instruction::I64GeS,
wasmparser::Operator::I64GeU => Instruction::I64GeU,
wasmparser::Operator::F32Eq => Instruction::F32Eq,
wasmparser::Operator::F32Ne => Instruction::F32Ne,
wasmparser::Operator::F32Lt => Instruction::F32Lt,
wasmparser::Operator::F32Gt => Instruction::F32Gt,
wasmparser::Operator::F32Le => Instruction::F32Le,
wasmparser::Operator::F32Ge => Instruction::F32Ge,
wasmparser::Operator::F64Eq => Instruction::F64Eq,
wasmparser::Operator::F64Ne => Instruction::F64Ne,
wasmparser::Operator::F64Lt => Instruction::F64Lt,
wasmparser::Operator::F64Gt => Instruction::F64Gt,
wasmparser::Operator::F64Le => Instruction::F64Le,
wasmparser::Operator::F64Ge => Instruction::F64Ge,
wasmparser::Operator::I32Clz => Instruction::I32Clz,
wasmparser::Operator::I32Ctz => Instruction::I32Ctz,
wasmparser::Operator::I32Popcnt => Instruction::I32Popcnt,
wasmparser::Operator::I32Add => Instruction::I32Add,
wasmparser::Operator::I32Sub => Instruction::I32Sub,
wasmparser::Operator::I32Mul => Instruction::I32Mul,
wasmparser::Operator::I32DivS => Instruction::I32DivS,
wasmparser::Operator::I32DivU => Instruction::I32DivU,
wasmparser::Operator::I32RemS => Instruction::I32RemS,
wasmparser::Operator::I32RemU => Instruction::I32RemU,
wasmparser::Operator::I32And => Instruction::I32And,
wasmparser::Operator::I32Or => Instruction::I32Or,
wasmparser::Operator::I32Xor => Instruction::I32Xor,
wasmparser::Operator::I32Shl => Instruction::I32Shl,
wasmparser::Operator::I32ShrS => Instruction::I32ShrS,
wasmparser::Operator::I32ShrU => Instruction::I32ShrU,
wasmparser::Operator::I32Rotl => Instruction::I32Rotl,
wasmparser::Operator::I32Rotr => Instruction::I32Rotr,
wasmparser::Operator::I64Clz => Instruction::I64Clz,
wasmparser::Operator::I64Ctz => Instruction::I64Ctz,
wasmparser::Operator::I64Popcnt => Instruction::I64Popcnt,
wasmparser::Operator::I64Add => Instruction::I64Add,
wasmparser::Operator::I64Sub => Instruction::I64Sub,
wasmparser::Operator::I64Mul => Instruction::I64Mul,
wasmparser::Operator::I64DivS => Instruction::I64DivS,
wasmparser::Operator::I64DivU => Instruction::I64DivU,
wasmparser::Operator::I64RemS => Instruction::I64RemS,
wasmparser::Operator::I64RemU => Instruction::I64RemU,
wasmparser::Operator::I64And => Instruction::I64And,
wasmparser::Operator::I64Or => Instruction::I64Or,
wasmparser::Operator::I64Xor => Instruction::I64Xor,
wasmparser::Operator::I64Shl => Instruction::I64Shl,
wasmparser::Operator::I64ShrS => Instruction::I64ShrS,
wasmparser::Operator::I64ShrU => Instruction::I64ShrU,
wasmparser::Operator::I64Rotl => Instruction::I64Rotl,
wasmparser::Operator::I64Rotr => Instruction::I64Rotr,
wasmparser::Operator::F32Abs => Instruction::F32Abs,
wasmparser::Operator::F32Neg => Instruction::F32Neg,
wasmparser::Operator::F32Ceil => Instruction::F32Ceil,
wasmparser::Operator::F32Floor => Instruction::F32Floor,
wasmparser::Operator::F32Trunc => Instruction::F32Trunc,
wasmparser::Operator::F32Nearest => Instruction::F32Nearest,
wasmparser::Operator::F32Sqrt => Instruction::F32Sqrt,
wasmparser::Operator::F32Add => Instruction::F32Add,
wasmparser::Operator::F32Sub => Instruction::F32Sub,
wasmparser::Operator::F32Mul => Instruction::F32Mul,
wasmparser::Operator::F32Div => Instruction::F32Div,
wasmparser::Operator::F32Min => Instruction::F32Min,
wasmparser::Operator::F32Max => Instruction::F32Max,
wasmparser::Operator::F32Copysign => Instruction::F32Copysign,
wasmparser::Operator::F64Abs => Instruction::F64Abs,
wasmparser::Operator::F64Neg => Instruction::F64Neg,
wasmparser::Operator::F64Ceil => Instruction::F64Ceil,
wasmparser::Operator::F64Floor => Instruction::F64Floor,
wasmparser::Operator::F64Trunc => Instruction::F64Trunc,
wasmparser::Operator::F64Nearest => Instruction::F64Nearest,
wasmparser::Operator::F64Sqrt => Instruction::F64Sqrt,
wasmparser::Operator::F64Add => Instruction::F64Add,
wasmparser::Operator::F64Sub => Instruction::F64Sub,
wasmparser::Operator::F64Mul => Instruction::F64Mul,
wasmparser::Operator::F64Div => Instruction::F64Div,
wasmparser::Operator::F64Min => Instruction::F64Min,
wasmparser::Operator::F64Max => Instruction::F64Max,
wasmparser::Operator::F64Copysign => Instruction::F64Copysign,
wasmparser::Operator::I32WrapI64 => Instruction::I32WrapI64,
wasmparser::Operator::I32TruncF32S => Instruction::I32TruncF32S,
wasmparser::Operator::I32TruncF32U => Instruction::I32TruncF32U,
wasmparser::Operator::I32TruncF64S => Instruction::I32TruncF64S,
wasmparser::Operator::I32TruncF64U => Instruction::I32TruncF64U,
wasmparser::Operator::I64ExtendI32S => Instruction::I64ExtendI32S,
wasmparser::Operator::I64ExtendI32U => Instruction::I64ExtendI32U,
wasmparser::Operator::I64TruncF32S => Instruction::I64TruncF32S,
wasmparser::Operator::I64TruncF32U => Instruction::I64TruncF32U,
wasmparser::Operator::I64TruncF64S => Instruction::I64TruncF64S,
wasmparser::Operator::I64TruncF64U => Instruction::I64TruncF64U,
wasmparser::Operator::F32ConvertI32S => Instruction::F32ConvertI32S,
wasmparser::Operator::F32ConvertI32U => Instruction::F32ConvertI32U,
wasmparser::Operator::F32ConvertI64S => Instruction::F32ConvertI64S,
wasmparser::Operator::F32ConvertI64U => Instruction::F32ConvertI64U,
wasmparser::Operator::F32DemoteF64 => Instruction::F32DemoteF64,
wasmparser::Operator::F64ConvertI32S => Instruction::F64ConvertI32S,
wasmparser::Operator::F64ConvertI32U => Instruction::F64ConvertI32U,
wasmparser::Operator::F64ConvertI64S => Instruction::F64ConvertI64S,
wasmparser::Operator::F64ConvertI64U => Instruction::F64ConvertI64U,
wasmparser::Operator::F64PromoteF32 => Instruction::F64PromoteF32,
wasmparser::Operator::I32ReinterpretF32 => Instruction::I32ReinterpretF32,
wasmparser::Operator::I64ReinterpretF64 => Instruction::I64ReinterpretF64,
wasmparser::Operator::F32ReinterpretI32 => Instruction::F32ReinterpretI32,
wasmparser::Operator::F64ReinterpretI64 => Instruction::F64ReinterpretI64,
wasmparser::Operator::I32Extend8S => Instruction::I32Extend8S,
wasmparser::Operator::I32Extend16S => Instruction::I32Extend16S,
wasmparser::Operator::I64Extend8S => Instruction::I64Extend8S,
wasmparser::Operator::I64Extend16S => Instruction::I64Extend16S,
wasmparser::Operator::I64Extend32S => Instruction::I64Extend32S,
wasmparser::Operator::RefEq => Instruction::RefEq,
wasmparser::Operator::StructNew { struct_type_index } => {
Instruction::StructNew(*struct_type_index)
}
wasmparser::Operator::StructNewDefault { struct_type_index } => {
Instruction::StructNewDefault(*struct_type_index)
}
wasmparser::Operator::StructGet {
struct_type_index,
field_index,
} => Instruction::StructGet {
struct_type_index: rebinder.ty(*struct_type_index),
field_index: *field_index,
},
wasmparser::Operator::StructGetS {
struct_type_index,
field_index,
} => Instruction::StructGetS {
struct_type_index: rebinder.ty(*struct_type_index),
field_index: *field_index,
},
wasmparser::Operator::StructGetU {
struct_type_index,
field_index,
} => Instruction::StructGetU {
struct_type_index: rebinder.ty(*struct_type_index),
field_index: *field_index,
},
wasmparser::Operator::StructSet {
struct_type_index,
field_index,
} => Instruction::StructSet {
struct_type_index: rebinder.ty(*struct_type_index),
field_index: *field_index,
},
wasmparser::Operator::ArrayNew { array_type_index } => {
Instruction::ArrayNew(*array_type_index)
}
wasmparser::Operator::ArrayNewDefault { array_type_index } => {
Instruction::ArrayNewDefault(*array_type_index)
}
wasmparser::Operator::ArrayNewFixed {
array_type_index,
array_size,
} => Instruction::ArrayNewFixed {
array_type_index: rebinder.ty(*array_type_index),
array_size: *array_size,
},
wasmparser::Operator::ArrayNewData {
array_type_index,
array_data_index,
} => Instruction::ArrayNewData {
array_type_index: rebinder.ty(*array_type_index),
array_data_index: rebinder.data(*array_data_index),
},
wasmparser::Operator::ArrayNewElem {
array_type_index,
array_elem_index,
} => Instruction::ArrayNewElem {
array_type_index: rebinder.ty(*array_type_index),
array_elem_index: rebinder.elem(*array_elem_index),
},
wasmparser::Operator::ArrayGet { array_type_index } => {
Instruction::ArrayGet(*array_type_index)
}
wasmparser::Operator::ArrayGetS { array_type_index } => {
Instruction::ArrayGetS(*array_type_index)
}
wasmparser::Operator::ArrayGetU { array_type_index } => {
Instruction::ArrayGetU(*array_type_index)
}
wasmparser::Operator::ArraySet { array_type_index } => {
Instruction::ArraySet(*array_type_index)
}
wasmparser::Operator::ArrayLen => Instruction::ArrayLen,
wasmparser::Operator::ArrayFill { array_type_index } => {
Instruction::ArrayFill(rebinder.ty(*array_type_index))
}
wasmparser::Operator::ArrayCopy {
array_type_index_dst,
array_type_index_src,
} => Instruction::ArrayCopy {
array_type_index_dst: rebinder.ty(*array_type_index_dst),
array_type_index_src: rebinder.ty(*array_type_index_src),
},
wasmparser::Operator::ArrayInitData {
array_type_index,
array_data_index,
} => Instruction::ArrayInitData {
array_type_index: rebinder.ty(*array_type_index),
array_data_index: rebinder.data(*array_data_index),
},
wasmparser::Operator::ArrayInitElem {
array_type_index,
array_elem_index,
} => Instruction::ArrayInitElem {
array_type_index: rebinder.ty(*array_type_index),
array_elem_index: rebinder.elem(*array_elem_index),
},
wasmparser::Operator::RefTestNonNull { hty: _ } => {
unimplemented!("RefTestNonNull: GC types not supported")
}
wasmparser::Operator::RefTestNullable { hty: _ } => {
unimplemented!("RefTestNullable: GC types not supported")
}
wasmparser::Operator::RefCastNonNull { hty: _ } => {
unimplemented!("RefCastNonNull: GC types not supported")
}
wasmparser::Operator::RefCastNullable { hty: _ } => {
unimplemented!("RefCastNullable: GC types not supported")
}
wasmparser::Operator::BrOnCast {
relative_depth: _,
from_ref_type: _,
to_ref_type: _,
} => unimplemented!("Wasm GC cast not supported"),
wasmparser::Operator::BrOnCastFail {
relative_depth: _,
from_ref_type: _,
to_ref_type: _,
} => unimplemented!("Wasm GC cast not supported"),
wasmparser::Operator::AnyConvertExtern => Instruction::AnyConvertExtern,
wasmparser::Operator::ExternConvertAny => Instruction::ExternConvertAny,
wasmparser::Operator::RefI31 => Instruction::RefI31,
wasmparser::Operator::I31GetS => Instruction::I31GetS,
wasmparser::Operator::I31GetU => Instruction::I31GetU,
wasmparser::Operator::StructNewDesc { struct_type_index } => {
Instruction::StructNewDesc(*struct_type_index)
}
wasmparser::Operator::StructNewDefaultDesc { struct_type_index } => {
Instruction::StructNewDefaultDesc(*struct_type_index)
}
wasmparser::Operator::RefGetDesc { type_index } => {
Instruction::RefGetDesc(rebinder.ty(*type_index))
}
wasmparser::Operator::RefCastDescEqNonNull { hty: _ } => {
unimplemented!("RefCastDescEqNonNull: GC types not supported")
}
wasmparser::Operator::RefCastDescEqNullable { hty: _ } => {
unimplemented!("RefCastDescEqNullable: GC types not supported")
}
wasmparser::Operator::BrOnCastDescEq {
relative_depth: _,
from_ref_type: _,
to_ref_type: _,
} => unimplemented!("BrOnCastDescEq: GC types not supported"),
wasmparser::Operator::BrOnCastDescEqFail {
relative_depth: _,
from_ref_type: _,
to_ref_type: _,
} => unimplemented!("BrOnCastDescEqFail: GC types not supported"),
wasmparser::Operator::I32TruncSatF32S => Instruction::I32TruncSatF32S,
wasmparser::Operator::I32TruncSatF32U => Instruction::I32TruncSatF32U,
wasmparser::Operator::I32TruncSatF64S => Instruction::I32TruncSatF64S,
wasmparser::Operator::I32TruncSatF64U => Instruction::I32TruncSatF64U,
wasmparser::Operator::I64TruncSatF32S => Instruction::I64TruncSatF32S,
wasmparser::Operator::I64TruncSatF32U => Instruction::I64TruncSatF32U,
wasmparser::Operator::I64TruncSatF64S => Instruction::I64TruncSatF64S,
wasmparser::Operator::I64TruncSatF64U => Instruction::I64TruncSatF64U,
wasmparser::Operator::MemoryInit { data_index, mem } => Instruction::MemoryInit {
mem: rebinder.memory(*mem),
data_index: rebinder.data(*data_index),
},
wasmparser::Operator::DataDrop { data_index } => {
Instruction::DataDrop(rebinder.data(*data_index))
}
wasmparser::Operator::MemoryCopy { dst_mem, src_mem } => Instruction::MemoryCopy {
src_mem: rebinder.memory(*src_mem),
dst_mem: rebinder.memory(*dst_mem),
},
wasmparser::Operator::MemoryFill { mem } => Instruction::MemoryFill(rebinder.memory(*mem)),
wasmparser::Operator::TableInit { elem_index, table } => Instruction::TableInit {
table: rebinder.table(*table),
elem_index: rebinder.elem(*elem_index),
},
wasmparser::Operator::ElemDrop { elem_index } => {
Instruction::ElemDrop(rebinder.elem(*elem_index))
}
wasmparser::Operator::TableCopy {
dst_table,
src_table,
} => Instruction::TableCopy {
src_table: rebinder.table(*src_table),
dst_table: rebinder.table(*dst_table),
},
wasmparser::Operator::TypedSelect { ty } => {
Instruction::TypedSelect(translate_val_type(*ty, rebinder))
}
wasmparser::Operator::TypedSelectMulti { tys: _ } => {
unimplemented!("TypedSelectMulti: GC types not supported")
}
wasmparser::Operator::RefNull { hty: _ } => unimplemented!("RefNull not supported"),
wasmparser::Operator::RefIsNull => Instruction::RefIsNull,
wasmparser::Operator::RefFunc { function_index } => {
Instruction::RefFunc(rebinder.function(*function_index))
}
wasmparser::Operator::TableFill { table } => Instruction::TableFill(rebinder.table(*table)),
wasmparser::Operator::TableGet { table } => Instruction::TableGet(rebinder.table(*table)),
wasmparser::Operator::TableSet { table } => Instruction::TableSet(rebinder.table(*table)),
wasmparser::Operator::TableGrow { table } => Instruction::TableGrow(rebinder.table(*table)),
wasmparser::Operator::TableSize { table } => Instruction::TableSize(rebinder.table(*table)),
wasmparser::Operator::ReturnCall { function_index } => {
Instruction::ReturnCall(rebinder.function(*function_index))
}
wasmparser::Operator::ReturnCallIndirect {
type_index,
table_index,
} => Instruction::ReturnCallIndirect {
type_index: rebinder.ty(*type_index),
table_index: rebinder.table(*table_index),
},
wasmparser::Operator::MemoryDiscard { mem } => {
Instruction::MemoryDiscard(rebinder.memory(*mem))
}
wasmparser::Operator::MemoryAtomicNotify { memarg } => {
Instruction::MemoryAtomicNotify(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::MemoryAtomicWait32 { memarg } => {
Instruction::MemoryAtomicWait32(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::MemoryAtomicWait64 { memarg } => {
Instruction::MemoryAtomicWait64(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::AtomicFence => Instruction::AtomicFence,
wasmparser::Operator::I32AtomicLoad { memarg } => {
Instruction::I32AtomicLoad(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicLoad { memarg } => {
Instruction::I64AtomicLoad(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicLoad8U { memarg } => {
Instruction::I32AtomicLoad8U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicLoad16U { memarg } => {
Instruction::I32AtomicLoad16U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicLoad8U { memarg } => {
Instruction::I64AtomicLoad8U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicLoad16U { memarg } => {
Instruction::I64AtomicLoad16U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicLoad32U { memarg } => {
Instruction::I64AtomicLoad32U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicStore { memarg } => {
Instruction::I32AtomicStore(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicStore { memarg } => {
Instruction::I64AtomicStore(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicStore8 { memarg } => {
Instruction::I32AtomicStore8(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicStore16 { memarg } => {
Instruction::I32AtomicStore16(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicStore8 { memarg } => {
Instruction::I64AtomicStore8(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicStore16 { memarg } => {
Instruction::I64AtomicStore16(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicStore32 { memarg } => {
Instruction::I64AtomicStore32(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwAdd { memarg } => {
Instruction::I32AtomicRmwAdd(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwAdd { memarg } => {
Instruction::I64AtomicRmwAdd(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8AddU { memarg } => {
Instruction::I32AtomicRmw8AddU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16AddU { memarg } => {
Instruction::I32AtomicRmw16AddU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8AddU { memarg } => {
Instruction::I64AtomicRmw8AddU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16AddU { memarg } => {
Instruction::I64AtomicRmw16AddU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32AddU { memarg } => {
Instruction::I64AtomicRmw32AddU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwSub { memarg } => {
Instruction::I32AtomicRmwSub(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwSub { memarg } => {
Instruction::I64AtomicRmwSub(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8SubU { memarg } => {
Instruction::I32AtomicRmw8SubU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16SubU { memarg } => {
Instruction::I32AtomicRmw16SubU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8SubU { memarg } => {
Instruction::I64AtomicRmw8SubU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16SubU { memarg } => {
Instruction::I64AtomicRmw16SubU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32SubU { memarg } => {
Instruction::I64AtomicRmw32SubU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwAnd { memarg } => {
Instruction::I32AtomicRmwAnd(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwAnd { memarg } => {
Instruction::I64AtomicRmwAnd(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8AndU { memarg } => {
Instruction::I32AtomicRmw8AndU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16AndU { memarg } => {
Instruction::I32AtomicRmw16AndU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8AndU { memarg } => {
Instruction::I64AtomicRmw8AndU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16AndU { memarg } => {
Instruction::I64AtomicRmw16AndU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32AndU { memarg } => {
Instruction::I64AtomicRmw32AndU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwOr { memarg } => {
Instruction::I32AtomicRmwOr(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwOr { memarg } => {
Instruction::I64AtomicRmwOr(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8OrU { memarg } => {
Instruction::I32AtomicRmw8OrU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16OrU { memarg } => {
Instruction::I32AtomicRmw16OrU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8OrU { memarg } => {
Instruction::I64AtomicRmw8OrU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16OrU { memarg } => {
Instruction::I64AtomicRmw16OrU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32OrU { memarg } => {
Instruction::I64AtomicRmw32OrU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwXor { memarg } => {
Instruction::I32AtomicRmwXor(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwXor { memarg } => {
Instruction::I64AtomicRmwXor(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8XorU { memarg } => {
Instruction::I32AtomicRmw8XorU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16XorU { memarg } => {
Instruction::I32AtomicRmw16XorU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8XorU { memarg } => {
Instruction::I64AtomicRmw8XorU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16XorU { memarg } => {
Instruction::I64AtomicRmw16XorU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32XorU { memarg } => {
Instruction::I64AtomicRmw32XorU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwXchg { memarg } => {
Instruction::I32AtomicRmwXchg(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwXchg { memarg } => {
Instruction::I64AtomicRmwXchg(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8XchgU { memarg } => {
Instruction::I32AtomicRmw8XchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16XchgU { memarg } => {
Instruction::I32AtomicRmw16XchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8XchgU { memarg } => {
Instruction::I64AtomicRmw8XchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16XchgU { memarg } => {
Instruction::I64AtomicRmw16XchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32XchgU { memarg } => {
Instruction::I64AtomicRmw32XchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmwCmpxchg { memarg } => {
Instruction::I32AtomicRmwCmpxchg(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmwCmpxchg { memarg } => {
Instruction::I64AtomicRmwCmpxchg(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw8CmpxchgU { memarg } => {
Instruction::I32AtomicRmw8CmpxchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I32AtomicRmw16CmpxchgU { memarg } => {
Instruction::I32AtomicRmw16CmpxchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw8CmpxchgU { memarg } => {
Instruction::I64AtomicRmw8CmpxchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw16CmpxchgU { memarg } => {
Instruction::I64AtomicRmw16CmpxchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::I64AtomicRmw32CmpxchgU { memarg } => {
Instruction::I64AtomicRmw32CmpxchgU(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load { memarg } => {
Instruction::V128Load(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load8x8S { memarg } => {
Instruction::V128Load8x8S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load8x8U { memarg } => {
Instruction::V128Load8x8U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load16x4S { memarg } => {
Instruction::V128Load16x4S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load16x4U { memarg } => {
Instruction::V128Load16x4U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load32x2S { memarg } => {
Instruction::V128Load32x2S(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load32x2U { memarg } => {
Instruction::V128Load32x2U(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load8Splat { memarg } => {
Instruction::V128Load8Splat(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load16Splat { memarg } => {
Instruction::V128Load16Splat(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load32Splat { memarg } => {
Instruction::V128Load32Splat(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load64Splat { memarg } => {
Instruction::V128Load64Splat(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load32Zero { memarg } => {
Instruction::V128Load32Zero(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load64Zero { memarg } => {
Instruction::V128Load64Zero(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Store { memarg } => {
Instruction::V128Store(translate_memarg(memarg, rebinder))
}
wasmparser::Operator::V128Load8Lane { memarg, lane } => Instruction::V128Load8Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Load16Lane { memarg, lane } => Instruction::V128Load16Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Load32Lane { memarg, lane } => Instruction::V128Load32Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Load64Lane { memarg, lane } => Instruction::V128Load64Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Store8Lane { memarg, lane } => Instruction::V128Store8Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Store16Lane { memarg, lane } => Instruction::V128Store16Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Store32Lane { memarg, lane } => Instruction::V128Store32Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Store64Lane { memarg, lane } => Instruction::V128Store64Lane {
memarg: translate_memarg(memarg, rebinder),
lane: *lane,
},
wasmparser::Operator::V128Const { value } => Instruction::V128Const(value.i128()),
wasmparser::Operator::I8x16Shuffle { lanes } => Instruction::I8x16Shuffle(*lanes),
wasmparser::Operator::I8x16ExtractLaneS { lane } => Instruction::I8x16ExtractLaneS(*lane),
wasmparser::Operator::I8x16ExtractLaneU { lane } => Instruction::I8x16ExtractLaneU(*lane),
wasmparser::Operator::I8x16ReplaceLane { lane } => Instruction::I8x16ReplaceLane(*lane),
wasmparser::Operator::I16x8ExtractLaneS { lane } => Instruction::I16x8ExtractLaneS(*lane),
wasmparser::Operator::I16x8ExtractLaneU { lane } => Instruction::I16x8ExtractLaneU(*lane),
wasmparser::Operator::I16x8ReplaceLane { lane } => Instruction::I16x8ReplaceLane(*lane),
wasmparser::Operator::I32x4ExtractLane { lane } => Instruction::I32x4ExtractLane(*lane),
wasmparser::Operator::I32x4ReplaceLane { lane } => Instruction::I32x4ReplaceLane(*lane),
wasmparser::Operator::I64x2ExtractLane { lane } => Instruction::I64x2ExtractLane(*lane),
wasmparser::Operator::I64x2ReplaceLane { lane } => Instruction::I64x2ReplaceLane(*lane),
wasmparser::Operator::F32x4ExtractLane { lane } => Instruction::F32x4ExtractLane(*lane),
wasmparser::Operator::F32x4ReplaceLane { lane } => Instruction::F32x4ReplaceLane(*lane),
wasmparser::Operator::F64x2ExtractLane { lane } => Instruction::F64x2ExtractLane(*lane),
wasmparser::Operator::F64x2ReplaceLane { lane } => Instruction::F64x2ReplaceLane(*lane),
wasmparser::Operator::I8x16Swizzle => Instruction::I8x16Swizzle,
wasmparser::Operator::I8x16Splat => Instruction::I8x16Splat,
wasmparser::Operator::I16x8Splat => Instruction::I16x8Splat,
wasmparser::Operator::I32x4Splat => Instruction::I32x4Splat,
wasmparser::Operator::I64x2Splat => Instruction::I64x2Splat,
wasmparser::Operator::F32x4Splat => Instruction::F32x4Splat,
wasmparser::Operator::F64x2Splat => Instruction::F64x2Splat,
wasmparser::Operator::I8x16Eq => Instruction::I8x16Eq,
wasmparser::Operator::I8x16Ne => Instruction::I8x16Ne,
wasmparser::Operator::I8x16LtS => Instruction::I8x16LtS,
wasmparser::Operator::I8x16LtU => Instruction::I8x16LtU,
wasmparser::Operator::I8x16GtS => Instruction::I8x16GtS,
wasmparser::Operator::I8x16GtU => Instruction::I8x16GtU,
wasmparser::Operator::I8x16LeS => Instruction::I8x16LeS,
wasmparser::Operator::I8x16LeU => Instruction::I8x16LeU,
wasmparser::Operator::I8x16GeS => Instruction::I8x16GeS,
wasmparser::Operator::I8x16GeU => Instruction::I8x16GeU,
wasmparser::Operator::I16x8Eq => Instruction::I16x8Eq,
wasmparser::Operator::I16x8Ne => Instruction::I16x8Ne,
wasmparser::Operator::I16x8LtS => Instruction::I16x8LtS,
wasmparser::Operator::I16x8LtU => Instruction::I16x8LtU,
wasmparser::Operator::I16x8GtS => Instruction::I16x8GtS,
wasmparser::Operator::I16x8GtU => Instruction::I16x8GtU,
wasmparser::Operator::I16x8LeS => Instruction::I16x8LeS,
wasmparser::Operator::I16x8LeU => Instruction::I16x8LeU,
wasmparser::Operator::I16x8GeS => Instruction::I16x8GeS,
wasmparser::Operator::I16x8GeU => Instruction::I16x8GeU,
wasmparser::Operator::I32x4Eq => Instruction::I32x4Eq,
wasmparser::Operator::I32x4Ne => Instruction::I32x4Ne,
wasmparser::Operator::I32x4LtS => Instruction::I32x4LtS,
wasmparser::Operator::I32x4LtU => Instruction::I32x4LtU,
wasmparser::Operator::I32x4GtS => Instruction::I32x4GtS,
wasmparser::Operator::I32x4GtU => Instruction::I32x4GtU,
wasmparser::Operator::I32x4LeS => Instruction::I32x4LeS,
wasmparser::Operator::I32x4LeU => Instruction::I32x4LeU,
wasmparser::Operator::I32x4GeS => Instruction::I32x4GeS,
wasmparser::Operator::I32x4GeU => Instruction::I32x4GeU,
wasmparser::Operator::I64x2Eq => Instruction::I64x2Eq,
wasmparser::Operator::I64x2Ne => Instruction::I64x2Ne,
wasmparser::Operator::I64x2LtS => Instruction::I64x2LtS,
wasmparser::Operator::I64x2GtS => Instruction::I64x2GtS,
wasmparser::Operator::I64x2LeS => Instruction::I64x2LeS,
wasmparser::Operator::I64x2GeS => Instruction::I64x2GeS,
wasmparser::Operator::F32x4Eq => Instruction::F32x4Eq,
wasmparser::Operator::F32x4Ne => Instruction::F32x4Ne,
wasmparser::Operator::F32x4Lt => Instruction::F32x4Lt,
wasmparser::Operator::F32x4Gt => Instruction::F32x4Gt,
wasmparser::Operator::F32x4Le => Instruction::F32x4Le,
wasmparser::Operator::F32x4Ge => Instruction::F32x4Ge,
wasmparser::Operator::F64x2Eq => Instruction::F64x2Eq,
wasmparser::Operator::F64x2Ne => Instruction::F64x2Ne,
wasmparser::Operator::F64x2Lt => Instruction::F64x2Lt,
wasmparser::Operator::F64x2Gt => Instruction::F64x2Gt,
wasmparser::Operator::F64x2Le => Instruction::F64x2Le,
wasmparser::Operator::F64x2Ge => Instruction::F64x2Ge,
wasmparser::Operator::V128Not => Instruction::V128Not,
wasmparser::Operator::V128And => Instruction::V128And,
wasmparser::Operator::V128AndNot => Instruction::V128AndNot,
wasmparser::Operator::V128Or => Instruction::V128Or,
wasmparser::Operator::V128Xor => Instruction::V128Xor,
wasmparser::Operator::V128Bitselect => Instruction::V128Bitselect,
wasmparser::Operator::V128AnyTrue => Instruction::V128AnyTrue,
wasmparser::Operator::I8x16Abs => Instruction::I8x16Abs,
wasmparser::Operator::I8x16Neg => Instruction::I8x16Neg,
wasmparser::Operator::I8x16Popcnt => Instruction::I8x16Popcnt,
wasmparser::Operator::I8x16AllTrue => Instruction::I8x16AllTrue,
wasmparser::Operator::I8x16Bitmask => Instruction::I8x16Bitmask,
wasmparser::Operator::I8x16NarrowI16x8S => Instruction::I8x16NarrowI16x8S,
wasmparser::Operator::I8x16NarrowI16x8U => Instruction::I8x16NarrowI16x8U,
wasmparser::Operator::I8x16Shl => Instruction::I8x16Shl,
wasmparser::Operator::I8x16ShrS => Instruction::I8x16ShrS,
wasmparser::Operator::I8x16ShrU => Instruction::I8x16ShrU,
wasmparser::Operator::I8x16Add => Instruction::I8x16Add,
wasmparser::Operator::I8x16AddSatS => Instruction::I8x16AddSatS,
wasmparser::Operator::I8x16AddSatU => Instruction::I8x16AddSatU,
wasmparser::Operator::I8x16Sub => Instruction::I8x16Sub,
wasmparser::Operator::I8x16SubSatS => Instruction::I8x16SubSatS,
wasmparser::Operator::I8x16SubSatU => Instruction::I8x16SubSatU,
wasmparser::Operator::I8x16MinS => Instruction::I8x16MinS,
wasmparser::Operator::I8x16MinU => Instruction::I8x16MinU,
wasmparser::Operator::I8x16MaxS => Instruction::I8x16MaxS,
wasmparser::Operator::I8x16MaxU => Instruction::I8x16MaxU,
wasmparser::Operator::I8x16AvgrU => Instruction::I8x16AvgrU,
wasmparser::Operator::I16x8ExtAddPairwiseI8x16S => Instruction::I16x8ExtAddPairwiseI8x16S,
wasmparser::Operator::I16x8ExtAddPairwiseI8x16U => Instruction::I16x8ExtAddPairwiseI8x16U,
wasmparser::Operator::I16x8Abs => Instruction::I16x8Abs,
wasmparser::Operator::I16x8Neg => Instruction::I16x8Neg,
wasmparser::Operator::I16x8Q15MulrSatS => Instruction::I16x8Q15MulrSatS,
wasmparser::Operator::I16x8AllTrue => Instruction::I16x8AllTrue,
wasmparser::Operator::I16x8Bitmask => Instruction::I16x8Bitmask,
wasmparser::Operator::I16x8NarrowI32x4S => Instruction::I16x8NarrowI32x4S,
wasmparser::Operator::I16x8NarrowI32x4U => Instruction::I16x8NarrowI32x4U,
wasmparser::Operator::I16x8ExtendLowI8x16S => Instruction::I16x8ExtendLowI8x16S,
wasmparser::Operator::I16x8ExtendHighI8x16S => Instruction::I16x8ExtendHighI8x16S,
wasmparser::Operator::I16x8ExtendLowI8x16U => Instruction::I16x8ExtendLowI8x16U,
wasmparser::Operator::I16x8ExtendHighI8x16U => Instruction::I16x8ExtendHighI8x16U,
wasmparser::Operator::I16x8Shl => Instruction::I16x8Shl,
wasmparser::Operator::I16x8ShrS => Instruction::I16x8ShrS,
wasmparser::Operator::I16x8ShrU => Instruction::I16x8ShrU,
wasmparser::Operator::I16x8Add => Instruction::I16x8Add,
wasmparser::Operator::I16x8AddSatS => Instruction::I16x8AddSatS,
wasmparser::Operator::I16x8AddSatU => Instruction::I16x8AddSatU,
wasmparser::Operator::I16x8Sub => Instruction::I16x8Sub,
wasmparser::Operator::I16x8SubSatS => Instruction::I16x8SubSatS,
wasmparser::Operator::I16x8SubSatU => Instruction::I16x8SubSatU,
wasmparser::Operator::I16x8Mul => Instruction::I16x8Mul,
wasmparser::Operator::I16x8MinS => Instruction::I16x8MinS,
wasmparser::Operator::I16x8MinU => Instruction::I16x8MinU,
wasmparser::Operator::I16x8MaxS => Instruction::I16x8MaxS,
wasmparser::Operator::I16x8MaxU => Instruction::I16x8MaxU,
wasmparser::Operator::I16x8AvgrU => Instruction::I16x8AvgrU,
wasmparser::Operator::I16x8ExtMulLowI8x16S => Instruction::I16x8ExtMulLowI8x16S,
wasmparser::Operator::I16x8ExtMulHighI8x16S => Instruction::I16x8ExtMulHighI8x16S,
wasmparser::Operator::I16x8ExtMulLowI8x16U => Instruction::I16x8ExtMulLowI8x16U,
wasmparser::Operator::I16x8ExtMulHighI8x16U => Instruction::I16x8ExtMulHighI8x16U,
wasmparser::Operator::I32x4ExtAddPairwiseI16x8S => Instruction::I32x4ExtAddPairwiseI16x8S,
wasmparser::Operator::I32x4ExtAddPairwiseI16x8U => Instruction::I32x4ExtAddPairwiseI16x8U,
wasmparser::Operator::I32x4Abs => Instruction::I32x4Abs,
wasmparser::Operator::I32x4Neg => Instruction::I32x4Neg,
wasmparser::Operator::I32x4AllTrue => Instruction::I32x4AllTrue,
wasmparser::Operator::I32x4Bitmask => Instruction::I32x4Bitmask,
wasmparser::Operator::I32x4ExtendLowI16x8S => Instruction::I32x4ExtendLowI16x8S,
wasmparser::Operator::I32x4ExtendHighI16x8S => Instruction::I32x4ExtendHighI16x8S,
wasmparser::Operator::I32x4ExtendLowI16x8U => Instruction::I32x4ExtendLowI16x8U,
wasmparser::Operator::I32x4ExtendHighI16x8U => Instruction::I32x4ExtendHighI16x8U,
wasmparser::Operator::I32x4Shl => Instruction::I32x4Shl,
wasmparser::Operator::I32x4ShrS => Instruction::I32x4ShrS,
wasmparser::Operator::I32x4ShrU => Instruction::I32x4ShrU,
wasmparser::Operator::I32x4Add => Instruction::I32x4Add,
wasmparser::Operator::I32x4Sub => Instruction::I32x4Sub,
wasmparser::Operator::I32x4Mul => Instruction::I32x4Mul,
wasmparser::Operator::I32x4MinS => Instruction::I32x4MinS,
wasmparser::Operator::I32x4MinU => Instruction::I32x4MinU,
wasmparser::Operator::I32x4MaxS => Instruction::I32x4MaxS,
wasmparser::Operator::I32x4MaxU => Instruction::I32x4MaxU,
wasmparser::Operator::I32x4DotI16x8S => Instruction::I32x4DotI16x8S,
wasmparser::Operator::I32x4ExtMulLowI16x8S => Instruction::I32x4ExtMulLowI16x8S,
wasmparser::Operator::I32x4ExtMulHighI16x8S => Instruction::I32x4ExtMulHighI16x8S,
wasmparser::Operator::I32x4ExtMulLowI16x8U => Instruction::I32x4ExtMulLowI16x8U,
wasmparser::Operator::I32x4ExtMulHighI16x8U => Instruction::I32x4ExtMulHighI16x8U,
wasmparser::Operator::I64x2Abs => Instruction::I64x2Abs,
wasmparser::Operator::I64x2Neg => Instruction::I64x2Neg,
wasmparser::Operator::I64x2AllTrue => Instruction::I64x2AllTrue,
wasmparser::Operator::I64x2Bitmask => Instruction::I64x2Bitmask,
wasmparser::Operator::I64x2ExtendLowI32x4S => Instruction::I64x2ExtendLowI32x4S,
wasmparser::Operator::I64x2ExtendHighI32x4S => Instruction::I64x2ExtendHighI32x4S,
wasmparser::Operator::I64x2ExtendLowI32x4U => Instruction::I64x2ExtendLowI32x4U,
wasmparser::Operator::I64x2ExtendHighI32x4U => Instruction::I64x2ExtendHighI32x4U,
wasmparser::Operator::I64x2Shl => Instruction::I64x2Shl,
wasmparser::Operator::I64x2ShrS => Instruction::I64x2ShrS,
wasmparser::Operator::I64x2ShrU => Instruction::I64x2ShrU,
wasmparser::Operator::I64x2Add => Instruction::I64x2Add,
wasmparser::Operator::I64x2Sub => Instruction::I64x2Sub,
wasmparser::Operator::I64x2Mul => Instruction::I64x2Mul,
wasmparser::Operator::I64x2ExtMulLowI32x4S => Instruction::I64x2ExtMulLowI32x4S,
wasmparser::Operator::I64x2ExtMulHighI32x4S => Instruction::I64x2ExtMulHighI32x4S,
wasmparser::Operator::I64x2ExtMulLowI32x4U => Instruction::I64x2ExtMulLowI32x4U,
wasmparser::Operator::I64x2ExtMulHighI32x4U => Instruction::I64x2ExtMulHighI32x4U,
wasmparser::Operator::F32x4Ceil => Instruction::F32x4Ceil,
wasmparser::Operator::F32x4Floor => Instruction::F32x4Floor,
wasmparser::Operator::F32x4Trunc => Instruction::F32x4Trunc,
wasmparser::Operator::F32x4Nearest => Instruction::F32x4Nearest,
wasmparser::Operator::F32x4Abs => Instruction::F32x4Abs,
wasmparser::Operator::F32x4Neg => Instruction::F32x4Neg,
wasmparser::Operator::F32x4Sqrt => Instruction::F32x4Sqrt,
wasmparser::Operator::F32x4Add => Instruction::F32x4Add,
wasmparser::Operator::F32x4Sub => Instruction::F32x4Sub,
wasmparser::Operator::F32x4Mul => Instruction::F32x4Mul,
wasmparser::Operator::F32x4Div => Instruction::F32x4Div,
wasmparser::Operator::F32x4Min => Instruction::F32x4Min,
wasmparser::Operator::F32x4Max => Instruction::F32x4Max,
wasmparser::Operator::F32x4PMin => Instruction::F32x4PMin,
wasmparser::Operator::F32x4PMax => Instruction::F32x4PMax,
wasmparser::Operator::F64x2Ceil => Instruction::F64x2Ceil,
wasmparser::Operator::F64x2Floor => Instruction::F64x2Floor,
wasmparser::Operator::F64x2Trunc => Instruction::F64x2Trunc,
wasmparser::Operator::F64x2Nearest => Instruction::F64x2Nearest,
wasmparser::Operator::F64x2Abs => Instruction::F64x2Abs,
wasmparser::Operator::F64x2Neg => Instruction::F64x2Neg,
wasmparser::Operator::F64x2Sqrt => Instruction::F64x2Sqrt,
wasmparser::Operator::F64x2Add => Instruction::F64x2Add,
wasmparser::Operator::F64x2Sub => Instruction::F64x2Sub,
wasmparser::Operator::F64x2Mul => Instruction::F64x2Mul,
wasmparser::Operator::F64x2Div => Instruction::F64x2Div,
wasmparser::Operator::F64x2Min => Instruction::F64x2Min,
wasmparser::Operator::F64x2Max => Instruction::F64x2Max,
wasmparser::Operator::F64x2PMin => Instruction::F64x2PMin,
wasmparser::Operator::F64x2PMax => Instruction::F64x2PMax,
wasmparser::Operator::I32x4TruncSatF32x4S => Instruction::I32x4TruncSatF32x4S,
wasmparser::Operator::I32x4TruncSatF32x4U => Instruction::I32x4TruncSatF32x4U,
wasmparser::Operator::F32x4ConvertI32x4S => Instruction::F32x4ConvertI32x4S,
wasmparser::Operator::F32x4ConvertI32x4U => Instruction::F32x4ConvertI32x4U,
wasmparser::Operator::I32x4TruncSatF64x2SZero => Instruction::I32x4TruncSatF64x2SZero,
wasmparser::Operator::I32x4TruncSatF64x2UZero => Instruction::I32x4TruncSatF64x2UZero,
wasmparser::Operator::F64x2ConvertLowI32x4S => Instruction::F64x2ConvertLowI32x4S,
wasmparser::Operator::F64x2ConvertLowI32x4U => Instruction::F64x2ConvertLowI32x4U,
wasmparser::Operator::F32x4DemoteF64x2Zero => Instruction::F32x4DemoteF64x2Zero,
wasmparser::Operator::F64x2PromoteLowF32x4 => Instruction::F64x2PromoteLowF32x4,
wasmparser::Operator::I8x16RelaxedSwizzle => Instruction::I8x16RelaxedSwizzle,
wasmparser::Operator::I32x4RelaxedTruncF32x4S => Instruction::I32x4RelaxedTruncF32x4S,
wasmparser::Operator::I32x4RelaxedTruncF32x4U => Instruction::I32x4RelaxedTruncF32x4U,
wasmparser::Operator::I32x4RelaxedTruncF64x2SZero => {
Instruction::I32x4RelaxedTruncF64x2SZero
}
wasmparser::Operator::I32x4RelaxedTruncF64x2UZero => {
Instruction::I32x4RelaxedTruncF64x2UZero
}
wasmparser::Operator::F32x4RelaxedMadd => Instruction::F32x4RelaxedMadd,
wasmparser::Operator::F32x4RelaxedNmadd => Instruction::F32x4RelaxedNmadd,
wasmparser::Operator::F64x2RelaxedMadd => Instruction::F64x2RelaxedMadd,
wasmparser::Operator::F64x2RelaxedNmadd => Instruction::F64x2RelaxedNmadd,
wasmparser::Operator::I8x16RelaxedLaneselect => Instruction::I8x16RelaxedLaneselect,
wasmparser::Operator::I16x8RelaxedLaneselect => Instruction::I16x8RelaxedLaneselect,
wasmparser::Operator::I32x4RelaxedLaneselect => Instruction::I32x4RelaxedLaneselect,
wasmparser::Operator::I64x2RelaxedLaneselect => Instruction::I64x2RelaxedLaneselect,
wasmparser::Operator::F32x4RelaxedMin => Instruction::F32x4RelaxedMin,
wasmparser::Operator::F32x4RelaxedMax => Instruction::F32x4RelaxedMax,
wasmparser::Operator::F64x2RelaxedMin => Instruction::F64x2RelaxedMin,
wasmparser::Operator::F64x2RelaxedMax => Instruction::F64x2RelaxedMax,
wasmparser::Operator::I16x8RelaxedQ15mulrS => Instruction::I16x8RelaxedQ15mulrS,
wasmparser::Operator::I16x8RelaxedDotI8x16I7x16S => Instruction::I16x8RelaxedDotI8x16I7x16S,
wasmparser::Operator::I32x4RelaxedDotI8x16I7x16AddS => {
Instruction::I32x4RelaxedDotI8x16I7x16AddS
}
wasmparser::Operator::TryTable { try_table } => Instruction::TryTable(
translate_block_type(try_table.ty, rebinder),
std::borrow::Cow::Owned(
try_table
.catches
.iter()
.map(|c| translate_catch(c, rebinder))
.collect(),
),
),
wasmparser::Operator::Throw { tag_index } => Instruction::Throw(rebinder.tag(*tag_index)),
wasmparser::Operator::ThrowRef => Instruction::ThrowRef,
wasmparser::Operator::Try { blockty } => {
Instruction::Try(translate_block_type(*blockty, rebinder))
}
wasmparser::Operator::Catch { tag_index } => Instruction::Catch(rebinder.tag(*tag_index)),
wasmparser::Operator::Rethrow { relative_depth } => Instruction::Rethrow(*relative_depth),
wasmparser::Operator::Delegate { relative_depth } => Instruction::Delegate(*relative_depth),
wasmparser::Operator::CatchAll => Instruction::CatchAll,
wasmparser::Operator::GlobalAtomicGet {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicGet"),
wasmparser::Operator::GlobalAtomicSet {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicSet"),
wasmparser::Operator::GlobalAtomicRmwAdd {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwAdd"),
wasmparser::Operator::GlobalAtomicRmwSub {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwSub"),
wasmparser::Operator::GlobalAtomicRmwAnd {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwAnd"),
wasmparser::Operator::GlobalAtomicRmwOr {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwOr"),
wasmparser::Operator::GlobalAtomicRmwXor {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwXor"),
wasmparser::Operator::GlobalAtomicRmwXchg {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwXchg"),
wasmparser::Operator::GlobalAtomicRmwCmpxchg {
ordering: _,
global_index: _,
} => unimplemented!("GlobalAtomicRmwCmpxchg"),
wasmparser::Operator::TableAtomicGet {
ordering: _,
table_index: _,
} => unimplemented!("TableAtomicGet"),
wasmparser::Operator::TableAtomicSet {
ordering: _,
table_index: _,
} => unimplemented!("TableAtomicSet"),
wasmparser::Operator::TableAtomicRmwXchg {
ordering: _,
table_index: _,
} => unimplemented!("TableAtomicRmwXchg"),
wasmparser::Operator::TableAtomicRmwCmpxchg {
ordering: _,
table_index: _,
} => unimplemented!("TableAtomicRmwCmpxchg"),
wasmparser::Operator::StructAtomicGet {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicGet"),
wasmparser::Operator::StructAtomicGetS {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicGetS"),
wasmparser::Operator::StructAtomicGetU {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicGetU"),
wasmparser::Operator::StructAtomicSet {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicSet"),
wasmparser::Operator::StructAtomicRmwAdd {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwAdd"),
wasmparser::Operator::StructAtomicRmwSub {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwSub"),
wasmparser::Operator::StructAtomicRmwAnd {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwAnd"),
wasmparser::Operator::StructAtomicRmwOr {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwOr"),
wasmparser::Operator::StructAtomicRmwXor {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwXor"),
wasmparser::Operator::StructAtomicRmwXchg {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwXchg"),
wasmparser::Operator::StructAtomicRmwCmpxchg {
ordering: _,
struct_type_index: _,
field_index: _,
} => unimplemented!("StructAtomicRmwCmpxchg"),
wasmparser::Operator::ArrayAtomicGet {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicGet"),
wasmparser::Operator::ArrayAtomicGetS {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicGetS"),
wasmparser::Operator::ArrayAtomicGetU {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicGetU"),
wasmparser::Operator::ArrayAtomicSet {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicSet"),
wasmparser::Operator::ArrayAtomicRmwAdd {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwAdd"),
wasmparser::Operator::ArrayAtomicRmwSub {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwSub"),
wasmparser::Operator::ArrayAtomicRmwAnd {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwAnd"),
wasmparser::Operator::ArrayAtomicRmwOr {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwOr"),
wasmparser::Operator::ArrayAtomicRmwXor {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwXor"),
wasmparser::Operator::ArrayAtomicRmwXchg {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwXchg"),
wasmparser::Operator::ArrayAtomicRmwCmpxchg {
ordering: _,
array_type_index: _,
} => unimplemented!("ArrayAtomicRmwCmpxchg"),
wasmparser::Operator::RefI31Shared => unimplemented!("RefI31Shared"),
wasmparser::Operator::CallRef { type_index } => {
Instruction::CallRef(rebinder.ty(*type_index))
}
wasmparser::Operator::ReturnCallRef { type_index } => {
Instruction::ReturnCallRef(rebinder.ty(*type_index))
}
wasmparser::Operator::RefAsNonNull => unimplemented!("RefAsNonNull"),
wasmparser::Operator::BrOnNull { relative_depth } => Instruction::BrOnNull(*relative_depth),
wasmparser::Operator::BrOnNonNull { relative_depth } => {
Instruction::BrOnNonNull(*relative_depth)
}
wasmparser::Operator::ContNew { cont_type_index: _ } => unimplemented!("ContNew"),
wasmparser::Operator::ContBind {
argument_index: _,
result_index: _,
} => unimplemented!("ContBind"),
wasmparser::Operator::Suspend { tag_index: _ } => unimplemented!("Suspend"),
wasmparser::Operator::Resume {
cont_type_index: _,
resume_table: _,
} => unimplemented!("Resume"),
wasmparser::Operator::ResumeThrow {
cont_type_index: _,
tag_index: _,
resume_table: _,
} => unimplemented!("ResumeThrow"),
wasmparser::Operator::ResumeThrowRef {
cont_type_index: _,
resume_table: _,
} => unimplemented!("ResumeThrowRef"),
wasmparser::Operator::Switch {
cont_type_index: _,
tag_index: _,
} => unimplemented!("Switch"),
wasmparser::Operator::I64Add128 => unimplemented!("I64Add128"),
wasmparser::Operator::I64Sub128 => unimplemented!("I64Sub128"),
wasmparser::Operator::I64MulWideS => unimplemented!("I64MulWideS"),
wasmparser::Operator::I64MulWideU => unimplemented!("I64MulWideU"),
_ => unimplemented!("unsupported wasmparser operator"),
}
}
pub fn translate_val_type<R: Rebind>(
ty: wasmparser::ValType,
rebinder: &R,
) -> wasm_encoder::ValType {
match ty {
wasmparser::ValType::I32 => wasm_encoder::ValType::I32,
wasmparser::ValType::I64 => wasm_encoder::ValType::I64,
wasmparser::ValType::F32 => wasm_encoder::ValType::F32,
wasmparser::ValType::F64 => wasm_encoder::ValType::F64,
wasmparser::ValType::V128 => wasm_encoder::ValType::V128,
wasmparser::ValType::Ref(r) => wasm_encoder::ValType::Ref(translate_ref_type(r, rebinder)),
}
}
pub fn translate_block_type<R: Rebind>(
bty: wasmparser::BlockType,
rebinder: &R,
) -> wasm_encoder::BlockType {
match bty {
wasmparser::BlockType::Empty => wasm_encoder::BlockType::Empty,
wasmparser::BlockType::Type(ty) => {
wasm_encoder::BlockType::Result(translate_val_type(ty, rebinder))
}
wasmparser::BlockType::FuncType(idx) => {
wasm_encoder::BlockType::FunctionType(rebinder.ty(idx))
}
}
}
pub fn translate_catch<R: Rebind>(catch: &wasmparser::Catch, rebinder: &R) -> wasm_encoder::Catch {
match catch {
wasmparser::Catch::One { tag, label } => wasm_encoder::Catch::One {
tag: rebinder.tag(*tag),
label: *label,
},
wasmparser::Catch::OneRef { tag, label } => wasm_encoder::Catch::OneRef {
tag: rebinder.tag(*tag),
label: *label,
},
wasmparser::Catch::All { label } => wasm_encoder::Catch::All { label: *label },
wasmparser::Catch::AllRef { label } => wasm_encoder::Catch::AllRef { label: *label },
}
}
pub fn translate_memarg<R: Rebind>(
memarg: &wasmparser::MemArg,
rebinder: &R,
) -> wasm_encoder::MemArg {
wasm_encoder::MemArg {
offset: memarg.offset,
align: memarg.align.into(),
memory_index: rebinder.memory(memarg.memory),
}
}
pub fn translate_const_expr<R: Rebind>(
expr: &wasmparser::ConstExpr,
rebinder: &R,
) -> Result<wasm_encoder::ConstExpr> {
let mut reader = expr.get_operators_reader();
let op = reader.read()?;
match op {
wasmparser::Operator::I32Const { value } => Ok(wasm_encoder::ConstExpr::i32_const(value)),
wasmparser::Operator::I64Const { value } => Ok(wasm_encoder::ConstExpr::i64_const(value)),
wasmparser::Operator::F32Const { value } => Ok(wasm_encoder::ConstExpr::f32_const(
f32::from_bits(value.bits()).into(),
)),
wasmparser::Operator::F64Const { value } => Ok(wasm_encoder::ConstExpr::f64_const(
f64::from_bits(value.bits()).into(),
)),
wasmparser::Operator::GlobalGet { global_index } => Ok(
wasm_encoder::ConstExpr::global_get(rebinder.global(global_index)),
),
wasmparser::Operator::RefNull { .. } => unimplemented!("RefNull not supported"),
wasmparser::Operator::RefFunc { function_index } => Ok(wasm_encoder::ConstExpr::ref_func(
rebinder.function(function_index),
)),
_ => eyre::bail!("Unsupported const expr operator: {:?}", op),
}
}