summaryrefslogtreecommitdiff
path: root/src/interp/interp.cc
Commit message (Collapse)AuthorAgeFilesLines
* interp: Implement EHv4 (#2512)Soni L.2024-11-201-2/+15
| | | Continuation of #2470
* binary/wat: Implement EHv4 (#2470)Soni L.2024-11-201-0/+2
| | | | This pull request implements EHv4. Binary is mostly untested until interp is working.
* Add support for the custom-page-sizes proposal (#2502)Keith Winstein2024-11-081-2/+8
| | | | This adds support in the binary/text parsers and writers, the validator and interpreter, and objdump (but not wasm2c).
* Update testsuite (#2495)Keith Winstein2024-10-301-0/+8
| | | | | The memory64 `table.wast` test has started to depend on function-references and gc (which WABT doesn't support yet), so vendor an older version of the test.
* interp: Handle ref.null exn (#2497)Soni L.2024-10-291-0/+5
|
* wasm-interp: Fix off-by-one in DoThrow (#2486)Soni L.2024-10-081-1/+2
|
* [wasm-interp] Fix memory corruption with recursive call_indirect (#2464)Soni L.2024-09-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The interpreter could overflow the stack without trapping properly in `call_indirect` situations. While it would set the `out_trap` to the trap reason, it would return `RunResult::Ok` and the interpreter code would only check `RunResult::Ok` to decide whether or not to keep running. In other words, while the stack overflow meant the interpreter wouldn't push a frame onto the call stack, the interpreter loop would continue advancing instructions, resulting in instructions after the runaway `call_indirect` running. If the offending `call_indirect` didn't have return values, it would be as if the call returned normally. If it did have return values, nothing would be pushed onto the value stack, yet the return types would be pushed onto the type stack. With careful manipulation of the following instructions, this could be used to cause all sorts of memory corruption. As it turns out, the function exit code, as well as a handful of other instructions, do check the state of the value and type stacks and can safely reproduce the bug without the memory corruption, so that's what we made the test do. The obvious fix was to make `call_indirect` propagate `RunResult::Trap` properly. Additionally, we made it so `assert_exhaustion` checks both the `RunResult` *and* the `out_trap`, and asserts if they don't match. This should help catch similar bugs in the future. Closes #2462 Fixes #2398
* Update testsuite and implement table64 (#2418)Sam Clegg2024-05-151-46/+62
| | | | | See https://github.com/WebAssembly/memory64/issues/51 Includes workaround for #2422
* Update testsuite and corresponding update to comment parser (#2416)Sam Clegg2024-05-131-4/+4
| | | | | | | The main change here is because `comments.wast` was updated to include a "quoted" module at the top level. Previously quoted modules had only been used as part of invalid or malformed assertion expressions.
* Share reading/validation code between elem exprs & other const exprs (#2288)Keith Winstein2023-09-061-10/+10
| | | | | | This continues the work from #1783 and reduces special handling of elem exprs, by treating them the same as other const expressions (init expressions).
* Replace MakeUnique with c++14 std::make_unique (#2152)Keith Winstein2023-02-271-7/+6
|
* Implement Relaxed SIMD proposal (#1994)Marcus Better2022-11-301-11/+101
| | | | | | | | This adds support for the new opcodes from the Relaxed SIMD proposal (https://github.com/WebAssembly/relaxed-simd) behind the "--enable-relaxed-simd" flag. The exception is the f32x4.relaxed_dot_bf16x8_add_f32x4 instruction which is not yet implemented.
* Convert type checks to assertions in the interpreter. NFC (#2055)Sam Clegg2022-11-111-10/+11
| | | | | | | | All of these checks represent cases where a validation error would prevent the type mismatch. When debugging #2054 this check actually worked against me since it was resulting a false-positive "out-of-bound" error reports when really it was an internal type inconsistency (a bug).
* Move headers to include/wabt/ (#1998)Alex Reinking2022-09-281-3/+3
| | | This makes things easier for users and packagers of libwabt.
* Improve the maintenace of ObjectKind types. (#1852)Zoltan Herczeg2022-03-081-2/+5
|
* Rework free list to use less memory. (#1841)Zoltan Herczeg2022-03-021-1/+1
|
* Improve Garbage Collection algorithm (#1830)Zoltan Herczeg2022-02-181-18/+34
| | | | The algorithm is made partially recursive.
* Initial implementation of extended-const proposal. (#1824)Sam Clegg2022-02-151-29/+30
| | | | | | | | | | The primary changes here are to the interpreter and how it handles initializer expressions. With this change we model these are normal function that we run during module initialization. I imagine we could optimize this further by creating one long function and encoding the `global.set`/`memory.init`/`table.init` into the function itself, but this change seems like a good first step to make the current tests pass.
* Fix size of segment in initialization error reporting (#1823)Sam Clegg2022-02-091-2/+10
| | | | | | | | | | | | | | | When data of element segment init fails we were reporting the size, but we were unconditionally calling `Drop` for active segments which meant they always get reported as zero sized in the error message. This mismatch was only showing up with bulk memory enabled (since without this we do a two phase initialization). The only test we have for this error message was using `--disable-bulk-memory`, but not for any good reason (most likely because of this very bug). Also restore the comment about why we sometimes need to do a two phase initialization for element and data segments. This comment was lost in PR #1330 but seem important since I don't think we have any tests for this older behaviour.
* Change Thread in interpreter to a normal object (#1809)Zoltan Herczeg2022-02-041-12/+20
| | | | Improves memory consumption since thread instances are freed without running garbage collector.
* Clang-format codebase (#1684)Heejin Ahn2021-12-201-20/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This applies clang-format to the whole codebase. I noticed we have .clang-format in wabt but the codebase is not very well formatted. This kind of mass-formatting PR has fans and skeptics because it can mess with `git blame`, but we did a similar thing in Binaryen a few years ago (WebAssembly/binaryen#2048, which was merged in WebAssembly/binaryen#2059) and it was not very confusing after all. If we are ever going to format the codebase, I think it is easier to do it in a single big PR than dozens of smaller PRs. This is using the existing .clang-format file in this repo, which follows the style of Chromium. If we think this does not suit the current formatting style, we can potentially tweak .clang-format too. For example, I noticed the current codebase puts many `case` statements within a single line when they are short, but the current .clang-format does not allow that. This does not include files in src/prebuilt, because they are generated. This also manually fixes some comment lines, because mechanically applying clang-format to long inline comments can look weird. I also added a clang-format check hook in the Github CI in #1683, which I think can be less controversial, given that it only checks the diff. --- After discussions, we ended up reverting many changes, especially one-liner functions and switch-cases, which are too many to wrap in `// clang-format off` and `// clang-format on`. I also considered fixing `.clang-format` to allow those one-liners but it caused a larger churn in other parts. So currently the codebase does not conform to `.clang-format` 100%, but we decided it's fine.
* Fix type names for function references (#1787)Sam Clegg2021-12-131-5/+5
| | | | | | | | This requires `Type::GetName` to return to be dynamicllay created and return `std::string` rather then a `const char*` As this diff shows this type name is only used in textual output and error messages so should this change should not have a effect of binary parse time or the interpreter.
* Add specification tests for exception handling proposal (#1764)Asumu Takikawa2021-12-061-1/+6
| | | | | | | | This PR imports the spec tests from the Wasm testsuite repo and adds infrastructure to run them correctly. * Adds test expectations for exception handling proposal spec tests. * Adds missing tag signature matching code for import tests. * Adds support for the `assert_exception` command used in new tests. * Fix filename normalization for the spec test runner.
* Add interpreter support for the exception handling proposal (#1749)Asumu Takikawa2021-11-171-6/+154
| | | | | | | | | | | | | | | | | | | | | Details about the implementation approach: * Try blocks generate metadata tracking the instruction ranges for the handlers and which exception tags are handled (or if a `catch_all` is present). The metadata is stored in a function's `FuncDesc`, and is transferred into the `Frame` when a function call is executed. * The stack is unwound when a `throw` is executed. This unwinding also handles tag dispatch to the appropriate catch. The metadata to find the matching handler is looked up in the call `Frame` stack. * If a `try-delegate` is present, it is used in the stack unwinding process to skip over to the relevant handler. * A separate `exceptions_` stack in call frames tracks caught exceptions that can be accessed via a `rethrow`. The stack is popped on exit from a try block or when exiting via control instructions like `br`. * Because stack unwinding relies on finding metadata in the call frame, `return_call` needs to be modified slightly to adjust the current frame when executing the call, rather than re-using the frame completely as-is.
* Update testsuite (#1738)Sam Clegg2021-10-181-0/+6
| | | | | | | | | | | bulk-memory-operations and reference-types were completely removed from the upstream testsuite becuase there were merged into the upstream spec: https://github.com/WebAssembly/testsuite/pull/44 In order to land this I had to disable several spec tests under wasm2c because it lacks support for mutli-table and reference types. I filed #1737 to track this.
* [simd] Remove unused template params (#1700)Ng Zhi An2021-08-061-6/+5
| | | | Also remove an unused transform, we are applying the unop f in the for loop directly after it.
* [simd] Fix load/store lanes on BE systems (#1697)Ng Zhi An2021-08-051-2/+2
| | | | | | The use of `.v` is incorrect, we should simply use array subscript operator on the Simd type, which takes care of BE systems. For #1670. (Not using fix as I don't have a BE system to verify.)
* Begin support for typed function references proposal: added the flag and ↵Dmitry Bezhetskov2021-07-251-0/+1
| | | | supported call_ref (#1691)
* [EH] Remove `unwind` (#1682)Heejin Ahn2021-06-291-1/+0
| | | `unwind` was removed. See WebAssembly/exception-handling#156.
* [EH] Replace event with tag (#1678)Heejin Ahn2021-06-221-19/+19
| | | | | | | | | | | We recently decided to change 'event' to 'tag', and 'event section' to 'tag section', out of the rationale that the section contains a generalized tag that references a type, which may be used for something other than exceptions, and the name 'event' can be confusing in the web context. See - https://github.com/WebAssembly/exception-handling/issues/159#issuecomment-857910130 - https://github.com/WebAssembly/exception-handling/pull/161
* Memory64: support 64-bit data init-expr (#1656)Wouter van Oortmerssen2021-04-051-3/+6
|
* [simd] Implement store lane (#1647)Ng Zhi An2021-03-221-8/+28
|
* [simd] Implement load lane (#1646)Ng Zhi An2021-03-221-0/+18
| | | | | | | | | This is a new kind of ir/ast node/instruction. It has 3 immediates: memarg align, memarg offset, and lane index. This required new visitor functions in all the places. Drive-by cleanup to share the simd lane parsing logic between shuffle, lane op and this new load lane instructions. This requires rebasing some tests because the error messages are slightly different now.
* [simd] Implement v128.load{32,64}_zero (#1644)Ng Zhi An2021-03-171-0/+17
| | | | This requires a new ir type, and the relevant implementation of virtual mthods in the various visitors.
* [simd] Implement i64x2.extend_{low,high}_i32x4_{s,u} (#1643)Ng Zhi An2021-03-161-0/+4
| | | Unskip and rebase simd_int_to_int_extend.
* [simd] Implement i64x2 comparisons (#1642)Ng Zhi An2021-03-161-0/+6
| | | Rebase and unskip simd_i64x2_cmp.
* [simd] Implement i32x4.dot_i16x8_s (#1640)Ng Zhi An2021-03-161-0/+18
| | | Rebase and unskip simd_i32x4_dot_i16x8.
* [simd] Implement q15mulrsat_s (#1639)Ng Zhi An2021-03-161-0/+2
| | | Rebase and unskip simd_i16x8_q15mulr_sat_s.
* [simd] Implement extmul instructions (#1638)Ng Zhi An2021-03-121-0/+27
| | | | | | | Renumber floating point rounding instructions since they overlap with these new extmul instructions. Rebase simd_f32x4_rounding and simd_f64x2_rounding. Rebase and unskip simd extmul tests.
* [simd] Implement extadd instructions (#1637)Ng Zhi An2021-03-121-0/+18
| | | | Rebase and unskip simd_i16x8_extadd_pairwise_i8x16.txt and simd_i32x4_extadd_pairwise_i16x8.
* [simd] Implement i64x2.abs (#1636)Ng Zhi An2021-03-121-0/+1
| | | Rebase and unskip simd_i64x2_arith2.txt.
* [simd] Implement i32x4.trunc_sat_f64x2_[su]_zero (#1635)Ng Zhi An2021-03-121-0/+2
| | | | Rebase simd_i32x4_trunc_sat_f64x2.txt and simd_i32x4_trunc_sat_f32x4.txt.
* [simd] Rename widen to extend, implement some double precision ops (#1633)Ng Zhi An2021-03-111-10/+32
| | | | | | | | | | | | 4 double precision conversion instructions are implemented: - f32x4.demote_f64x2_zero - f64x2.demote_low_f32x4 - f64x2.convert_low_i32x4_s - f64x2.convert_low_i32x4_u This is now sufficient to unskip simd_conversions.txt. Rebase a bunch of tests due to the rename from widen to extend.
* Implement i8x16.popcnt and rebase simd_i8x16_arith2.txt (#1625)Ng Zhi An2021-03-111-0/+2
|
* [simd] Rename any_true, implement i64x2 bitmask and all_true (#1624)Ng Zhi An2021-03-041-3/+3
| | | | | | | | | | | * Rename all any_true to v128.any_true * Add i64x2.bitmask and i64x2.all_true, rebase simd_boolean * Unskip spec/simd/simd_i16x8_arith2.txt since i64x2.abs is now implemented * Unskip spec/simd/simd_lane.txt * Update dump interp tests, rebase
* Update rethrow depth handling and catch_all opcode (#1608)Asumu Takikawa2021-02-181-0/+1
| | | | | | | | | | | | | Give `catch_all` its own opcode: Previously `catch_all` shared an opcode with `else`, but the spec now allocates it the 0x19 opcode. Adjust rethrow depth semantics: Previously this had interpreted the rethrow depth argument as counting only catch blocks, but the spec has clarified that it should count all blocks (in a similar fashion as `br` and related instructions).
* Update exception handling support to current proposal (#1596)Asumu Takikawa2021-02-101-4/+2
| | | | | | | | | | This PR updates the support of exception handling to the latest proposal (that is compatible with future 2-phase exception handling) described in https://github.com/WebAssembly/exception-handling/pull/137 and https://github.com/WebAssembly/exception-handling/pull/143. * Adds back tagged `catch $e`, `catch_all`, and `rethrow N` from a previous version of wabt, but with updates to match the current spec (e.g., `catch_all` shares an opcode with `else`, `rethrow`'s depth indexes only catch blocks, etc). * Adds `unwind` and `delegate` instructions. * Removes `exnref` and `br_on_exn`. * Updates relevant tests. There are some details that could still change (e.g., maybe how `delegate`'s depth is validated), but I'd be happy to submit further PRs if the spec details change.
* Port to big-endian platforms (s390x but others can be trivially added) (#1557)Soni L2020-12-071-14/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial attempt at s390x port * Second attempt at s390x port * Fix big-endian memory fill * Fix more memory location calculations * Improve SIMD * Implement big-endian memory grow * Fill relocation with 0x00, as per spec * Make wasm2c endianness work * Fix shuffle * Fix load endianness in wasm2c * Refactor into shared code * Clean up SwapBytesSized * Clean up MemcpyEndianAware * Clean up * "Fix" opcodecnt basic test
* Rename atomic.notify, *.atomic.wait (#1564)Ben Smith2020-11-031-3/+3
| | | | | | | | atomic.notify -> memory.atomic.notify i32.atomic.wait -> memory.atomic.wait32 i64.atomic.wait -> memory.atomic.wait64 These were renamed upstream a while ago, but the new names were not added to wabt.
* Changes required to make the new Memory64 spec tests run (#1560)Wouter van Oortmerssen2020-10-261-17/+21
| | | | | These uncovered some things the previous tests didn't! Also required the switching of the location of the index as discussed in https://github.com/WebAssembly/memory64/issues/5 Also one small .py change that ensures the new tests have consistent posix paths.