This makes it clear that this function only uses the FuncEnvironment
trait and not WasmRuntime.
Also make the translate_{grow,current}_memory() methods take &self
instead of &mut self. The &mut was left on there by accident.
This moves the last instruction-level callbacks into FuncEnvironment
such that the trait has all the information required to translate a
whole function.
Change the position argument to a FuncCursor. This eliminates all
exposure of FunctionBuilder<Local>, so its use properly becomes an
implementation detail.
Add two new arguments:
- table_index is the WebAssembly table referenced in the indirect call.
- sig_index is the WebAssembly signature index. We still have the SigRef
that was created by make_indirect_sig(), but the WebAssembly signature
index may be needed for detecting type mismatches at runtime.
Change the insertion location to a plain FuncCursor rather than a
FunctionBuilder<Local>. The fact that cretonne-wasm uses FunctionBuilder
should be an implementation detail, and the callbacks don't need to
access WebAssembly locals, so they don't need the extended interface.
Add a FunctionBuilder::cursor() method which creates a FuncCursor for
inserting instructions in the current EBB.
Also add a FuncEnvironment::translate_call() method which allows the
environment to override direct calls the same way as indirect calls.
This allows the environment to control the signatures used for direct
function calls. The signature and calling convention may depend on
whether the function is imported or local.
Also add WasmRuntime::declare_func_{import,type} to notify the runtime
about imported and local functions. This is necessary so the runtime
knows what function indexes are referring to .
Since imported and local functions are now declared to the runtime, it
is no longer necessary to return hashes mapping between WebAssembly
indexes and Cretonne entities.
Also stop return null entries for the imported functions in the
TranslationResult. Just return a vector of local functions.
The function environment is now expected to keep track of the function
signatures in the module, and it is asked to generate Cretonne
signatures to be used for indirect calls.
The combination of make_indirect_sig() and translate_call_indirect()
callbacks allow the runtime to insert additional function arguments for
indirect calls such as vmctx pointers and CFI-style signature identifiers.
This trait is used to provide the environment necessary to translate a
single WebAssembly function without having other global data structures
for the WebAssembly module.
The WasmRuntime trait extends the FuncEnvironment trait for those uses
that want to parse a whole WebAssembly module.
- Change the handling of WebAssembly globals to use the FuncEnvironment
trait as well as the new GlobalVar infrastructure in Cretonne. The
runtime is not consulted on the translation of each
get_global/get_global instruction. Instead it gets to create the
GlobalVar declaration in the function preamble the first time the
global is used.
- Change the handling of heap load/store instructions to use the new
Heap infrastructure in Cretonne. The runtime is called to create the
Heap declaration in the preamble. It is not involved in individual
load/store instructions.
It's not necessary to explicitly track whether the last instruction is a
return; if the builder for the last block isn't filled by the time we reach
the end, it needs a return to fill it.
The phantom unreachable stack is only used when the real unreachable stack is
active, so it's sufficient to check whether the real unreachable stack is empty.