winch: Prepare for an update to the wasm-tools crates (#5238)

This commit prepares the `winch` crate for updating `wasm-tools`,
notably changing a bit about how the visitation of operators works. This
moves the function body and wasm validator out of the `CodeGen`
structure and into parameters threaded into the emission of the actual
function.

Additionally the `VisitOperator` implementation was updated to remove
the explicit calls to the validator, favoring instead a macro-generated
solution to guarantee that all validation happens before any translation
proceeds. This means that the `VisitOperator for CodeGen` impl is now
infallible and the various methods have been inlined into the trait
methods as well as removing the `Result<_>`.

Finally this commit updates translation to call `validator.finish(..)`
which is required to perform the final validation steps of the function
body.
This commit is contained in:
Alex Crichton
2022-11-10 14:01:42 -06:00
committed by GitHub
parent 1f09954fa4
commit 3b9668558f
7 changed files with 91 additions and 105 deletions

View File

@@ -2,7 +2,7 @@ use crate::abi::{align_to, local::LocalSlot, ty_size, ABIArg, ABISig, ABI};
use anyhow::Result;
use smallvec::SmallVec;
use std::ops::Range;
use wasmparser::{FuncValidator, FunctionBody, ValType, ValidatorResources};
use wasmparser::{BinaryReader, FuncValidator, ValType, ValidatorResources};
// TODO:
// SpiderMonkey's implementation uses 16;
@@ -39,13 +39,13 @@ impl Frame {
/// Allocate a new Frame.
pub fn new<A: ABI>(
sig: &ABISig,
function: &mut FunctionBody,
body: &mut BinaryReader<'_>,
validator: &mut FuncValidator<ValidatorResources>,
abi: &A,
) -> Result<Self> {
let (mut locals, defined_locals_start) = Self::compute_arg_slots(sig, abi)?;
let (defined_slots, defined_locals_end) =
Self::compute_defined_slots(function, validator, defined_locals_start)?;
Self::compute_defined_slots(body, validator, defined_locals_start)?;
locals.extend(defined_slots);
let locals_size = align_to(defined_locals_end, abi.stack_align().into());
@@ -117,12 +117,11 @@ impl Frame {
}
fn compute_defined_slots(
body_data: &mut FunctionBody,
reader: &mut BinaryReader<'_>,
validator: &mut FuncValidator<ValidatorResources>,
next_stack: u32,
) -> Result<(Locals, u32)> {
let mut next_stack = next_stack;
let mut reader = body_data.get_binary_reader();
let local_count = reader.read_var_u32()?;
let mut slots: Locals = Default::default();