Update for wasm memory instruction renaming.
The wasm spec renamed `grow_memory` and `current_memory` to `memory.grow` and `memory.size`, respectively. Update cretonne's names to follow. Also, update to wasmparser 0.17.0, which also renames its corresponding operators.
This commit is contained in:
@@ -9,7 +9,7 @@ readme = "README.md"
|
|||||||
keywords = ["webassembly", "wasm"]
|
keywords = ["webassembly", "wasm"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmparser = { version = "0.16.1", default-features = false }
|
wasmparser = { version = "0.17.0", default-features = false }
|
||||||
cretonne-codegen = { path = "../codegen", version = "0.9.0", default-features = false }
|
cretonne-codegen = { path = "../codegen", version = "0.9.0", default-features = false }
|
||||||
cretonne-frontend = { path = "../frontend", version = "0.9.0", default-features = false }
|
cretonne-frontend = { path = "../frontend", version = "0.9.0", default-features = false }
|
||||||
hashmap_core = { version = "0.1.6", optional = true }
|
hashmap_core = { version = "0.1.6", optional = true }
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
//!
|
//!
|
||||||
//! - the loads and stores need the memory base address;
|
//! - the loads and stores need the memory base address;
|
||||||
//! - the `get_global` et `set_global` instructions depends on how the globals are implemented;
|
//! - the `get_global` et `set_global` instructions depends on how the globals are implemented;
|
||||||
//! - `current_memory` and `grow_memory` are runtime functions;
|
//! - `memory.size` and `memory.grow` are runtime functions;
|
||||||
//! - `call_indirect` has to translate the function index into the address of where this
|
//! - `call_indirect` has to translate the function index into the address of where this
|
||||||
//! is;
|
//! is;
|
||||||
//!
|
//!
|
||||||
@@ -398,18 +398,18 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
* Memory management is handled by environment. It is usually translated into calls to
|
* Memory management is handled by environment. It is usually translated into calls to
|
||||||
* special functions.
|
* special functions.
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
Operator::GrowMemory { reserved } => {
|
Operator::MemoryGrow { reserved } => {
|
||||||
// The WebAssembly MVP only supports one linear memory, but we expect the reserved
|
// The WebAssembly MVP only supports one linear memory, but we expect the reserved
|
||||||
// argument to be a memory index.
|
// argument to be a memory index.
|
||||||
let heap_index = reserved as MemoryIndex;
|
let heap_index = reserved as MemoryIndex;
|
||||||
let heap = state.get_heap(builder.func, reserved, environ);
|
let heap = state.get_heap(builder.func, reserved, environ);
|
||||||
let val = state.pop1();
|
let val = state.pop1();
|
||||||
state.push1(environ.translate_grow_memory(builder.cursor(), heap_index, heap, val)?)
|
state.push1(environ.translate_memory_grow(builder.cursor(), heap_index, heap, val)?)
|
||||||
}
|
}
|
||||||
Operator::CurrentMemory { reserved } => {
|
Operator::MemorySize { reserved } => {
|
||||||
let heap_index = reserved as MemoryIndex;
|
let heap_index = reserved as MemoryIndex;
|
||||||
let heap = state.get_heap(builder.func, reserved, environ);
|
let heap = state.get_heap(builder.func, reserved, environ);
|
||||||
state.push1(environ.translate_current_memory(builder.cursor(), heap_index, heap)?);
|
state.push1(environ.translate_memory_size(builder.cursor(), heap_index, heap)?);
|
||||||
}
|
}
|
||||||
/******************************* Load instructions ***********************************
|
/******************************* Load instructions ***********************************
|
||||||
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
|
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
Ok(pos.ins().Call(ir::Opcode::Call, VOID, callee, args).0)
|
Ok(pos.ins().Call(ir::Opcode::Call, VOID, callee, args).0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate_grow_memory(
|
fn translate_memory_grow(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_index: MemoryIndex,
|
_index: MemoryIndex,
|
||||||
@@ -271,7 +271,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
Ok(pos.ins().iconst(I32, -1))
|
Ok(pos.ins().iconst(I32, -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate_current_memory(
|
fn translate_memory_size(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_index: MemoryIndex,
|
_index: MemoryIndex,
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ pub trait FuncEnvironment {
|
|||||||
Ok(pos.ins().call(callee, call_args))
|
Ok(pos.ins().call(callee, call_args))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translate a `grow_memory` WebAssembly instruction.
|
/// Translate a `memory.grow` WebAssembly instruction.
|
||||||
///
|
///
|
||||||
/// The `index` provided identifies the linear memory to grow, and `heap` is the heap reference
|
/// The `index` provided identifies the linear memory to grow, and `heap` is the heap reference
|
||||||
/// returned by `make_heap` for the same index.
|
/// returned by `make_heap` for the same index.
|
||||||
@@ -171,7 +171,7 @@ pub trait FuncEnvironment {
|
|||||||
/// The `val` value is the requested memory size in pages.
|
/// The `val` value is the requested memory size in pages.
|
||||||
///
|
///
|
||||||
/// Returns the old size (in pages) of the memory.
|
/// Returns the old size (in pages) of the memory.
|
||||||
fn translate_grow_memory(
|
fn translate_memory_grow(
|
||||||
&mut self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
index: MemoryIndex,
|
index: MemoryIndex,
|
||||||
@@ -179,13 +179,13 @@ pub trait FuncEnvironment {
|
|||||||
val: ir::Value,
|
val: ir::Value,
|
||||||
) -> WasmResult<ir::Value>;
|
) -> WasmResult<ir::Value>;
|
||||||
|
|
||||||
/// Translates a `current_memory` WebAssembly instruction.
|
/// Translates a `memory.size` WebAssembly instruction.
|
||||||
///
|
///
|
||||||
/// The `index` provided identifies the linear memory to query, and `heap` is the heap reference
|
/// The `index` provided identifies the linear memory to query, and `heap` is the heap reference
|
||||||
/// returned by `make_heap` for the same index.
|
/// returned by `make_heap` for the same index.
|
||||||
///
|
///
|
||||||
/// Returns the size in pages of the memory.
|
/// Returns the size in pages of the memory.
|
||||||
fn translate_current_memory(
|
fn translate_memory_size(
|
||||||
&mut self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
index: MemoryIndex,
|
index: MemoryIndex,
|
||||||
|
|||||||
Reference in New Issue
Block a user