Files
wasmtime/lib/obj/src/emit_module.rs
Dan Gohman fb7153ccf4 Update to cranelift 0.20.0.
The biggest change is the split from FunctionIndex to
DefinedFuncIndex to FuncIndex. Take better advantage of this by
converting several Vecs to PrimaryMaps.

Also, table_addr can now handle indices of the table index type,
so we don't need to explicitly uextend them anymore.
2018-08-28 20:56:58 -07:00

38 lines
1.2 KiB
Rust

use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_entity::EntityRef;
use faerie::Artifact;
use wasmtime_environ::{Compilation, Module, Relocations};
/// Emits a module that has been emitted with the `wasmtime-environ` environment
/// implementation to a native object file.
pub fn emit_module(
obj: &mut Artifact,
module: &Module,
compilation: &Compilation,
relocations: &Relocations,
) -> Result<(), String> {
debug_assert!(
module.start_func.is_none()
|| module.start_func.unwrap().index() >= module.imported_funcs.len(),
"imported start functions not supported yet"
);
let mut shared_builder = settings::builder();
shared_builder
.enable("enable_verifier")
.expect("Missing enable_verifier setting");
for (i, function_relocs) in relocations.iter() {
assert!(function_relocs.is_empty(), "relocations not supported yet");
let body = &compilation.functions[i];
let func_index = module.func_index(i);
let string_name = format!("wasm_function[{}]", func_index.index());
obj.define(string_name, body.clone())
.map_err(|err| format!("{}", err))?;
}
Ok(())
}