Commit Graph

36 Commits

Author SHA1 Message Date
Nick Fitzgerald
acf8ad0df7 cranelift_wasm: expose the original Wasm function signature
In the `ModuleEnvironment::declare_signature` callback, also pass the original
Wasm function signature, so that consumers may associate this information with
each compiled function. This is often necessary because while each Wasm
signature gets compiled down into a single native signature, multiple Wasm
signatures might compile down into the same native signature, and in these cases
the original Wasm signature is required for dynamic type checking of calls.
2020-06-01 14:53:10 -07:00
Nick Fitzgerald
01a92aef95 cranelift_wasm: Use the TableIndex type instead of raw u32
About half of the `FuncEnvironment::translate_table_*` methods were using the
`TableIndex` newtype, while the other half were using raw `u32`s. This commit
makes everything use `TableIndex`.
2020-06-01 14:53:10 -07:00
Alex Crichton
65e32b3660 Store module name on wasmtime_environ::Module (#1309)
* Store module name on `wasmtime_environ::Module`

This keeps all name information in one place so we dont' have to keep
extra structures around in `wasmtime::Module`.

* rustfmt
2020-03-13 17:51:10 -05:00
Alex Crichton
3179dcf6f1 Update Cranelift's documentation after the merger. (#1238)
Update the documentation for the merger, and also for various changes in
Cranelift. Remove some old obsolete documentation, and convert the remaining
Sphinx files to Markdown. Some of the remaining content is still out of
date, but this is a step forward.
2020-03-05 15:51:12 -06:00
Alex Crichton
8597930eed rename PassiveElemIndex to ElemIndex and same for PassiveDataIndex (#1188)
* rename PassiveElemIndex to ElemIndex and same for PassiveDataIndex (#1411)

* rename PassiveDataIndex to DataIndex

* rename PassiveElemIndex to ElemIndex

* Apply renamings to wasmtime as well

* Run rustfmt

Co-authored-by: csmoe <csmoe@msn.com>
2020-03-02 08:55:25 -06:00
Josh Triplett
5e05aa1b03 Update to wasmparser 0.51
wasmparser::BinaryReaderError now encapsulates its fields, so call the
accessors rather than destructuring to get the fields.
2020-02-22 21:26:27 -08:00
Nick Fitzgerald
9b3ac10ebc wasm: Add support for passive data and element segments (#1389)
This is part of the bulk memory and reference types proposals.
2020-02-15 14:53:32 -08:00
Ryan Hunt
41f225804b Wasm: Allow environment to translate some global.set/get operations
Spidermonkey will need to emit pre/post barriers for global.set/get to a
reference type. #1176 and #1299 plan to add a template concept that could
be used to implement this. Once that has been stabilized, we should be able
to remove this code in favor of templates easily.
2020-01-23 13:37:11 -06:00
Ryan Hunt
f41bf5ecca Wasm: Use environment to translate reference types instructions and add support for multiple tables
This commit introduces environment functions to handle the translation of
reference type instructions, analogous to how bulk-memory was implemented.

Additionally, the bulk-memory instructions that operate on tables are extended
to support multiple table indices.
2020-01-23 13:37:11 -06:00
Alex Crichton
1266b68f9a Use is_wasm_parameter in translating wasm calls (#1352)
* Use `is_wasm_parameter` in translating wasm calls

Added in #1329 it's now possible for multiple parameters to be non-wasm
parameters, so the previous `param_types` method is no longer suitable
for acquiring all wasm-related parameters, rather then `FuncEnvironment`
must be consulted. This removes usage of `param_types()` as a method
from the wasm translation and instead adds a custom method inline for
filtering the parameters based on `is_wasm_parameter`.

* Apply feedback

* Run rustfmt

* Don't require `mut`

* Run rustfmt
2020-01-17 12:11:54 -08:00
Dan Gohman
1d504ecf6d Correctly count the number of wasm parameters. (#1337)
* Correctly count the number of wasm parameters.

Following up on #1329, this further replaces `num_normal_params` with a function
which calls `is_wasm_parameter` to correctly count the number of wasm
parameters a function has.

* Move is_wasm_parameter's implementation into the trait.
2020-01-14 11:42:22 -08:00
Andrew Brown
e8c3302bc5 Fix some additional clippy warnings 2020-01-10 08:38:40 -08:00
Dan Gohman
d765677fcc Add a is_wasm_parameter method to the wasm FuncEnvironment. (#1329)
This provides a more flexible way to allow embedding to tell
cranelift-wasm which function parameters are hidden, and which should be
translated as wasm user variables.

This replaces https://github.com/bytecodealliance/cranelift/pull/1086.
2020-01-10 04:40:25 -08:00
Yury Delendik
2c51341888 Add wasm reference/pointers translation. (#1073) 2019-12-06 17:46:03 -06:00
Ryan Hunt
aabf6559a0 Add hooks for implementing bulk-memory-operations (#1258) 2019-12-06 16:13:53 +01:00
Benjamin Bouvier
9080a02e10 Replace CraneStation by bytecodealliance everywhere; (#1221) 2019-11-12 10:09:31 -08:00
Josh Triplett
7e725cf880 Migrate from failure to thiserror
The failure crate invents its own traits that don't use
std::error::Error (because failure predates certain features added to
Error); this prevents using ? on an error from failure in a function
using Error. The thiserror crate integrates with the standard Error
trait instead.
2019-10-30 17:15:09 -07:00
Peter Huene
9f506692c2 Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
2019-10-24 17:20:12 -07:00
Nick Fitzgerald
ca53090f1b cranelift-wasm: Create ModuleTranslationState and polish API a little (#1111)
* cranelift-wasm: replace `WasmTypesMap` with `ModuleTranslationState`

The `ModuleTranslationState` contains information decoded from the Wasm module
that must be referenced during each Wasm function's translation.

This is only for data that is maintained by `cranelift-wasm` itself, as opposed
to being maintained by the embedder. Data that is maintained by the embedder is
represented with `ModuleEnvironment`.

A `ModuleTranslationState` is returned by `translate_module`, and can then be
used when translating functions from that module.

* cranelift-wasm: rename `TranslationState` to `FuncTranslationState`

To disambiguate a bit with the new `ModuleTranslationState`.

* cranelift-wasm: Reorganize the internal `state` module into submodules

One module for the `ModuleTranslationState` and another for the
`FuncTranslationState`.

* cranelift-wasm: replace `FuncTranslator` with methods on `ModuleTranslationState`

`FuncTranslator` was two methods that always took ownership of `self`, so it
didn't really make sense as an object as opposed to two different functions, or
in this case methods on the object that actually persists for a longer time.

I think this improves ergonomics nicely.

Before:

```rust
let module_translation = translate_module(...)?;
for body in func_bodies {
    let mut translator = FuncTranslator::new();
    translator.translate(body, ...)?;
}
```

After:

```rust
let module_translation = translate_module(...)?;
for body in func_bodies {
    module_translation.translate_func(body, ...)?;
}
```

Note that this commit does not remove `FuncTranslator`. It still exists, but is
just a wrapper over the `ModuleTranslationState` methods, and it is marked
deprecated, so that downstream users get a heads up. This should make the
transition easier.

* Revert "cranelift-wasm: replace `FuncTranslator` with methods on `ModuleTranslationState`"

This reverts commit 075f9ae933bcaae39348b61287c8f78a4009340d.
2019-10-11 12:37:17 -07:00
Benjamin Bouvier
5e87996275 [wasm] Make the WasmTypeMap constructor public; (#1125) 2019-10-10 12:19:53 -07:00
Nick Fitzgerald
10be3e4ba8 cranelift-wasm: support multi-value Wasm (#1049)
This commit introduces initial support for multi-value Wasm. Wasm blocks and
calls can now take and return an arbitrary number of values.

The encoding for multi-value blocks means that we need to keep the contents of
the "Types" section around when translating function bodies. To do this, we
introduce a `WasmTypesMap` type that maps the type indices to their parameters
and returns, construct it when parsing the "Types" section, and shepherd it
through a bunch of functions and methods when translating function bodies.
2019-10-02 12:40:35 -07:00
Nick Fitzgerald
8c3072c774 Combine VisibleTranslationState and TranslationState (#1076)
`VisibleTranslationState` was a wrapper around a `TranslationState` that was
meant to public API consumers outside of this crate. However, the internal
`TranslationState` and all its methods were still publicly exposed! This commit
simplifies and remedies the situation by combining them into a single
`TranslationState` type. Most of its methods are only `pub(crate)` now, not
visible to the entire world. The only methods that are `pub` are the ones that
`VisibleTranslationState` exposed.
2019-09-25 13:07:54 -06:00
Anthony Ramine
eeb3159fe9 Make wasm_unsupported be composeable 2019-09-23 10:36:03 +02:00
data-pup
ac2ca6116b allow module environment to parse name section 2019-09-10 11:30:54 +02:00
Alex Crichton
705bfacf10 rustfmt 2019-09-07 16:20:23 -07:00
Alex Crichton
dfda794f55 Add a custom section hook to ModuleEnvironment
This commit adds a hook to the `ModuleEnvironment` trait to learn when a
custom section in a wasm file is read. This hook can in theory be used
to parse and handle custom sections as they appear in the wasm file
without having to re-iterate over the wasm file after cranelift has
already parsed the wasm file.

The `translate_module` function is now less strict in that it doesn't
require sections to be in a particular order, but it's figured that the
wasm file is already validated elsewhere to verify the section order.
2019-09-07 16:20:23 -07:00
Carmen Kwan
19257f80c1 Add reference types R32 and R64
-Add resumable_trap, safepoint, isnull, and null instructions
-Add Stackmap struct and StackmapSink trait

Co-authored-by: Mir Ahmed <mirahmed753@gmail.com>
Co-authored-by: Dan Gohman <sunfish@mozilla.com>
2019-08-16 11:35:16 -07:00
Adam C. Foltzer
73670aab43 Return a WasmResult from ModuleEnvironment methods (#886)
* [wasm] return a WasmResult from `declare_table_elements`

This method in particular needs to accommodate failure because any table index other than zero is
currently invalid.

* [wasm] additional failure handling improvements

- Adds `WasmResult<()>` as the return type for most of the `ModuleEnvironment` methods that
previously returned nothing.

- Replaces some panics with `WasmError::Unsupported` now that the methods can return a result.

- Adds a `wasm_unsupported!()` macro for early returns with a formatted unsupported message.
2019-08-07 13:23:32 -07:00
iximeow
3d42753535 add VisibleTranslationState for a public-friendly interface 2019-07-31 12:15:51 +02:00
Andy Wortman
b5cb8556f6 [wasm] Pass translation state along for before/after_translate_operator callbacks (#879) 2019-07-30 16:32:50 +02:00
Andy Wortman
b7a9d65458 cranelift-wasm hooks to instrument wasm operators (#861)
* cranelift-wasm hooks to instrument wasm operators
2019-07-25 09:36:17 -07:00
Benjamin Bouvier
a0ddbf403c [wasm] Have the WasmError::User member be a String; 2019-05-14 18:34:16 +02:00
Benjamin Bouvier
3ce5d2057d [wasm] Add the ability to provide a user-defined error; 2019-04-30 13:58:18 +02:00
Benjamin Bouvier
02e114cf3d [wasm] Make FuncEnvironment functions fallible (fixes #752); 2019-04-30 13:58:18 +02:00
Yury Delendik
27b0933a4a Preserve global wasm module offset in SourceLoc. 2019-03-05 14:51:40 +01:00
lazypassion
747ad3c4c5 moved crates in lib/ to src/, renamed crates, modified some files' text (#660)
moved crates in lib/ to src/, renamed crates, modified some files' text (#660)
2019-01-28 15:56:54 -08:00