winch: Introduce winch-environ (#6017)
This commit introduces the `winch-environ` crate. This crate's responsibility is to provide a shared implementatation of the `winch_codegen::FuncEnv` trait, which is Winch's function compilation environment, used to resolve module and runtime specific information needed by the code generation, such as resolving all the details about a callee in a WebAssembly module, or resolving specific information from the `VMContext`. As of this change, the implementation only includes the necessary pieces to resolve a function callee in a WebAssembly module. The idea is to evolve the `winch_codegen::FuncEnv` trait as we evolve Winch's code generation.
This commit is contained in:
@@ -12,6 +12,7 @@ edition.workspace = true
|
||||
winch-test-macros = {workspace = true}
|
||||
target-lexicon = { workspace = true }
|
||||
winch-codegen = { workspace = true, features = ['all-arch'] }
|
||||
winch-environ = { workspace = true }
|
||||
wasmtime-environ = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
wat = { workspace = true }
|
||||
|
||||
@@ -10,11 +10,11 @@ mod test {
|
||||
use std::str::FromStr;
|
||||
use target_lexicon::Triple;
|
||||
use wasmtime_environ::{
|
||||
wasmparser::{types::Types, Parser as WasmParser, Validator},
|
||||
DefinedFuncIndex, FunctionBodyData, Module, ModuleEnvironment, Tunables,
|
||||
wasmparser::{Parser as WasmParser, Validator},
|
||||
DefinedFuncIndex, FunctionBodyData, ModuleEnvironment, Tunables,
|
||||
};
|
||||
use winch_codegen::isa::TargetIsa;
|
||||
use winch_codegen::lookup;
|
||||
use winch_environ::FuncEnv;
|
||||
use winch_test_macros::generate_file_tests;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@@ -109,10 +109,11 @@ mod test {
|
||||
let body_inputs = std::mem::take(&mut translation.function_body_inputs);
|
||||
let module = &translation.module;
|
||||
let types = translation.get_types();
|
||||
let env = FuncEnv::new(module, &types, &*isa);
|
||||
|
||||
let binding = body_inputs
|
||||
.into_iter()
|
||||
.map(|func| compile(&*isa, module, types, func).join("\n"))
|
||||
.map(|func| compile(&env, func).join("\n"))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n\n");
|
||||
let actual = binding.as_str();
|
||||
@@ -143,23 +144,20 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
fn compile(
|
||||
isa: &dyn TargetIsa,
|
||||
module: &Module,
|
||||
types: &Types,
|
||||
f: (DefinedFuncIndex, FunctionBodyData<'_>),
|
||||
) -> Vec<String> {
|
||||
let index = module.func_index(f.0);
|
||||
let sig = types
|
||||
fn compile(env: &FuncEnv, f: (DefinedFuncIndex, FunctionBodyData<'_>)) -> Vec<String> {
|
||||
let index = env.module.func_index(f.0);
|
||||
let sig = env
|
||||
.types
|
||||
.function_at(index.as_u32())
|
||||
.expect(&format!("function type at index {:?}", index.as_u32()));
|
||||
let FunctionBodyData { body, validator } = f.1;
|
||||
let validator = validator.into_validator(Default::default());
|
||||
|
||||
let buffer = isa
|
||||
let buffer = env
|
||||
.isa
|
||||
.compile_function(&sig, &body, validator)
|
||||
.expect("Couldn't compile function");
|
||||
|
||||
disasm(buffer.data(), isa).unwrap()
|
||||
disasm(buffer.data(), env.isa).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user