Skip to content

Commit

Permalink
cranelift-wasm: Make FuncEnvironment::translate_ref_func take a `Fu…
Browse files Browse the repository at this point in the history
…ncIndex`

It was previously taking a raw `u32`. This change makes it more clear what index
space that index points into.
  • Loading branch information
fitzgen committed Jun 23, 2020
1 parent c6f32f6 commit ddc2ce8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cranelift/wasm/src/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
state.push1(environ.translate_ref_is_null(builder.cursor(), value)?);
}
Operator::RefFunc { function_index } => {
state.push1(environ.translate_ref_func(builder.cursor(), *function_index)?);
let index = FuncIndex::from_u32(*function_index);
state.push1(environ.translate_ref_func(builder.cursor(), index)?);
}
Operator::AtomicNotify { .. }
| Operator::I32AtomicWait { .. }
Expand Down
2 changes: 1 addition & 1 deletion cranelift/wasm/src/environ/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
fn translate_ref_func(
&mut self,
mut pos: FuncCursor,
_func_index: u32,
_func_index: FuncIndex,
) -> WasmResult<ir::Value> {
Ok(pos.ins().null(self.reference_type()))
}
Expand Down
6 changes: 5 additions & 1 deletion cranelift/wasm/src/environ/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ pub trait FuncEnvironment: TargetEnvironment {
}

/// Translate a `ref.func` WebAssembly instruction.
fn translate_ref_func(&mut self, pos: FuncCursor, func_index: u32) -> WasmResult<ir::Value>;
fn translate_ref_func(
&mut self,
pos: FuncCursor,
func_index: FuncIndex,
) -> WasmResult<ir::Value>;

/// Translate a `global.get` WebAssembly instruction at `pos` for a global
/// that is custom.
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
fn translate_ref_func(
&mut self,
_: cranelift_codegen::cursor::FuncCursor<'_>,
_: u32,
_: FuncIndex,
) -> WasmResult<ir::Value> {
Err(WasmError::Unsupported(
"the `ref.func` instruction is not supported yet".into(),
Expand Down

0 comments on commit ddc2ce8

Please sign in to comment.