Skip to content

Commit

Permalink
Add unimplemented stubs for Cranelift interfaces
Browse files Browse the repository at this point in the history
Cranelift changes to FuncEnvironment, TargetEnvironment, and GlobalInit (see bytecodealliance/cranelift#1073) require these changes to compile wasmtime.
  • Loading branch information
abrown authored and yurydelendik committed Dec 31, 2019
1 parent 681445b commit 31096ae
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
87 changes: 85 additions & 2 deletions crates/environ/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_entity::EntityRef;
use cranelift_wasm::{
self, FuncIndex, GlobalIndex, GlobalVariable, MemoryIndex, SignatureIndex, TableIndex,
WasmResult,
TargetEnvironment, WasmError, WasmResult,
};
#[cfg(feature = "lightbeam")]
use cranelift_wasm::{DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex};
Expand Down Expand Up @@ -355,11 +355,13 @@ impl lightbeam::ModuleContext for FuncEnvironment<'_> {
// TODO: type of a global
}

impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'module_environment> {
impl<'module_environment> TargetEnvironment for FuncEnvironment<'module_environment> {
fn target_config(&self) -> TargetFrontendConfig {
self.target_config
}
}

impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'module_environment> {
fn make_table(&mut self, func: &mut ir::Function, index: TableIndex) -> WasmResult<ir::Table> {
let pointer_type = self.pointer_type();

Expand Down Expand Up @@ -702,4 +704,85 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
.call_indirect(func_sig, func_addr, &[vmctx, memory_index]);
Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap())
}

fn translate_memory_copy(
&mut self,
_pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_memory_fill(
&mut self,
_pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
_dst: ir::Value,
_val: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_memory_init(
&mut self,
_pos: FuncCursor,
_index: MemoryIndex,
_heap: ir::Heap,
_seg_index: u32,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_data_drop(&mut self, _pos: FuncCursor, _seg_index: u32) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_table_size(
&mut self,
_pos: FuncCursor,
_index: TableIndex,
_table: ir::Table,
) -> WasmResult<ir::Value> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_table_copy(
&mut self,
_pos: FuncCursor,
_dst_table_index: TableIndex,
_dst_table: ir::Table,
_src_table_index: TableIndex,
_src_table: ir::Table,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_table_init(
&mut self,
_pos: FuncCursor,
_seg_index: u32,
_table_index: TableIndex,
_table: ir::Table,
_dst: ir::Value,
_src: ir::Value,
_len: ir::Value,
) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}

fn translate_elem_drop(&mut self, _pos: FuncCursor, _seg_index: u32) -> WasmResult<()> {
Err(WasmError::Unsupported("bulk memory".to_string()))
}
}
10 changes: 6 additions & 4 deletions crates/environ/src/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_entity::PrimaryMap;
use cranelift_wasm::{
self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex,
ModuleTranslationState, SignatureIndex, Table, TableIndex, WasmResult,
ModuleTranslationState, SignatureIndex, Table, TableIndex, TargetEnvironment, WasmResult,
};
use std::convert::TryFrom;

Expand Down Expand Up @@ -86,13 +86,15 @@ impl<'data> ModuleEnvironment<'data> {
}
}

/// This trait is useful for `translate_module` because it tells how to translate
/// environment-dependent wasm instructions. These functions should not be called by the user.
impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data> {
impl<'data> TargetEnvironment for ModuleEnvironment<'data> {
fn target_config(&self) -> TargetFrontendConfig {
self.result.target_config
}
}

/// This trait is useful for `translate_module` because it tells how to translate
/// environment-dependent wasm instructions. These functions should not be called by the user.
impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data> {
fn reserve_signatures(&mut self, num: u32) -> WasmResult<()> {
self.result
.module
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ fn initialize_globals(instance: &mut Instance) {
unsafe { *to = *from };
}
GlobalInit::Import => panic!("locally-defined global initialized as import"),
GlobalInit::RefNullConst => unimplemented!(),
}
}
}
Expand Down

0 comments on commit 31096ae

Please sign in to comment.