Support RefIsNull operator.

This commit is contained in:
Chris Fallin 2024-04-02 13:20:28 -07:00
parent fbb0a34a25
commit 4eaf0ced01
4 changed files with 8 additions and 0 deletions

View file

@ -913,6 +913,7 @@ impl<'a> WasmFuncBackend<'a> {
Operator::CallRef { sig_index } => {
Some(wasm_encoder::Instruction::CallRef(sig_index.index() as u32))
}
Operator::RefIsNull => Some(wasm_encoder::Instruction::RefIsNull),
Operator::RefFunc { func_index } => {
Some(wasm_encoder::Instruction::RefFunc(func_index.index() as u32))
}

View file

@ -1420,6 +1420,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
| wasmparser::Operator::F32x4DemoteF64x2Zero
| wasmparser::Operator::F64x2PromoteLowF32x4
| wasmparser::Operator::CallRef { .. }
| wasmparser::Operator::RefIsNull
| wasmparser::Operator::RefFunc { .. } => {
self.emit(Operator::try_from(&op).unwrap(), loc)?
}

View file

@ -482,6 +482,7 @@ pub fn op_inputs(
params.push(Type::TypedFuncRef(true, sig_index.index() as u32));
Ok(params.into())
}
Operator::RefIsNull => Ok(vec![op_stack.last().unwrap().0].into()),
Operator::RefFunc { .. } => Ok(Cow::Borrowed(&[])),
}
}
@ -945,6 +946,7 @@ pub fn op_outputs(
Operator::CallRef { sig_index } => {
Ok(Vec::from(module.signatures[*sig_index].returns.clone()).into())
}
Operator::RefIsNull => Ok(Cow::Borrowed(&[Type::I32])),
Operator::RefFunc { func_index } => {
let ty = module.funcs[*func_index].sig();
Ok(vec![Type::TypedFuncRef(true, ty.index() as u32)].into())
@ -1415,6 +1417,7 @@ impl Operator {
Operator::F64x2PromoteLowF32x4 => &[],
Operator::CallRef { .. } => &[All],
Operator::RefIsNull => &[],
Operator::RefFunc { .. } => &[],
}
}
@ -1906,6 +1909,7 @@ impl std::fmt::Display for Operator {
Operator::F64x2PromoteLowF32x4 => write!(f, "f64x2promotelowf32x4")?,
Operator::CallRef { sig_index } => write!(f, "call_ref<{}>", sig_index)?,
Operator::RefIsNull => write!(f, "ref_is_null")?,
Operator::RefFunc { func_index } => write!(f, "ref_func<{}>", func_index)?,
}

View file

@ -634,6 +634,7 @@ pub enum Operator {
CallRef {
sig_index: Signature,
},
RefIsNull,
RefFunc {
func_index: Func,
},
@ -1269,6 +1270,7 @@ impl<'a, 'b> std::convert::TryFrom<&'b wasmparser::Operator<'a>> for Operator {
&wasmparser::Operator::CallRef { type_index } => Ok(Operator::CallRef {
sig_index: Signature::from(type_index),
}),
&wasmparser::Operator::RefIsNull => Ok(Operator::RefIsNull),
&wasmparser::Operator::RefFunc { function_index } => Ok(Operator::RefFunc {
func_index: Func::from(function_index),
}),