Path: blob/main/crates/cranelift/src/translate/environ/spec.rs
3104 views
//! All the runtime support necessary for the wasm to cranelift translation is formalized by the1//! traits `FunctionEnvironment` and `ModuleEnvironment`.2//!3//! There are skeleton implementations of these traits in the `dummy` module, and complete4//! implementations in [Wasmtime].5//!6//! [Wasmtime]: https://github.com/bytecodealliance/wasmtime78use cranelift_codegen::ir;9use cranelift_codegen::ir::immediates::Offset32;10use cranelift_codegen::isa::TargetFrontendConfig;11use smallvec::SmallVec;12use wasmtime_environ::{GlobalConstValue, Tunables, TypeConvert, WasmHeapType};1314/// The value of a WebAssembly global variable.15#[derive(Clone, Copy)]16pub enum GlobalVariable {17/// The global is known to be a constant value.18Constant {19/// The global's known value.20value: GlobalConstValue,21},2223/// This is a variable in memory that should be referenced through a `GlobalValue`.24Memory {25/// The address of the global variable storage.26gv: ir::GlobalValue,27/// An offset to add to the address.28offset: Offset32,29/// The global variable's type.30ty: ir::Type,31},3233/// This is a global variable that needs to be handled by the environment.34Custom,35}3637/// Environment affecting the translation of a WebAssembly.38pub trait TargetEnvironment: TypeConvert {39/// Get the information needed to produce Cranelift IR for the given target.40fn target_config(&self) -> TargetFrontendConfig;4142/// Whether to enable Spectre mitigations for heap accesses.43fn heap_access_spectre_mitigation(&self) -> bool;4445/// Whether to add proof-carrying-code facts to verify memory accesses.46fn proof_carrying_code(&self) -> bool;4748/// Get the Cranelift reference type to use for the given Wasm reference49/// type.50///51/// Returns a pair of the CLIF reference type to use and a boolean that52/// describes whether the value should be included in GC stack maps or not.53fn reference_type(&self, ty: WasmHeapType) -> (ir::Type, bool);5455/// Returns the compilation knobs that are in effect.56fn tunables(&self) -> &Tunables;57}5859/// A smallvec that holds the IR values for a struct's fields.60pub type StructFieldsVec = SmallVec<[ir::Value; 4]>;616263