This makes the details of the spiderwasm prologue configurable so it is
easier to modify SpiderMonkey without having to change Cretonne.
Create a stack object representing the SpiderMonkey prologue words
before calculating the stack layout so they won't be overwritten by
Cretonne's stack objects.
When debugging code built with panic=about, the debug trace buffer is
not flushed on a panic and important messages are lost.
This does slow down debug tracing a bit, but this is still better than
unbuffered or line buffered I/O since the dbg!() macro can write out
many lines like a whole function.
A subtle difference here is that the `end` at the end of a function body
now gets handled by translate_operator/translate_unreachable_operator, so we
no longer have to do as much special-case cleanup at the end of the function
body.
This is a preperatory step for converting module_translator.rs to use
the new FuncTranslator mechanism.
The flag guarantees that the generated function does not have any
internal return instructions. If the function returns at all, the return
must be the last instruction.
For now just implement a verifier check for this property. When we get
CFG simplifiers and block layout optimizations, they will need to heed
the flag.
With FuncEnvironment using FuncCursors in place of full
FunctionBuilders, it's useful to move several of these convenience
functions from FunctionBuilder to Function.
wasmparser's API is changing in anticipation of streaming decoding, so
it will now hand large data section initializers back in chunks rather
than all at once.
This makes it possible to clear out a Function data structure so it can
be reused for compiling multiple functions.
Also add clear() methods to various sub-structures.
The new FuncTranslator type can be used to translate binary WebAssembly
functions to Cretonne IL one at a time. It is independent of the
module-level parser also present in the cretonne-wasm crate.
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 type is not longer used in any public interface, it has become an
internal implementation detail.
Also remove some unused exported types from the crate.
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.
* Replace SSABuilder's variables HashMaps with EntityMaps.
Current measurements show that memory usage is approximately the same,
and it's about 20% faster.
* Add EntityMap::with_default and use it.
* rustfmt
* Use var_defs[block].expand().
Instead of allocating a vector to store jump arguments for processing
later, just have the later code rescan through the predecessors to
obtain the values, which are memoized.
This also eliminates a linear search through the predecessor list when
splitting a critical edge.