summaryrefslogtreecommitdiff
path: root/test/wasm2asm
Commit message (Collapse)AuthorAgeFilesLines
* Rename `wasm2asm` to `wasm2js`, emit ESM by default (#1642)Alex Crichton2018-08-3069-118563/+0
| | | | | | | | | | | | | | | | | | | | | | | | * Rename the `wasm2asm` tool to `wasm2js` This commit performs a relatively simple rename of the `wasm2asm` tool to `wasm2js`. The functionality of the tool doesn't change just yet but it's intended that we'll start generating an ES module instead of just an `asm.js` function soon. * wasm2js: Support `*.wasm` input files Previously `wasm2js` only supported `*.wast` files but to make it a bit easier to use in tooling pipelines this commit adds support for reading in a `*.wasm` file directly. Determining which parser to use depends on the input filename, where the binary parser is used with `*.wasm` files and the wast parser is used for all other files. * wasm2js: Emit ESM imports/exports by default This commit alters the default behavior of `wasm2js` to emit an ESM by default, either importing items from the environment or exporting. Items like initialization of memory are also handled here.
* wasm2asm: Fix and enable a large number of spec tests (#1558)Alex Crichton2018-05-2957-613/+61314
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Import `abort` from the environment * Add passing spec tests * Bind the abort function * wasm2asm: Fix name collisions Currently function names and local names can collide in namespaces, causing buggy results when a function intends to call another function but ends up using a local value as the target! This fix was required to enable the `fac` spec test * wasm2asm: Get multiple modules in one file working The spec tests seem to have multiple modules defined in some tests and the invocations all use the most recently defined module. This commit updates the `--allow-asserts` mode of wasm2asm to work with this mode of tests, enabling us to enable more spec tests for wasm2asm. * wasm2asm: Enable the float_literals spec test This needed to be modified to account for how JS engines don't work with NaN bits the same way, but it's otherwise largely the same test. Additionally it turns out that asm.js doesn't accept either `Infinity` or `NaN` ambient globals so they needed to get imported through the `global` variable rather than defined as literals in code * wasm2asm: Fix function pointer invocations This commit fixes invocations of functions through function pointers as previously the table names on lookup and definition were mismatched. Both tables now go through signature-based namification rather than athe name of the type itself. Overall this enables a slew of spec tests * wasm2asm: Enable the left-to-right spec test There were two small bugs in the order of evaluation of operators with wasm2asm. The `select` instruction would sometimes evaluate the condition first when it was supposed to be last. Similarly a `call_indirect` instruction would evaluate the function pointer first when it was supposed to be evaluated last. The `select` instruction case was a relatively small fix but the one for `call_indirect` was a bit more pessimized to generate some temporaries. Hopefully if this becomes up a problem it can be tightened up. * wasm2asm: Fix signed load promotions of 64-bit ints This commit enables the `endianness` spec test which revealed a bug in 64-bit loads from smaller sizes which were signed. Previously the upper bits of the 64-bit number were all set to zero but the fix was for signed loads to have all the upper bits match the highest bit of the low 32 bits that we load. * wasm2asm: Enable the `stack` spec test Internally the spec test uses a mixture of the s-expression syntax and the wat syntax, so this is copied over into the `wasm2asm` folder after going through `wat2wasm` to ensure it's consistent for binaryen. * wasm2asm: Fix unaligned loads/stores of floats Replace these operations in `RemoveNonJSOps` by using reinterpretation to translate floats to integers and then use the existing code for unaligned loads/stores of integers. * wasm2asm: Fix a tricky grow_memory codegen bug This commit fixes a tricky codegen bug found in the `grow_memory` instruction. Specifically if you stored the result of `grow_memory` immediately into memory it would look like: HEAP32[..] = __wasm_grow_memory(..); Here though it looks like JS evaluates the destination *before* the grow function is called, but the grow function will invalidate the destination! Furthermore this is actually generalizable to all function calls: HEAP32[..] = foo(..); Because any function could transitively call `grow_memory`. This commit fixes the issue by ensuring that store instructions are always considered statements, unconditionally evaluating the value into a temporary and then storing that into the destination. While a bit of a pessmimization for now it should hopefully fix the bug here. * wasm2asm: Handle offsets in tables This commit fixes initializing tables whose elements have an initial offset. This should hopefully help fix some more Rust code which has all function pointers offset by default! * Update tests * Tweak * location on types * Rename entries of NameScope and document fromName * Comment on lowercase names * Update compiled JS * Update js test output expectation * Rename NameScope::Global to NameScope::Top * Switch to `enum class` * Switch to `Fatal()` * Add TODO for when asm.js is no longer generated
* wasm2asm: Finish i64 lowering operations (#1563)Alex Crichton2018-05-2511-230/+2433
| | | | | | | | | | | | | | | | | * wasm2asm: Finish i64 lowering operations This commit finishes out lowering i64 operations to JS with implementations of division and remainder for JS. The primary change here is to have these compiled from Rust to wasm and then have them "linked in" via intrinsics. The `RemoveNonJSOps` pass has been updated to include some of what `I64ToI32Lowering` was previously doing, basically replacing some instructions with calls to intrinsics. The intrinsics are now all tracked in one location. Hopefully the intrinsics don't need to be regenerated too much, but for posterity the source currently [lives in a gist][gist], although I suspect that gist won't continue to compile and work as-is for all of time. [gist]: https://gist.github.com/alexcrichton/e7ea67bcdd17ce4b6254e66f77165690
* wasm2asm: Finish f32/f64 operations (#1554)Alex Crichton2018-05-1922-946/+1265
|
* wasm2asm: Implement float<->int conversions (#1550)Alex Crichton2018-05-164-1/+841
| | | | | | | | | This commit lifts the same conversion strategy that `emcc` takes to convert between floats point numbers and integers, and it should implement all the various matrices of i32/u32/i64/u64 to f32/f64 Some refactoring was performed in the i64->i32 pass to allow for temporary variables to get allocated which have types other than i32, but otherwise this contains a pretty direct translation of `emcc`'s operations to `wasm2asm`.
* wasm2asm: Implement f32/f64.copysign (#1551)Alex Crichton2018-05-152-0/+35
| | | | | | This commit implements the `copysign` instruction for the wasm2asm binary. The implementation here is a new pass which wholesale replaces `copysign` instructions with the equivalent bit ops and reinterpretation instructions. It's intended that this matches Emscripten's implementation of lowering here.
* In full-printing mode, print comments for control flow endings, to help ↵Alon Zakai2018-05-141-0/+3
| | | | | | | | | | | readability (#1552) Like this: (block $x .. ) ;; end block $x Also fix some current breakage on master.
* wasm2asm: Add math aliases for floor, ceil and sqrt (#1549)Daniel Wirtz2018-05-1416-1/+102
|
* Implement 64-bit rotation lowering for wasm2asm (#1545)Alex Crichton2018-05-142-0/+215
| | | | Not much fancy here, but rather each operation is naively lowered inline to the if/else chain to execute it.
* wasm2asm: Implement reinterpretation instructions (#1547)Alex Crichton2018-05-132-0/+101
| | | | | | | | | | | | | As mentioned in #1458 a naive implementation of these instructions is to round trip the value through address 0 in linear memory. Also pointed out in #1458 this isn't necessarily valid for all languages. For now, though, languages like Rust, C, and C++ would likely be horribly broken if valid data could be stored at low addresses, so this commit goes ahead and adds an implementation of the reinterpretation instructions by traveling data through address 0. This will likely need an update if a language comes a long which can validly store data in the first 8 bytes of linear memory, but it seems like that won't happen in the near future. Closes #1458
* Clean up wasm2asm testing (#1546)Alon Zakai2018-05-1315-0/+51905
| | | | | * Move wasm2asm test outputs into their natural location, test/wasm2asm/ * Let people create new tests in there that ./auto_update_tests.py will auto-generate outputs for, just like all the other tests.
* Implement signed 64-bit shift right for wasm2asm (#1544)Alex Crichton2018-05-121-0/+81
| | | | Mostly piggy-back pon the previous 64-bit shift lowering code, just filling in a few gaps.
* remap {get,set}_local indices (#1486)Nathan Froyd2018-03-231-0/+27
| | | | | | | | | | When lowering i64 values in a function, we create new local variables for all of the i64 local variables, one local for the low bits, and one for the high bits. We create a mapping between the old locals and the new as well. During translation, when we encountered a `get_local` that didn't have type `i64`, we skipped it, on the supposition that there was nothing to do. But that's not true; the local it was getting may have been remapped to a new index in the lowered function, and we need to account for that change. Similar logic holds for `set_local`.
* fix and implement more unary ops (#1442)Nathan Froyd2018-02-261-0/+145
| | | | | | | | | | | | | | | | | | * add tests for i32.popcnt * lower i64.popcnt * add tests for i64.extend_u/i32 * lower i64.extend_s/i32 * fix lowering i64.eqz * lower i64.eqz more efficiently * add tests for i32.clz/i32.ctz * lower i64.clz/i64.ctz
* better handling of float ops in wasm2asm (#1427)Nathan Froyd2018-02-151-0/+84
| | | | | | | | | | | | | | | | | | | | * explicitly handle binary float operations in processFunctionBody We weren't handling them before, but it wasn't obvious. Make the (non-) handling of them explicit in the code. We'll add handlers for them shortly. * add handling for simple binary float operations min, max, and copysign will require more sophisticated handling. * add handling for float comparisons * move float min/max handling to the correct place It was previously grouped with the i32 ops. * handle float promotion and demotion
* implement lowering for i64 subtraction (#1429)Nathan Froyd2018-02-141-0/+66
| | | | | | | | | * fix lowering of i64 adds We're not permitted to reuse the input as temporary variables for the results. Weird things happen otherwise. * add support for lowering i64 subtraction
* add wasm2asm lowering for 64-bit signed comparisons (#1421)Nathan Froyd2018-02-141-0/+269
| | | Plus some tests, to make sure we implemented things correctly.
* Update call_indirect text syntax to match spec update (#1281)Derek Schuff2017-11-131-4/+4
| | | | Function type gets its own element rather than being a part of the call_indirect (see WebAssembly/spec#599)
* i64 to i32 lowering for wasm2asm (#1134)Thomas Lively2017-09-011-0/+1468