Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simd_visitor helper methods to FuncValidator #1927

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/wasmparser/src/validator/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ impl<T: WasmModuleResources> FuncValidator<T> {
self.validator.with_resources(&self.resources, offset)
}

/// Same as [`FuncValidator::visit`] except that the returned type
/// implements the [`VisitSimdOperator`](crate::VisitSimdOperator) trait as
/// well.
#[cfg(feature = "simd")]
pub fn simd_visitor<'this, 'a: 'this>(
&'this mut self,
offset: usize,
) -> impl crate::VisitSimdOperator<'a, Output = Result<()>> + ModuleArity + 'this {
self.validator.with_resources_simd(&self.resources, offset)
}

/// Function that must be called after the last opcode has been processed.
///
/// This will validate that the function was properly terminated with the
Expand Down
19 changes: 19 additions & 0 deletions crates/wasmparser/src/validator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,25 @@ impl OperatorValidator {
})
}

/// Same as `with_resources` above but guarantees it's able to visit simd
/// operators as well.
#[cfg(feature = "simd")]
pub fn with_resources_simd<'a, 'validator, 'resources, T>(
&'validator mut self,
resources: &'resources T,
offset: usize,
) -> impl VisitSimdOperator<'a, Output = Result<()>> + ModuleArity + 'validator
where
T: WasmModuleResources,
'resources: 'validator,
{
WasmProposalValidator(OperatorValidatorTemp {
offset,
inner: self,
resources,
})
}

pub fn finish(&mut self, offset: usize) -> Result<()> {
if self.control.last().is_some() {
bail!(
Expand Down
Loading