1use wasmparser::types::Types;
7use wasmtime_environ::{FuncIndex, Module};
8use winch_codegen::{self, Callee, TargetIsa};
9
10pub struct FuncEnv<'a> {
13 pub module: &'a Module,
15 pub types: &'a Types,
17 pub isa: &'a Box<dyn TargetIsa>,
19}
20
21impl<'a> winch_codegen::FuncEnv for FuncEnv<'a> {
22 fn callee_from_index(&self, index: u32) -> Callee {
23 let func = self
24 .types
25 .function_at(index)
26 .unwrap_or_else(|| panic!("function type at index: {}", index));
27
28 Callee {
29 ty: func.clone(),
30 import: self.module.is_imported_function(FuncIndex::from_u32(index)),
31 index,
32 }
33 }
34}
35
36impl<'a> FuncEnv<'a> {
37 pub fn new(module: &'a Module, types: &'a Types, isa: &'a Box<dyn TargetIsa>) -> Self {
39 Self { module, types, isa }
40 }
41}