Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/cranelift/src/translate/environ/spec.rs
3104 views
1
//! All the runtime support necessary for the wasm to cranelift translation is formalized by the
2
//! traits `FunctionEnvironment` and `ModuleEnvironment`.
3
//!
4
//! There are skeleton implementations of these traits in the `dummy` module, and complete
5
//! implementations in [Wasmtime].
6
//!
7
//! [Wasmtime]: https://github.com/bytecodealliance/wasmtime
8
9
use cranelift_codegen::ir;
10
use cranelift_codegen::ir::immediates::Offset32;
11
use cranelift_codegen::isa::TargetFrontendConfig;
12
use smallvec::SmallVec;
13
use wasmtime_environ::{GlobalConstValue, Tunables, TypeConvert, WasmHeapType};
14
15
/// The value of a WebAssembly global variable.
16
#[derive(Clone, Copy)]
17
pub enum GlobalVariable {
18
/// The global is known to be a constant value.
19
Constant {
20
/// The global's known value.
21
value: GlobalConstValue,
22
},
23
24
/// This is a variable in memory that should be referenced through a `GlobalValue`.
25
Memory {
26
/// The address of the global variable storage.
27
gv: ir::GlobalValue,
28
/// An offset to add to the address.
29
offset: Offset32,
30
/// The global variable's type.
31
ty: ir::Type,
32
},
33
34
/// This is a global variable that needs to be handled by the environment.
35
Custom,
36
}
37
38
/// Environment affecting the translation of a WebAssembly.
39
pub trait TargetEnvironment: TypeConvert {
40
/// Get the information needed to produce Cranelift IR for the given target.
41
fn target_config(&self) -> TargetFrontendConfig;
42
43
/// Whether to enable Spectre mitigations for heap accesses.
44
fn heap_access_spectre_mitigation(&self) -> bool;
45
46
/// Whether to add proof-carrying-code facts to verify memory accesses.
47
fn proof_carrying_code(&self) -> bool;
48
49
/// Get the Cranelift reference type to use for the given Wasm reference
50
/// type.
51
///
52
/// Returns a pair of the CLIF reference type to use and a boolean that
53
/// describes whether the value should be included in GC stack maps or not.
54
fn reference_type(&self, ty: WasmHeapType) -> (ir::Type, bool);
55
56
/// Returns the compilation knobs that are in effect.
57
fn tunables(&self) -> &Tunables;
58
}
59
60
/// A smallvec that holds the IR values for a struct's fields.
61
pub type StructFieldsVec = SmallVec<[ir::Value; 4]>;
62
63