Commit Graph

22 Commits

Author SHA1 Message Date
Dan Gohman
c808447468 Have declare_table_elements consume its elements argument.
The producer is already allocating a new Vec, so no need to require the
consumer to allocate one too.
2017-10-13 12:43:15 -07:00
Dan Gohman
bd94a3b202 Move the 'data lifetime parameter to the ModuleEnvironment trait.
This is needed to allow implementations to have 'data-lifetime
references if they choose to. The DummyEnvironment is an example of an
implementation that doesn't choose to.
2017-10-13 12:43:15 -07:00
Dan Gohman
733870aee4 Make FuncEnvironment independent from ModuleEnvironment (formerly WasmRuntime).
This renames WasmRuntime to ModuleEnvironment, and makes several changes
to allow for more flexible compilation.

ModuleEnvironment no longer derives from FuncEnvironment, and no longer
has the `begin_translation` and `next_translation` functions, so that
independent `FuncEnvironment` instances can operate within the same
module.

Also, this obviates the rest of TranslationResult, as it moves processing
of function bodies into the environment. The DummyEnvironment implementation
gives an example of decoding the function bodies as they are parsed, however
other implementation strategies are now possible.
2017-10-10 15:50:24 -07:00
Dan Gohman
d4c0c5babc Rename WasmRuntime's get_name to get_func_name. 2017-10-10 10:21:06 -07:00
Dan Gohman
8e1ba080c0 Complete support for global init expressions. 2017-10-10 09:35:10 -07:00
Dan Gohman
653e8bb563 Declare exports via the WasmRuntime.
Also, redo how functions are named in the DummyRuntime. Use the FunctionName
field to just encode the wasm function index rather than trying to shoehorn
a printable name into it. And to make up for that, teach the wasm printer
to print export names as comments next to the function definitions.

This also makes the fields of DummyRuntime public, in preparation for
the DummyRuntime to have a more general-purpose debugging role, as well
as possibly to allow it to serve as a base for other implementations.
2017-10-10 08:46:10 -07:00
Dan Gohman
2c9d03f9bd Let the runtime provide the number of imported functions.
This obviates the need to keep a separate running total of the number of
functions seen.
2017-10-09 17:29:39 -07:00
Dan Gohman
e74bc06380 Move start_index out of TranslationResult and into the WasmRuntime.
This makes it more consistent with how all the rest of the content of
a wasm module is handled. And, now TranslationResult just has a Vec
of translated functions, which will make it easier to refactor further.
2017-10-09 17:29:39 -07:00
Dan Gohman
ef5ad630c8 Use the WasmRuntime's global list rather than keeping a separate list. 2017-10-09 17:29:39 -07:00
Dan Gohman
3841552b7c Use the WasmRuntime's type list rather than keeping a separate list. 2017-10-09 17:29:39 -07:00
Dan Gohman
7410ddfe08 Use the WasmRuntime's signature list rather than keeping a separate list.
This way, if the runtime modifies the signature, such as to add special
arguments, they are reflected in the resulting function defintions.
2017-10-04 16:57:39 -07:00
Jakob Stoklund Olesen
39992014e0 Make FuncEnvironment callbacks take an &mut self parameter.
The WasmRuntime trait already does this, and nothing in the function
translator requires the environment trait object to be non-mutable.
2017-09-14 12:25:59 -07:00
Dan Gohman
1ab207b93c Add support for emitting code with a single return at the end. (#153)
This also enables testing of the wasmtests tests.

This also updates for wabt updating to the official "wat" filename
extension, as opposed to "wast".
2017-09-12 13:27:36 -07:00
Dan Gohman
388a96421b Add documentation comments to GlobalValue's fields. 2017-09-07 10:34:26 -07:00
Jakob Stoklund Olesen
d6f6af104b Make translate_operator() generic on FuncEnvironment.
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.
2017-09-06 16:24:55 -07:00
Jakob Stoklund Olesen
b10faca534 Move translate_grow_memory and translate_current_memory too.
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.
2017-09-06 15:44:23 -07:00
Jakob Stoklund Olesen
26048c2ecc Move WasmRuntime::translate_call_indirect() into FuncEnvironment.
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.
2017-09-06 15:18:55 -07:00
Jakob Stoklund Olesen
dc2bee9cef Add a FuncEnvironment::make_direct_func() callback.
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.
2017-09-06 12:36:19 -07:00
Jakob Stoklund Olesen
27e9e16077 Add a FuncEnvironment::make_indirect_sig() callback.
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.
2017-09-06 10:28:11 -07:00
Jakob Stoklund Olesen
0ac1d0dd94 Add FuncEnvironment trait.
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.
2017-09-05 16:17:52 -07:00
Dan Gohman
2efdc0ed37 Update rustfmt to 0.9.0. 2017-08-31 10:44:59 -07:00
Denis Merigoux
ee9989c4b9 Dumped code from the wasm2cretonne repo.
Integrated wasm test suite translation as cretonne test

Fixes #146.
Fixes #143.
2017-08-28 15:57:43 -07:00