29 Commits

Author SHA1 Message Date
f622b8e47c Use new wast parser in wasm2js (#6606)
When generating assertions, traverse the `WASTScript` data structure rather than
interleaving assertion parsing with emitting.
2024-05-29 10:35:25 -07:00
f92350d294 wasm2js: Stop emitting nan and infinity (#5391)
As noted in #4739, legacy language emitting nan and infinity
exists, with the observation that it can be removed once asm.js
is no longer used and global NaN is available.

This commit removes that asm.js-specific code accordingly.
2023-01-04 15:02:14 -08:00
c43721a1ae wasm2js: Support for flexible module import naming (#5114)
The previous code was making emscripten-specific assumptions about
imports basically all coming from the `env` module.

I can't find a way to make this backwards compatible so may do a
combined roll with the emscripten-side change:
https://github.com/emscripten-core/emscripten/pull/17806
2022-10-05 15:18:22 -07:00
d797c751df wasm2js: Don't assume that env.abort can always be impored. (#5049)
This import was being injected and then used to implement trapping.
Rather than injecting an import that doesn't exist in the original
module we instead use the existing mechanism to implement this as
an internal helper.
2022-09-16 09:33:08 -07:00
64f9732c40 wasm2js: Have instantiate function take standard import object (#5018)
Previously we were assuming asmLibraryArg which is what emscripten
passes as the `env` import object but using this method is more
flexible and should allow wasm2js to work with import that are
not all form a single object.

The slight size increase here is just temporary until emscripten
gets updated.

See https://github.com/emscripten-core/emscripten/pull/17737
2022-09-14 19:36:37 +00:00
236296d856 [wasm2js] Use native JavaScript Math.trunc (#3329) 2020-11-10 13:04:16 -08:00
040a7cc372 wasm2js: Remove global dict arguments to asmFunc (#3325) 2020-11-05 16:10:10 -08:00
f61ec303bc wasm2js: Skip heap creation in the absence of wasm memory. NFC (#3167)
Also, format the asmFunc call to make it more readable in the ES6
modules case.
2020-09-24 14:34:05 -07:00
ee00f64775 wasm2js: Support exported tables (#3152) 2020-09-21 16:39:46 -07:00
8d13b5a9c5 Stop emitting "almost asm" in wasm2js output (#2221)
We don't ever emit "use asm" anymore, so this similar annotation is not really useful, it just increases size.
2019-07-12 13:46:03 -07:00
e54b1d3bf6 wasm2js: optimize away unneeded load coercions (#2107) 2019-05-15 11:04:20 -07:00
415e8b37c2 wasm2js: optimize loads (#2085)
When loading a boolean, prefer the signed heap (which is more commonly used, and may be faster).
We never use HEAPU32 (HEAP32 is always enough), just remove it.
2019-05-03 13:47:49 -07:00
80b509cfb8 wasm2js: don't emit obviously unnecessary parens (#2080)
A minifier would probably remove them later anyhow, but they make reading the code annoying and hard.
2019-05-02 16:40:20 -07:00
af459403bc wasm2js: don't run coalesce-locals if not optimizing (#2076)
That pass is very slow on unoptimized code (super-linear on the number of locals, which if unoptimized can be massive due to flatten).
2019-05-01 17:18:04 -07:00
73709b4da0 wasm2js: run more optimizations (#2073)
In particular, coalesce-locals is useful even if closure is run later (apparently it finds stuff closure can't).
2019-05-01 10:43:01 -07:00
8d4bcd6e02 wasm2js: run full optimizations during the pipeline (#2071)
We flatten for the i64 lowering etc. passes, and it is worth optimizing afterwards, to clean up stuff they created. That is run if the user ran wasm2js with an optimization level (like wasm2js -O3).

Split the test files to check both optimized and unoptimized code.
2019-04-30 20:30:03 -07:00
09945884f7 Remove f32 legalization from LegalizeJSInterface (#2052)
As well as i64 splitting this pass was also converting f32 to f64
at the wasm boundry.  However it appears this is not actually useful
and makes somethings (such as dynamic linking) harder.
2019-04-25 07:50:15 -07:00
c3ed0f176b wasm2js: more js optimization (#2050)
* Emit ints as signed, so -1 isn't a big unsigned number.
* x - -c (where c is a constant) is larger than x + c in js (but not wasm)
* +(+x) => +x
* Avoid unnecessary coercions on calls, return, load, etc. - we just need coercions when entering or exiting "wasm" (not internally), and on actual operations that need them.
2019-04-24 15:27:05 -07:00
f81c78bd62 wasm2js: start to optionally optimize the JS (#2046)
Removes redundant | 0s and similar things. (Apparently closure compiler doesn't do that, so makes sense to do here.)
2019-04-24 10:22:56 -07:00
5d3fcffdd9 wasm2js: emit quoted properties for the exports, to support closure compiler (#2043) 2019-04-23 17:13:47 -07:00
455f431260 wasm2js: avoid non-ES5 stuff like "let" (#2041)
Also fix the fuzzer's handling of feature flags so that wasm2js can work.
2019-04-23 12:40:14 -07:00
db14d0477f wasm2js2 import fixes (#2031)
* Don't assume function types exist in legalize-js-interface.
* Properly handle (ignore) imports in RemoveNonJSOps - do not try to recurse into them.
* Run legalize-js-interface and remove-unused-module-elements in wasm2js, the first is necessary, the last is nice to have.
2019-04-19 15:22:55 -07:00
a9808ac698 wasm2js: do not try to be smart with not emitting if braces, the corner cases are tricky (#2026)
leave them for later optimizers/minifiers
2019-04-18 13:06:23 -07:00
8dc68bc96d wasm2js: remove "use asm", we are not asm.js anymore (#2020)
Also emit the memory growth code based on memory growth, and not whether we are "use asm" or not.
2019-04-18 10:39:41 -07:00
1e91e1b666 Use a single table in wasm2js (#2005)
This replaces the multiple asm.js tables (of power-of-2 size) with a single simple table.

Also supports importing the table.
2019-04-15 13:57:56 -07:00
883d14de71 Wasm2js memory fixes (#2003)
* I64ToI32Lowering - don't assume address 0 is a hardcoded location for scratch memory. Import __tempMemory__ for that.
* RemoveNonJSOps - also use __tempMemory__. Oddly here the address was a hardcoded 1024 (perhaps where the rust program put a static global?).
* Support imported ints in wasm2js, coercing them as needed.
* Add "env" import support in the tests, since now we emit imports from there.
* Make wasm2js tests split out multi-module tests using split_wast which is more robust and avoids emitting multiple outputs in one file (which makes no sense for ES6 modules)
2019-04-12 15:45:10 -07:00
b769b4ede6 Wasm2js refactoring (#1997)
Early work for #1929

* Leave core wasm module - the "asm.js function" - to Wasm2JSBuilder, and add Wasm2JSGlue which emits the code before and after that. Currently that's some ES6 code, but we may want to change that later.
* Add add AssertionEmitter class for the sole purpose of emitting modules + assertions for testing. This avoids some hacks from before like starting from index 1 (assuming the module at first position was already parsed and printed) and printing of the f32Equal etc. functions not at the very top (which was due to technical limitations before).

Logic-wise, there should be no visible change, except some whitespace and reodering, and that I made the exceptions print out the source of the assertion that failed from the wast:

-if (!check2()) fail2();
+if (!check2()) throw 'assertion failed: ( assert_return ( call add ( i32.const 1 ) ( i32.const 1 ) ) ( i32.const 2 ) )';

(fail2 etc. did not exist, and seems to just have given a unique number for each assertion?)
2019-04-11 14:01:51 -07:00
d8bcf64e48 Optimize away sets of the same local (#1940) 2019-03-07 17:13:02 -08:00
f109f3cae1 Rename wasm2asm to wasm2js, emit ESM by default (#1642)
* 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.
2018-08-30 16:10:26 -07:00