summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* wasm2js: use scratch memory properly (#2033)Alon Zakai2019-04-226-82/+237
| | | | | | | This replaces all uses of __tempMemory__, the old scratch space location, with calls to function imports for scratch memory access. This lets us then implement those in a way that does not use the same heap as main memory. This avoids possible bugs with scratch memory overwriting something, or just in general that it has observable side effects, which can confuse fuzzing etc. The intrinsics are currently implemented in the glue. We could perhaps emit them inline instead (but that might limit asm.js optimizations, so I wanted to keep our options open for now - easy to change later). Also fixes some places where we used 0 as the scratch space address.
* wasm2js2 import fixes (#2031)Alon Zakai2019-04-193-5/+9
| | | | | | * 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.
* wasm2js: handle unreachable select and global.set (#2029)Alon Zakai2019-04-181-0/+21
|
* Reland emitting of DataCount section (#2027)Thomas Lively2019-04-182-11/+6
| | | | | | This reverts commit cb2d63586c08a3dd194d2b733ceb3f5051c081f8. The issues with feature validation were mostly resolved in #1993, and this PR finishes the job by adding feature flags to wasm-as to avoid emitting the DataCount section when bulk-memory is not enabled.
* Refactor interpreter initialization to use bulk memory (#2025)Thomas Lively2019-04-183-285/+357
| | | | | | | | | | This corresponds to changes made to the initialization procedure in the spec. It also removes all the heavy initialization work from the external interface of the interpreter, which is a nice encapsulation win. Implementation of the interpretation of the remaining bulk memory operations and more rigorous tests of that interpretation will come in a follow-up PR.
* wasm2js: do not try to be smart with not emitting if braces, the corner ↵Alon Zakai2019-04-181-33/+17
| | | | | cases are tricky (#2026) leave them for later optimizers/minifiers
* wasm2js: remove "use asm", we are not asm.js anymore (#2020)Alon Zakai2019-04-181-17/+2
| | | Also emit the memory growth code based on memory growth, and not whether we are "use asm" or not.
* Wasm2js: support i64 globals (#2021)Alon Zakai2019-04-183-12/+53
| | | Split them into two i32 globals.
* Use OverriddenVisitor in ExpressionRunner (#2024)Alon Zakai2019-04-171-16/+20
| | | Should prevent surprises in the future.
* Do not precompute bulk memory operations (#2023)Thomas Lively2019-04-171-0/+12
| | | Fixes #1984
* wasm2js: fix br_table to loop (#2018)Alon Zakai2019-04-171-9/+11
|
* Improve log-execution pass to also log around returns (#2019)Alon Zakai2019-04-171-1/+14
|
* Fix if else JS printing when if body is a labelled block (#2017)Alon Zakai2019-04-171-1/+4
| | | | | | | | | | | | Before, we'd print if (..) label: { .. }; else .. But that is wrong, as it ends the if too early. After this, we print if (..) label: { .. } else .. The bug was we checked if the if body was a block, but not if it was a labelled block.
* Demote a wasm2js warning on scopes (#2016)Alon Zakai2019-04-171-2/+6
| | | We do not actually analyze scopes properly there, see comment in the commit. For now, just demote it to a warning. Not sure if it's worth fixing it or just removing it.
* wasm2js: Fix unaligned loads and stores (#2015)Alon Zakai2019-04-171-0/+1
| | | We forgot to set them as unsigned, which meant that we were reading uninitialized memory when checking that field, which mostly worked, except if it previously contained something...
* Change default feature set to MVP (#1993)Thomas Lively2019-04-1610-11/+63
| | | | | In the absence of the target features section or command line flags. When there are command line flags, it is an error if they do not exactly match the target features section, except if --detect-features has been provided. Also adds a --print-features pass to print the command line flags for all enabled options and uses it to make the feature tests more rigorous.
* Improve instrumentation passes (#2012)Alon Zakai2019-04-162-52/+93
| | | | | * Make the memory instrumentation pass log both pointers and values. * Use "env" as the import module - simpler to support and get working.
* wasm2js: support memory imports properly, updating their buffer too (#2013)Alon Zakai2019-04-161-3/+29
| | | | | * Emit an import statement for the memory. * Update the imported memory's buffer when we grow.
* Make sure we always add signature to `fp$` functions (#1994)Sam Clegg2019-04-161-3/+13
| | | | | | | | Previously we were searching for the function by name but this doesn't work when the internal name for the function is different. In order to repro such a case the shared.c test was converted to C++ since then binaryen's internal name is different since it comes from the de-mangled name section.
* Verify flat IR where it is expected, and give a nice error (#2009)Alon Zakai2019-04-167-40/+136
| | | Fixes #2007 #2008
* Do not emit the DataCount section (#2010)Thomas Lively2019-04-151-3/+8
| | | | | Its presence was causing validation errors in the Emscripten test suite. This should be reverted once the default feature set is no longer All.
* Use a single table in wasm2js (#2005)Alon Zakai2019-04-153-63/+93
| | | | | This replaces the multiple asm.js tables (of power-of-2 size) with a single simple table. Also supports importing the table.
* DataCount section (#2006)Thomas Lively2019-04-152-1/+33
| | | | | | | | * DataCount section Read the DataCount section and verify that it agrees with the data section. Also emit the DataCount section when bulk-memory is enabled and there are a nonzero number of segments. Factor out some shared unit test code.
* Move features from passOptions to Module (#2001)Thomas Lively2019-04-1232-195/+234
| | | | | This allows us to emit a (potentially modified) target features section and conditionally emit other sections such as the DataCount section based on the presence of features.
* Wasm2js memory fixes (#2003)Alon Zakai2019-04-124-47/+92
| | | | | | | | * 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)
* wasm2js memory improvements (#2002)Alon Zakai2019-04-121-30/+39
| | | | | * Refactor memory code to share it between the two emitting modes. * Get memory emitting set up in the emscripten mode.
* wasm2js: emscripten glue option (#2000)Alon Zakai2019-04-112-4/+66
| | | | | | Add a wasm2js option for the glue to be in emscripten-compatible format (as opposed to ES6). This does a few things so far: * Emit START_FUNCTIONS, END_FUNCTIONS markers in the code, for future use in the optimizer. * Emit the glue as a function to be called from emscripten.
* Wasm2js refactoring (#1997)Alon Zakai2019-04-114-536/+561
| | | | | | | | | | | | | 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?)
* Bulk memory side effects (#1998)Thomas Lively2019-04-111-12/+40
|
* don't precompute anything to a vector for now (#1999)Alon Zakai2019-04-101-1/+2
| | | We handled this for the normal case, but the optimizer can also precompute a return into a value, so check the output of the precomputation as well.
* Handle relocatable code in AsmConstWalker (#1992)Sam Clegg2019-04-101-4/+17
| | | | | | In relocatable code the constant offset might be relative to __memory_base.
* Minor wasm2js cleanups (#1995)Alon Zakai2019-04-101-21/+40
| | | | | * Only look at the sign of loads when they actually matter. * Prepare for imported globals (just refactoring/cleanup).
* Fuzz fixes (#1991)Alon Zakai2019-04-103-5/+15
| | | | | | | Get fuzzer to attempt to create almost all features. Pass v8 all the flags to allow that. Fix fuzz bugs where we read signed_ even when it was irrelevant for that type of load. Improve wasm-reduce on fuzz testcases, try to replace a node with drops of its children, not just the children themselves.
* avoid signed overflow undefined behavior in OptimizeInstructions constant ↵Alon Zakai2019-04-091-2/+2
| | | | computations (#1990)
* Directize: if we change a type to unreachable, we need to propagate that out ↵Alon Zakai2019-04-091-0/+10
| | | | (#1989)
* Better memory fuzzing (#1987)Alon Zakai2019-04-085-12/+77
| | | | | | | | Hash the contents of all of memory and log that out in random places in the fuzzer, so we are more sensitive there and can catch memory bugs. Fix UB that was uncovered by this in the binary writing code - if a segment is empty, we should not look at &vector[0], and instead use vector.data(). Add Builder::addExport convenience method.
* wasm-emscripten-finalize: rename function pointer getter functions (#1988)Sam Clegg2019-04-081-4/+25
| | | | | | | | Turns out there was already a precedent in emscripten for using `fp$` for these functions. Also, improve the heuristics for guessing the stack pointer global. There are cases where we don't use have an explicit stack pointer at all but *do* have both imported and exported globals.
* Move segment merging to fit web limits into its own pass (#1980)Thomas Lively2019-04-088-138/+228
| | | | | | It was previously part of writing a binary, but changing the number of segments at such a late stage would not work in the presence of bulk memory's datacount section. Also updates the memory packing pass to respect the web's limits on the number of data segments.
* Directize: arguments may have had side effects, don't just remove them when ↵Alon Zakai2019-04-081-5/+14
| | | | optimizing to an unreachable (#1985)
* Passive segments (#1976)Thomas Lively2019-04-0522-89/+196
| | | | | Adds support for the bulk memory proposal's passive segments. Uses a new (data passive ...) s-expression syntax to mark sections as passive.
* Add missing comma in metadata JSON (#1983)Thomas Lively2019-04-051-1/+1
|
* Add feature options to emscripten metadata (#1982)Thomas Lively2019-04-055-25/+62
| | | Emscripten runs wasm-emscripten-finalize before running wasm-opt, so the target features section is stripped out before optimizations are run. One option would have been to add another wasm-opt invocation at the very end to strip the target features section, but dumping the features as metadata avoids the extra tool invocation. In the long run, it would be nice to have only as single binaryen invocation to do all the work that needs doing.
* wasm-emscripten-finalize: add namedGlobals to output metadata (#1979)Sam Clegg2019-04-042-8/+21
| | | | | | This key is used by emscripten when building with MAIN_MODULE in order to export global variables from the main module to the side modules.
* Use target features section in wasm-opt (#1967)Thomas Lively2019-04-0311-91/+198
| | | | | | | If the user does not supply features explicitly on the command line, read and use the features in the target features section for validation and passes. If the user does supply features explicitly, error if they are not a superset of the features marked as used in the target features section and the user does not explicitly handle this.
* Update test/spec/memory.wast to latest upstream (#1801)Alon Zakai2019-04-035-3/+34
| | | | | | | Minus multi-memory which we don't support yet. Improve validator. Fix some minor validation issues in our tests.
* Add a mechanism to pass arguments to passes (#1941)Alon Zakai2019-04-033-13/+29
| | | | | | | | | This allows wasm-opt --pass-arg=KEY:VALUE where KEY and VALUE are strings. It is then added to passOptions.arguments, where passes can read it. This is used in ExtractFunction instead of an env var.
* Directize: turns indirect calls into direct ones (#1974)Alon Zakai2019-04-024-2/+136
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | * wip [ci skip] * works * test output * test update * js build * better location for running directize
| * better location for running directizeAlon Zakai2019-04-021-1/+1
| |
| * worksAlon Zakai (kripken)2019-03-312-16/+18
| |
| * wip [ci skip]Alon Zakai (kripken)2019-03-314-2/+134
| |