496 Commits

Author SHA1 Message Date
Alex Crichton
39e57e3e9a Migrate back to std:: stylistically (#554)
* Migrate back to `std::` stylistically

This commit moves away from idioms such as `alloc::` and `core::` as
imports of standard data structures and types. Instead it migrates all
crates to uniformly use `std::` for importing standard data structures
and types. This also removes the `std` and `core` features from all
crates to and removes any conditional checking for `feature = "std"`

All of this support was previously added in #407 in an effort to make
wasmtime/cranelift "`no_std` compatible". Unfortunately though this
change comes at a cost:

* The usage of `alloc` and `core` isn't idiomatic. Especially trying to
  dual between types like `HashMap` from `std` as well as from
  `hashbrown` causes imports to be surprising in some cases.
* Unfortunately there was no CI check that crates were `no_std`, so none
  of them actually were. Many crates still imported from `std` or
  depended on crates that used `std`.

It's important to note, however, that **this does not mean that wasmtime
will not run in embedded environments**. The style of the code today and
idioms aren't ready in Rust to support this degree of multiplexing and
makes it somewhat difficult to keep up with the style of `wasmtime`.
Instead it's intended that embedded runtime support will be added as
necessary. Currently only `std` is necessary to build `wasmtime`, and
platforms that natively need to execute `wasmtime` will need to use a
Rust target that supports `std`. Note though that not all of `std` needs
to be supported, but instead much of it could be configured off to
return errors, and `wasmtime` would be configured to gracefully handle
errors.

The goal of this PR is to move `wasmtime` back to idiomatic usage of
features/`std`/imports/etc and help development in the short-term.
Long-term when platform concerns arise (if any) they can be addressed by
moving back to `no_std` crates (but fixing the issues mentioned above)
or ensuring that the target in Rust has `std` available.

* Start filling out platform support doc
2019-11-18 22:04:06 -08:00
Dan Gohman
061b453255 Remove unneeded extern crate, macro_use, and tidy uses. 2019-11-08 17:55:38 -08:00
Dan Gohman
1a0ed6e388 Use the more-asserts crate in more places.
This provides assert_le, assert_lt, and so on, which can print the
values of the operands.
2019-11-08 15:24:53 -08:00
Alex Crichton
ae86822c37 Move stray top-level misc_testsuite to tests (#528)
I think this may have been a mistake from #523?
2019-11-08 17:03:10 -06:00
Dan Gohman
9af562c1ff Update dependencies. 2019-11-08 10:48:50 -08:00
Dan Gohman
b158666f2b Reorganize tests.
- Move spec_testsuite and misc_testsuite under the tests directory.
 - Remove some redundant tests from filetests.
 - Move wat tests to wat/tests.
2019-11-08 10:31:44 -08:00
Alex Crichton
59b15eab13 Simplify #[test] generation for *.wast files (#507)
This commit simplifies the build script slightly for generating tests by
doing a few dull refactorings:

* Leaves formatting to `rustfmt`
* Extract bulk of code execution into a top-level shared `run_wast`
  function so each test is a one-liner
* Use `anyhow` for errors both in the script and in tests
2019-11-07 17:01:17 -06:00
Alex Crichton
9947bc5209 Switch from wabt crate to wast (#434)
* Switch lightbeam from `wabt` to `wast`

Switch from a C++-based `*.wat` parser to a Rust-based parser

* Remove unneeded `wabt` dev-dependency from wasmtime-api

* Rewrite `wasmtime-wast` crate with `wast-parser`

This commit moves the `wasmtime-wast` crate off the `wabt` crate on to
the `wast-parser` crate which is a Rust implementation of a `*.wast` and
`*.wat` parser. The intention here is to continue to reduce the amount
of C++ required to build wasmtime!

* Use new `wat` and `wast` crate names
2019-10-18 13:25:48 -07:00
Dan Gohman
8e1b44b29c Make more code work with no_std. (#407)
* Make more code work with no_std.

no_std support is still incomplete, but this patch takes care of the
bulk of the straightforward parts.
2019-10-08 16:53:32 -07:00
Dan Gohman
65b8afabe6 Make use of Lightbeam configurable.
This adds a `--always-lightbeam` option as well as an `--always-cranelift`
option, to allow the compilation strategy to be selected via the
command-line. This also enables regular testing for Lightbeam.
2019-10-02 11:54:06 -07:00
Andrew Brown
ce8e8662ff Enable SIMD in WAST testsuites 2019-09-26 15:46:18 -07:00
Artur Jamro
286d2515f9 Check trap code in test suite assertions 2019-09-26 11:43:41 -07:00
Yury Delendik
ddbc00752e Generate debug info for LLDB/GDB (#50)
* Transform DWARF sections into native format for wasm2obj and wasmtime.

Generate DWARF sections based on WASM DWARF.
Ignore some of debug_info/debug_line for dead code.

* Fix test
2019-03-06 16:03:32 -08:00
Dan Gohman
ddb8453b0d Move wasmtime's instantiation test into a separate file. 2019-02-01 18:20:59 -08:00
Dan Gohman
f6c2fe7d2d Update to Rust 2018 Edition. 2019-01-03 12:58:11 -08:00
Dan Gohman
7592c99f3b Refactor the compilation and instantiation pipeline.
wasmtime-execute is now wasmtime-jit. Move `JITCode` and the TargetIsa
into a new `Compiler` type. `InstancePlus` is no more, with trampoline
functionality now handled by `Compiler`.
2019-01-03 11:47:55 -08:00
Dan Gohman
3f24098edc Implement the remaining valid spec tests.
And lots of other miscellaneous changes. Rename InstanceWorld to
InstancePlus and reorganize its contents. This still isn't a great name,
but at least now it has a clear purpose.
2018-12-12 11:49:02 -08:00
Dan Gohman
83f8a31010 Convert the wast test harness into a crate.
This uses a build.rs file to collect all the wast tests and create
individual `#[test]` lines for them, so that `cargo test` can run them
in parallel.
2018-12-05 02:25:34 -05:00
Dan Gohman
bd69768e0d Improve infrastructure.
Do more encapsulation of raw pointers, use more PrimaryMaps instead of
Vecs, add a table.rs for managing table storage.
2018-12-05 02:25:34 -05:00
Dan Gohman
8dbd4b8d7c Start a wast testing harness and add some tests.
This implements a minimal wast testing harness in tests/wast.rs, which
runs the wast tests under tests/wast.

It also adds tests for trapping in a variety of ways, and fixes several
bugs exposed by those tests.
2018-12-05 02:25:34 -05:00
Dan Gohman
d0fe50a2a8 Check in the wasmstandalone code.
This is based on the code in https://github.com/denismerigoux/cretonne/commits/wasm2cretonne
before wasmstandalone was removed, with minor updates for the new library structure.
It is not yet updated for the latest cretonne API changes.
2017-09-05 17:06:51 -07:00
Jakob Stoklund Olesen
7f3b807597 Add a calling convention to all function signatures.
A CallConv enum on every function signature makes it possible to
generate calls to functions with different calling conventions within
the same ISA / within a single function.

The calling conventions also serve as a way of customizing Cretonne's
behavior when embedded inside a VM. As an example, the SpiderWASM
calling convention is used to compile WebAssembly functions that run
inside the SpiderMonkey virtual machine.

All function signatures must have a calling convention at the end, so
this changes the textual IL syntax.

Before:

    sig1 = signature(i32, f64) -> f64

After

    sig1 = (i32, f64) -> f64 native
    sig2 = (i32) spiderwasm

When printing functions, the signature goes after the return types:

    function %r1() -> i32, f32 spiderwasm {
    ebb1:
        ...
    }

In the parser, this calling convention is optional and defaults to
"native". This is mostly to avoid updating all the existing test cases
under filetests/. When printing a function, the calling convention is
always included, including for "native" functions.
2017-08-03 11:40:24 -07:00
Aleksey Kuznetsov
8b484b1c77 Binary function names (#91)
* Function names should start with %

* Create FunctionName from string

* Implement displaying of FunctionName as %nnnn with fallback to #xxxx

* Run rustfmt and fix FunctionName::with_string in parser

* Implement FunctionName::new as a generic function

* Binary function names should start with #

* Implement NameRepr for function name

* Fix examples in docs to reflect that function names start with %

* Rebase and fix filecheck tests
2017-06-10 10:30:37 -07:00
Jakob Stoklund Olesen
22ad3c0bf8 Compute a CFG post-order when building the dominator tree.
The DominatorTree has existing DomNodes per EBB that can be used in lieu
of expensive HastSets for the depth-first traversal of the CFG.

Make the computed and cached post-order available for other passes
through the `cfg_postorder()` method which returns a slice.

The post-order algorithm is essentially the same as the one in
ControlFlowGraph::postorder_ebbs(), except it will never push a
successor node that has already been visited once. This is more
efficient, but it generates a different post-order.

Change the cfg_traversal tests to check this new algorithm.
2017-06-02 16:39:18 -07:00
Jakob Stoklund Olesen
8353651559 rustfmt 0.8.1 2017-04-05 09:00:11 -07:00
Jakob Stoklund Olesen
f84e218a93 Rename the 'cfg' module to 'flowgraph'.
The 'cfg' name was easy to confuse with 'configuration'.
2017-03-21 15:33:23 -07:00
Jakob Stoklund Olesen
32709a56ca Upgrade to rustfmt 0.8.0.
Lots of changes this time.

Worked around what looks like a rustfmt bug in parse_inst_operands where
a large match was nested inside Ok().
2017-03-14 10:48:05 -07:00
Jakob Stoklund Olesen
0f29fc7a52 Make the ControlFlowGraph reusable.
Move the flow graph computation into a compute method which can be
called with multiple functions.

This allows us to reuse the ControlFlowGraph memory and keep an instance
in the Context.
2017-02-17 12:20:33 -08:00
Jakob Stoklund Olesen
893a630ca0 Upgrade to rustfmt 0.6.3 2016-12-21 10:06:49 -08:00
Jakob Stoklund Olesen
a8a79df620 Promote the src/tools crate to the top-level workspace.
The 'src' and 'tests' top-level directories now contain tools sources
and integration tests for any of the library crates.
2016-10-17 15:04:29 -07:00
Jakob Stoklund Olesen
78a2e47d95 Implement the 'test print-cfg' sub-test.
Move the CFG tests into the filetests directory.

Remove the tests directory, there are no more shell-driven tests left.
2016-09-15 17:21:56 -07:00
Jakob Stoklund Olesen
0b7f87b14c Convert parser tests to filetests.
Create a new directory hierarchy under 'filetests' for all the tests
that are run by 'cton-util test'.

Convert the parser tests under 'tests/parser' to use 'test cat' and
filecheck directives.
2016-09-15 15:50:47 -07:00
Jakob Stoklund Olesen
8483dc1085 Add an explainer mode to filecheck.
The -c flag to 'cton-util filecheck' will now print out a description of how
the directives are matching the input.

This explanation is also printed when a match fails.
2016-09-09 17:08:29 -07:00
Jakob Stoklund Olesen
e41853cab0 Convert the DFG tests to use filecheck. 2016-09-09 11:09:54 -07:00
Jakob Stoklund Olesen
20fc675fc0 Parse the BranchTable instruction format.
Resolve the jump table reference immediately since all jump tables are declared
in the preamble.
2016-07-22 15:16:14 -07:00
Jakob Stoklund Olesen
274671d12a Implement jump tables.
- Add a ir::jumptable module with a JumpTableData struct representing the vector
  of destinations.
- Add an entity map of jump tables to the Function.
- Parse and write jump tables in the function preamble.
- Rewrite EBB references in jumptables after parsing.
2016-07-22 14:48:53 -07:00
Morgan Phillips
5bcce51bd9 Add print-cfg tests 2016-07-14 13:43:11 -07:00
Jakob Stoklund Olesen
ad5e6b14cf Add tests for parsing call and return. 2016-07-08 16:28:19 -07:00
Jakob Stoklund Olesen
a39e418d32 Rewrite EBB and value references after parsing.
We llow forward references to values and EBBs, so it is not possible to rewrite
these from the source domain to the in-memory domain during parsing.

Instead go through all the instructions after parsing everything and rewrite the
value and EBB references when everything has been created and mapped.
2016-07-08 15:15:53 -07:00
Jakob Stoklund Olesen
4a929f5e41 Add meta definition for bitcast.
This instruction uses two type variables: input and output. Make sure that our
parser can handle it. The output type variable annotation is mandatory.

Add a ValueTypeSet::example() method which is used to provide better diagnostics
for a missing type variable.
2016-07-07 14:01:00 -07:00
Jakob Stoklund Olesen
86688053a6 Define icmp and fcmp comparison instructions.
Add new intcc and floatcc operand types for the immediate condition codes on
these instructions.

Add new IntCompare and FloatCompare instruction formats.

Add a generic match_enum() parser function that can match any identifier-like
enumerated operand kind that implements FromStr.

Define the icmp and fcmp instructions in case.py. Include documentation for the
condition codes with these two instructions.
2016-07-07 11:43:12 -07:00
Jakob Stoklund Olesen
a6c1362975 Parse insertlane and extractlane instruction formats.
These instruction formats take immediate lane index operands. We store these as
u8 fields and require them to be in decimal format in the source. No hexadecimal
lane indexes are supported.
2016-07-06 13:36:15 -07:00
Jakob Stoklund Olesen
e5feb864c7 Parse select instructions. 2016-07-05 16:51:26 -07:00
Jakob Stoklund Olesen
cdc2638f96 Parse branch and jump instructions.
These instruction formats take EBB references with lists of argument values. For
EBBs with no arguments, the argument value list may be omitted.
2016-07-05 15:23:42 -07:00
Jakob Stoklund Olesen
a82554192a Print a type suffix on some polymorphic instructions. 2016-07-05 13:45:15 -07:00
Jakob Stoklund Olesen
954fd015e0 Add very basic test framework for parser tests.
Start with a shell script that runs .cton files through 'cton-util cat' and
compares the output to a reference. This can get fancy later.
2016-07-05 12:51:02 -07:00