* Refactor where results of compilation are stored This commit refactors the internals of compilation in Wasmtime to change where results of individual function compilation are stored. Previously compilation resulted in many maps being returned, and compilation results generally held all these maps together. This commit instead switches this to have all metadata stored in a `CompiledFunction` instead of having a separate map for each item that can be stored. The motivation for this is primarily to help out with future module-linking-related PRs. What exactly "module level" is depends on how we interpret modules and how many modules are in play, so it's a bit easier for operations in wasmtime to work at the function level where possible. This means that we don't have to pass around multiple different maps and a function index, but instead just one map or just one entry representing a compiled function. Additionally this change updates where the parallelism of compilation happens, pushing it into `wasmtime-jit` instead of `wasmtime-environ`. This is another goal where `wasmtime-jit` will have more knowledge about module-level pieces with module linking in play. User-facing-wise this should be the same in terms of parallel compilation, though. The ultimate goal of this refactoring is to make it easier for the results of compilation to actually be a set of wasm modules. This means we won't be able to have a map-per-metadata where the primary key is the function index, because there will be many modules within one "object file". * Don't clear out fields, just don't store them Persist a smaller set of fields in `CompilationArtifacts` instead of trying to clear fields out and dynamically not accessing them.
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
//! Data structures to provide transformation of the source
|
|
// addresses of a WebAssembly module into the native code.
|
|
|
|
use cranelift_codegen::ir;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Single source location to generated address mapping.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
|
pub struct InstructionAddressMap {
|
|
/// Original source location.
|
|
pub srcloc: ir::SourceLoc,
|
|
|
|
/// Generated instructions offset.
|
|
pub code_offset: usize,
|
|
|
|
/// Generated instructions length.
|
|
pub code_len: usize,
|
|
}
|
|
|
|
/// Function and its instructions addresses mappings.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
|
pub struct FunctionAddressMap {
|
|
/// Instructions maps.
|
|
/// The array is sorted by the InstructionAddressMap::code_offset field.
|
|
pub instructions: Vec<InstructionAddressMap>,
|
|
|
|
/// Function start source location (normally declaration).
|
|
pub start_srcloc: ir::SourceLoc,
|
|
|
|
/// Function end source location.
|
|
pub end_srcloc: ir::SourceLoc,
|
|
|
|
/// Generated function body offset if applicable, otherwise 0.
|
|
pub body_offset: usize,
|
|
|
|
/// Generated function body length.
|
|
pub body_len: usize,
|
|
}
|
|
|
|
/// Memory definition offset in the VMContext structure.
|
|
#[derive(Debug, Clone)]
|
|
pub enum ModuleMemoryOffset {
|
|
/// Not available.
|
|
None,
|
|
/// Offset to the defined memory.
|
|
Defined(u32),
|
|
/// Offset to the imported memory.
|
|
Imported(u32),
|
|
}
|