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

@@ -34,7 +34,7 @@ impl TargetIsa for Aarch64 {
fn compile_function(
&self,
_sig: &FuncType,
mut _body: FunctionBody,
_body: &FunctionBody,
mut _validator: FuncValidator<ValidatorResources>,
) -> Result<Vec<String>> {
todo!()

View File

@@ -85,7 +85,7 @@ pub trait TargetIsa: Send + Sync {
fn compile_function(
&self,
sig: &FuncType,
body: FunctionBody,
body: &FunctionBody,
validator: FuncValidator<ValidatorResources>,
) -> Result<Vec<String>>;

View File

@@ -47,9 +47,10 @@ impl TargetIsa for X64 {
fn compile_function(
&self,
sig: &FuncType,
mut body: FunctionBody,
body: &FunctionBody,
mut validator: FuncValidator<ValidatorResources>,
) -> Result<Vec<String>> {
let mut body = body.get_binary_reader();
let masm = MacroAssembler::new();
let stack = Stack::new();
let abi = abi::X64ABI::default();
@@ -58,9 +59,8 @@ impl TargetIsa for X64 {
// TODO Add in floating point bitmask
let regalloc = RegAlloc::new(RegSet::new(ALL_GPR, 0), regs::scratch());
let codegen_context = CodeGenContext::new(masm, stack, &frame);
let mut codegen =
CodeGen::new::<abi::X64ABI>(codegen_context, abi_sig, body, validator, regalloc);
let mut codegen = CodeGen::new::<abi::X64ABI>(codegen_context, abi_sig, regalloc);
codegen.emit()
codegen.emit(&mut body, validator)
}
}