Revert "Remove FunctionBuilderContext from API, and change FunctionBuilder API"

This reverts commit 39e638af99dbe6537bc935bfb1a74669b62877b3.
This commit is contained in:
Erin Power
2019-09-14 17:08:10 +02:00
committed by Benjamin Bouvier
parent 8d62d5f724
commit 5426e42a27
11 changed files with 172 additions and 162 deletions

View File

@@ -81,7 +81,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
* `get_global` and `set_global` are handled by the environment.
***********************************************************************************/
Operator::GetGlobal { global_index } => {
let val = match state.get_global(&mut builder.func, *global_index, environ)? {
let val = match state.get_global(builder.func, *global_index, environ)? {
GlobalVariable::Const(val) => val,
GlobalVariable::Memory { gv, offset, ty } => {
let addr = builder.ins().global_value(environ.pointer_type(), gv);
@@ -92,7 +92,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
state.push1(val);
}
Operator::SetGlobal { global_index } => {
match state.get_global(&mut builder.func, *global_index, environ)? {
match state.get_global(builder.func, *global_index, environ)? {
GlobalVariable::Const(_) => panic!("global #{} is a constant", *global_index),
GlobalVariable::Memory { gv, offset, ty } => {
let addr = builder.ins().global_value(environ.pointer_type(), gv);
@@ -367,8 +367,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
* argument referring to an index in the external functions table of the module.
************************************************************************************/
Operator::Call { function_index } => {
let (fref, num_args) =
state.get_direct_func(&mut builder.func, *function_index, environ)?;
let (fref, num_args) = state.get_direct_func(builder.func, *function_index, environ)?;
let call = environ.translate_call(
builder.cursor(),
FuncIndex::from_u32(*function_index),
@@ -389,8 +388,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
Operator::CallIndirect { index, table_index } => {
// `index` is the index of the function's signature and `table_index` is the index of
// the table to search the function in.
let (sigref, num_args) = state.get_indirect_sig(&mut builder.func, *index, environ)?;
let table = state.get_table(&mut builder.func, *table_index, environ)?;
let (sigref, num_args) = state.get_indirect_sig(builder.func, *index, environ)?;
let table = state.get_table(builder.func, *table_index, environ)?;
let callee = state.pop1();
let call = environ.translate_call_indirect(
builder.cursor(),
@@ -418,13 +417,13 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
// The WebAssembly MVP only supports one linear memory, but we expect the reserved
// argument to be a memory index.
let heap_index = MemoryIndex::from_u32(*reserved);
let heap = state.get_heap(&mut builder.func, *reserved, environ)?;
let heap = state.get_heap(builder.func, *reserved, environ)?;
let val = state.pop1();
state.push1(environ.translate_memory_grow(builder.cursor(), heap_index, heap, val)?)
}
Operator::MemorySize { reserved } => {
let heap_index = MemoryIndex::from_u32(*reserved);
let heap = state.get_heap(&mut builder.func, *reserved, environ)?;
let heap = state.get_heap(builder.func, *reserved, environ)?;
state.push1(environ.translate_memory_size(builder.cursor(), heap_index, heap)?);
}
/******************************* Load instructions ***********************************
@@ -1238,7 +1237,7 @@ fn translate_load<FE: FuncEnvironment + ?Sized>(
) -> WasmResult<()> {
let addr32 = state.pop1();
// We don't yet support multiple linear memories.
let heap = state.get_heap(&mut builder.func, 0, environ)?;
let heap = state.get_heap(builder.func, 0, environ)?;
let (base, offset) = get_heap_addr(heap, addr32, offset, environ.pointer_type(), builder);
// Note that we don't set `is_aligned` here, even if the load instruction's
// alignment immediate says it's aligned, because WebAssembly's immediate
@@ -1263,7 +1262,7 @@ fn translate_store<FE: FuncEnvironment + ?Sized>(
let val_ty = builder.func.dfg.value_type(val);
// We don't yet support multiple linear memories.
let heap = state.get_heap(&mut builder.func, 0, environ)?;
let heap = state.get_heap(builder.func, 0, environ)?;
let (base, offset) = get_heap_addr(heap, addr32, offset, environ.pointer_type(), builder);
// See the comments in `translate_load` about the flags.
let flags = MemFlags::new();