Commit Graph

86 Commits

Author SHA1 Message Date
Dan Gohman
47bc963ba5 Add a JumpTableData::with_capacity and use it.
As with Vec::with_capacity, this helps reduce intermediate heap allocation.
2017-09-11 08:47:28 -07:00
Dan Gohman
620f1f49e2 Move several functions from FunctionBuilder to Function.
With FuncEnvironment using FuncCursors in place of full
FunctionBuilders, it's useful to move several of these convenience
functions from FunctionBuilder to Function.
2017-09-11 08:40:50 -07:00
Jakob Stoklund Olesen
439a40e5e4 Add a WebAssembly function translator.
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.
2017-09-07 16:12:48 -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
Jakob Stoklund Olesen
19c8ba5021 Eliminate the sig argument to translate_operator.
The current function's return types are pushed as the first control
stack frame.
2017-09-05 11:51:32 -07:00
Jakob Stoklund Olesen
2671cbb092 Add TranslationState::in_unreachable_code().
Move an unreachable code test and sanity check into this method.
2017-09-05 11:46:08 -07:00
Jakob Stoklund Olesen
6f864f2926 Move translation state initialization into a method. 2017-09-05 11:00:40 -07:00
Dan Gohman
ef3ea72422 Avoid calling Vec::split_off, avoiding more heap allocations. 2017-09-05 09:23:20 -07:00
Jakob Stoklund Olesen
03939e4f9f Move TranslationState into its own module.
Add some convenience methods for common state access patterns.
2017-09-01 15:55:02 -07:00
Jakob Stoklund Olesen
6762194801 Move stack and control_stack into TranslationState.
This reduces the number of function arguments passed around and it keeps
related information together.
2017-09-01 14:29:35 -07:00
Dan Gohman
fe12fe0e63 Avoid unneeded calls to .as_slice(). 2017-09-01 12:15:14 -07:00
Dan Gohman
9d2fbdae62 Avoid cloning a jump argument vector to the heap. 2017-09-01 12:15:14 -07:00
Dan Gohman
dc79d155ff Comment wording cleanups. 2017-08-31 12:47:05 -07:00
Dan Gohman
a7d629c368 Use the Self keyword where applicable.
https://github.com/rust-lang-nursery/rust-clippy/wiki#use_self
2017-08-31 12:47:05 -07:00
Dan Gohman
da2c2151b1 Fix trivial_numeric_casts errors. 2017-08-31 12:47:05 -07:00
Dan Gohman
9726bb7367 Avoid matching with reference patterns.
https://github.com/rust-lang-nursery/rust-clippy/wiki#match_ref_pats
2017-08-31 12:47:05 -07:00
Dan Gohman
5a8d1a9fda Use if let instead of match.
https://github.com/rust-lang-nursery/rust-clippy/wiki#single_match
2017-08-31 12:47:05 -07:00
Dan Gohman
574031e4d2 Avoid unneeded passing by value.
https://github.com/rust-lang-nursery/rust-clippy/wiki#needless_pass_by_value
2017-08-31 12:47:05 -07:00
Dan Gohman
b6641ff443 Avoid clone() on a Copy type.
https://github.com/rust-lang-nursery/rust-clippy/wiki#clone_on_copy
2017-08-31 12:47:05 -07:00
Dan Gohman
105998944e Avoid redundant borrows.
https://github.com/rust-lang-nursery/rust-clippy/wiki#needless_borrow
2017-08-31 12:47:05 -07:00
Dan Gohman
9a8f01b832 Avoid unnecessary '&' in matches.
https://github.com/rust-lang-nursery/rust-clippy/wiki#match_ref_pats
2017-08-31 12:47:05 -07:00
Dan Gohman
b411d01d6d Use [] instead of .get().unwrap().
https://github.com/rust-lang-nursery/rust-clippy/wiki#get_unwrap
2017-08-31 12:47:05 -07:00
Dan Gohman
2efdc0ed37 Update rustfmt to 0.9.0. 2017-08-31 10:44:59 -07:00
Dan Gohman
a0a3401ef1 Don't special-case br_table with an empty table.
Empty br_table tables are very uncommon (they're easy for wasm producers to
optimize away), so we don't need to special-case them.
2017-08-30 15:05:00 -07:00
Dan Gohman
8647b10135 Loop over references to containers instead of using explicit iteration methods.
https://github.com/rust-lang-nursery/rust-clippy/wiki#explicit_iter_loop
2017-08-30 14:52:17 -07:00
Dan Gohman
03698f6bc8 Use slices rather than Vec borrows.
https://github.com/rust-lang-nursery/rust-clippy/wiki#ptr_arg
2017-08-30 14:48:17 -07:00
Dan Gohman
c380df1d04 Eliminate a heap allocation. 2017-08-29 05:44:40 -07:00
Dan Gohman
4afa5df3b6 Remove the last_inst_return field.
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.
2017-08-29 05:09:25 -07:00
Dan Gohman
ea1d053831 Simplify the "am I in unreachable code" predicate.
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.
2017-08-29 03:36:38 -07:00
Dan Gohman
c71d4fc01b Remove a stale comment. 2017-08-29 03:30:22 -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