Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/environ/src/component/artifacts.rs
1692 views
1
//! Definitions of compilation artifacts of the component compilation process
2
//! which are serialized with `bincode` into output ELF files.
3
4
use crate::{
5
CompiledModuleInfo, FunctionLoc, PrimaryMap, StaticModuleIndex,
6
component::{Component, ComponentTypes, TrampolineIndex, TypeComponentIndex},
7
};
8
use serde_derive::{Deserialize, Serialize};
9
10
/// Serializable state that's stored in a compilation artifact.
11
#[derive(Serialize, Deserialize)]
12
pub struct ComponentArtifacts {
13
/// The type of this component.
14
pub ty: TypeComponentIndex,
15
/// Information all kept available at runtime as-is.
16
pub info: CompiledComponentInfo,
17
/// Type information for this component and all contained modules.
18
pub types: ComponentTypes,
19
/// Serialized metadata about all included core wasm modules.
20
pub static_modules: PrimaryMap<StaticModuleIndex, CompiledModuleInfo>,
21
}
22
23
/// Runtime state that a component retains to support its operation.
24
#[derive(Serialize, Deserialize)]
25
pub struct CompiledComponentInfo {
26
/// Type information calculated during translation about this component.
27
pub component: Component,
28
29
/// Where lowered function trampolines are located within the `text`
30
/// section of `code_memory`.
31
///
32
/// These are the
33
///
34
/// 1. Wasm-call,
35
/// 2. array-call
36
///
37
/// function pointers that end up in a `VMFuncRef` for each
38
/// lowering.
39
pub trampolines: PrimaryMap<TrampolineIndex, AllCallFunc<FunctionLoc>>,
40
41
/// The location of the wasm-to-array trampoline for the `resource.drop`
42
/// intrinsic.
43
pub resource_drop_wasm_to_array_trampoline: Option<FunctionLoc>,
44
}
45
46
/// A triple of related functions/trampolines variants with differing calling
47
/// conventions: `{wasm,array}_call`.
48
///
49
/// Generic so we can use this with either the `Box<dyn Any + Send>`s that
50
/// implementations of the compiler trait return or with `FunctionLoc`s inside
51
/// an object file, for example.
52
#[derive(Clone, Copy, Default, Serialize, Deserialize)]
53
pub struct AllCallFunc<T> {
54
/// The function exposing the Wasm calling convention.
55
pub wasm_call: T,
56
/// The function exposing the array calling convention.
57
pub array_call: T,
58
}
59
60
impl<T> AllCallFunc<T> {
61
/// Map an `AllCallFunc<T>` into an `AllCallFunc<U>`.
62
pub fn map<U>(self, mut f: impl FnMut(T) -> U) -> AllCallFunc<U> {
63
AllCallFunc {
64
wasm_call: f(self.wasm_call),
65
array_call: f(self.array_call),
66
}
67
}
68
}
69
70