wasmtime: Pass around more contexts instead of fields (#1486)
* wasmtime: Pass around more contexts instead of fields This commit refactors some wasmtime internals to pass around more context-style structures rather than individual fields of each structure. The intention here is to make the addition of fields to a structure easier to plumb throughout the internals of wasmtime. Currently you need to edit lots of functions to pass lots of parameters, but ideally after this you'll only need to edit one or two struct fields and then relevant locations have access to the information already. Updates in this commit are: * `debug_info` configuration is now folded into `Tunables`. Additionally a `wasmtime::Config` now holds a `Tunables` directly and is passed into an internal `Compiler`. Eventually this should allow for direct configuration of the `Tunables` attributes from the `wasmtime` API, but no new configuration is exposed at this time. * `ModuleTranslation` is now passed around as a whole rather than passing individual components to allow access to all the fields, including `Tunables`. This was motivated by investigating what it would take to optionally allow loops and such to get interrupted, but that sort of codegen setting was currently relatively difficult to plumb all the way through and now it's hoped to be largely just an addition to `Tunables`. * Fix lightbeam compile
This commit is contained in:
@@ -11,8 +11,6 @@ use std::{
|
||||
use structopt::{clap::AppSettings, StructOpt};
|
||||
use target_lexicon::Triple;
|
||||
use wasmtime_environ::CacheConfig;
|
||||
#[cfg(feature = "lightbeam")]
|
||||
use wasmtime_environ::Lightbeam;
|
||||
|
||||
/// The after help text for the `wasm2obj` command.
|
||||
pub const WASM2OBJ_AFTER_HELP: &str = "The translation is dependent on the environment chosen.\n\
|
||||
|
||||
58
src/obj.rs
58
src/obj.rs
@@ -54,29 +54,14 @@ pub fn compile_to_obj(
|
||||
let mut obj = Artifact::new(isa.triple().clone(), artifact_name);
|
||||
|
||||
// TODO: Expose the tunables as command-line flags.
|
||||
let tunables = Tunables::default();
|
||||
let mut tunables = Tunables::default();
|
||||
tunables.debug_info = debug_info;
|
||||
|
||||
let (
|
||||
module,
|
||||
module_translation,
|
||||
lazy_function_body_inputs,
|
||||
lazy_data_initializers,
|
||||
target_config,
|
||||
) = {
|
||||
let environ = ModuleEnvironment::new(isa.frontend_config(), tunables);
|
||||
let environ = ModuleEnvironment::new(isa.frontend_config(), &tunables);
|
||||
|
||||
let translation = environ
|
||||
.translate(wasm)
|
||||
.context("failed to translate module")?;
|
||||
|
||||
(
|
||||
translation.module,
|
||||
translation.module_translation.unwrap(),
|
||||
translation.function_body_inputs,
|
||||
translation.data_initializers,
|
||||
translation.target_config,
|
||||
)
|
||||
};
|
||||
let translation = environ
|
||||
.translate(wasm)
|
||||
.context("failed to translate module")?;
|
||||
|
||||
// TODO: use the traps information
|
||||
let (
|
||||
@@ -88,23 +73,11 @@ pub fn compile_to_obj(
|
||||
_traps,
|
||||
frame_layouts,
|
||||
) = match strategy {
|
||||
Strategy::Auto | Strategy::Cranelift => Cranelift::compile_module(
|
||||
&module,
|
||||
&module_translation,
|
||||
lazy_function_body_inputs,
|
||||
&*isa,
|
||||
debug_info,
|
||||
cache_config,
|
||||
),
|
||||
Strategy::Auto | Strategy::Cranelift => {
|
||||
Cranelift::compile_module(&translation, &*isa, cache_config)
|
||||
}
|
||||
#[cfg(feature = "lightbeam")]
|
||||
Strategy::Lightbeam => Lightbeam::compile_module(
|
||||
&module,
|
||||
&module_translation,
|
||||
lazy_function_body_inputs,
|
||||
&*isa,
|
||||
debug_info,
|
||||
cache_config,
|
||||
),
|
||||
Strategy::Lightbeam => Lightbeam::compile_module(&translation, &*isa, cache_config),
|
||||
#[cfg(not(feature = "lightbeam"))]
|
||||
Strategy::Lightbeam => bail!("lightbeam support not enabled"),
|
||||
other => bail!("unsupported compilation strategy {:?}", other),
|
||||
@@ -116,7 +89,10 @@ pub fn compile_to_obj(
|
||||
}
|
||||
|
||||
let module_vmctx_info = {
|
||||
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local);
|
||||
let ofs = VMOffsets::new(
|
||||
translation.target_config.pointer_bytes(),
|
||||
&translation.module.local,
|
||||
);
|
||||
ModuleVmctxInfo {
|
||||
memory_offset: if ofs.num_imported_memories > 0 {
|
||||
ModuleMemoryOffset::Imported(ofs.vmctx_vmmemory_import(MemoryIndex::new(0)))
|
||||
@@ -133,11 +109,11 @@ pub fn compile_to_obj(
|
||||
|
||||
emit_module(
|
||||
&mut obj,
|
||||
&module,
|
||||
&translation.module,
|
||||
&compilation,
|
||||
&relocations,
|
||||
&lazy_data_initializers,
|
||||
&target_config,
|
||||
&translation.data_initializers,
|
||||
&translation.target_config,
|
||||
)
|
||||
.map_err(|e| anyhow!(e))
|
||||
.context("failed to emit module")?;
|
||||
|
||||
Reference in New Issue
Block a user