summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer/simple_ast.h
Commit message (Collapse)AuthorAgeFilesLines
* Use new wast parser in wasm2js (#6606)Thomas Lively2024-05-291-2/+1
| | | | When generating assertions, traverse the `WASTScript` data structure rather than interleaving assertion parsing with emitting.
* [NFC] Mark operator== as const (#5990)walkingeyerobot2023-10-031-1/+1
| | | | | C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.
* wasm2js: Stop emitting nan and infinity (#5391)Will Cohen2023-01-041-14/+6
| | | | | | | 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.
* Switch from `typedef` to `using` in C++ code. NFC (#5258)Sam Clegg2022-11-151-1/+1
| | | | This is more modern and (IMHO) easier to read than that old C typedef syntax.
* Make `Name` a pointer, length pair (#5122)Thomas Lively2022-10-111-9/+10
| | | | | | | | | | | | | | | | | | | | | | | With the goal of supporting null characters (i.e. zero bytes) in strings. Rewrite the underlying interned `IString` to store a `std::string_view` rather than a `const char*`, reduce the number of map lookups necessary to intern a string, and present a more immutable interface. Most importantly, replace the `c_str()` method that returned a `const char*` with a `toString()` method that returns a `std::string`. This new method can correctly handle strings containing null characters. A `const char*` can still be had by calling `data()` on the `std::string_view`, although this usage should be discouraged. This change is NFC in spirit, although not in practice. It does not intend to support any particular new functionality, but it is probably now possible to use strings containing null characters in at least some cases. At least one parser bug is also incidentally fixed. Follow-on PRs will explicitly support and test strings containing nulls for particular use cases. The C API still uses `const char*` to represent strings. As strings containing nulls become better supported by the rest of Binaryen, this will no longer be sufficient. Updating the C and JS APIs to use pointer, length pairs is left as future work.
* [wasm2js] Support exports of Globals (#4523)magic-akari2022-03-171-5/+49
| | | | | | Export an object with a `.value` property like the wasm JS API does in browsers, and implement them with a getter and setter. Fixes #4522
* Make static buffers in numToString thread local (#4134)Thomas Lively2021-09-091-4/+6
| | | | | | | Validation is performed on multiple threads at once and when there are multiple validation failures, those threads can all end up in `numToString` at the same time as they construct their respective error messages. Previously the threads would race on their access to the snprintf buffers, sometimes leading to segfaults. Fix the data races by making the buffers thread local.
* Simplify some numeric code (#3186)Max Graey2020-10-011-2/+2
|
* wasm2js: don't emit obviously unnecessary parens (#2080)Alon Zakai2019-05-021-12/+26
| | | A minifier would probably remove them later anyhow, but they make reading the code annoying and hard.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-83/+139
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-334/+439
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* wasm2js: remove unneeded break/continue labels (#2058)Alon Zakai2019-04-261-5/+4
|
* wasm2js: more js optimization (#2050)Alon Zakai2019-04-241-0/+3
| | | | | | * 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.
* wasm2js: start to optionally optimize the JS (#2046)Alon Zakai2019-04-241-11/+2
| | | Removes redundant | 0s and similar things. (Apparently closure compiler doesn't do that, so makes sense to do here.)
* wasm2js: emit quoted properties for the exports, to support closure compiler ↵Alon Zakai2019-04-231-2/+17
| | | | (#2043)
* wasm2js: fix printing of negated negative constants (#2034)Alon Zakai2019-04-221-0/+3
| | | It is invalid to print --5, we need to add a space - -5 so that it is valid JS to parse.
* 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
* 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.
* More misc ASAN fixes (#1882)Alon Zakai2019-01-221-0/+1
| | | | | | | | | | * fix buffer overflow in simple_ast.h printing. * check wasm binary format reading of function export indexes for errors. * check if s-expr format imports have a non-empty module and base. Fixes #1876 Fixes #1877 Fixes #1879
* Code style improvements (#1868)Alon Zakai2019-01-151-10/+11
| | | | * Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
* Fix alignment in MixedAllocator (#1740)Alon Zakai2018-11-131-2/+2
| | | Necessary for simd, as we add a type with alignment >8. We were just broken on that before this PR.
* wasm2asm: Fix and enable a large number of spec tests (#1558)Alex Crichton2018-05-291-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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: Implement float<->int conversions (#1550)Alex Crichton2018-05-161-0/+15
| | | | | | | | | 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`.
* i64 to i32 lowering for wasm2asm (#1134)Thomas Lively2017-09-011-3/+5
|
* wasm2asm test generation (#1124)Thomas Lively2017-08-161-61/+41
| | | | | | | | | | | | | | | | | * Translate assert_return invokes to asm * Translate assert_trap tests to JS * Enable wasm2asm tests * Fix wasm2asm translation of store * Update ubuntu nodejs in Travis * Free JSPrinter buffer * Use unique_ptr for Functions to prevent leaks * Add tests for assert translation
* Get wasm2asm building again (#1107)Thomas Lively2017-08-021-0/+651
| | | | | | | | | | | | | | | | | | * Get wasm2asm building again Updates CMakeLists.txt to have wasm2asm built by default, updates wasm2asm.h to account for recent interface changes, and restores JSPrinter functionality. * Implement splice for array values * Clean up wasm2asm testing * Print semicolons after statements in blocks * Cleanups and semicolons for condition arms * Prettify semicolon emission
* refactor asm.js ast to use an AssignName node, for the common case of ↵Alon Zakai (kripken)2017-01-311-9/+30
| | | | assigning to a name and not an arbitrary ast node
* refactor asm.js ast to not use STAT nodes - we don't need to print the ↵Alon Zakai (kripken)2017-01-311-632/+2
| | | | asm.js anyhow, so knowing where ;s are is unnecessary bloat
* refactor asm.js ast to use an Assign nodeAlon Zakai (kripken)2017-01-311-116/+48
|
* use MixedArena in asm.js astAlon Zakai (kripken)2017-01-311-43/+35
|
* refactor asm.js ast to use a string node directly instead of [NAME, string]Alon Zakai (kripken)2017-01-311-8/+10
|
* refactor asm.js ast to use a number node directly instead of [NUM, number]Alon Zakai (kripken)2017-01-301-7/+17
|
* fix large f32 consts, fixes #817 (#820)Alon Zakai2016-11-011-2/+2
|
* Fix some C6246: "Local declaration of 'i' hides declaration of the same name ↵juj2016-10-201-1/+1
| | | | in outer scope." warnings. (#795)
* clean up in emscripten-optimizer arenasAlon Zakai2016-04-271-0/+1
|
* use strncpy #283Alon Zakai2016-03-281-1/+1
|
* Add Travis builds with sanitizersJF Bastien2016-01-101-15/+14
| | | | | | | | | | | | | | | | This triggers 5 independent build / test runs: - clang, no sanitizer; - clang, UB sanitizer; - clang, address sanitizer (disabled for now); - clang, thread sanitizer (disabled for now); - GCC. Enabling UBSan led to these changes: - Fix a bunch of undefined behavior throughout the code base. - Fix some tests that relied on that undefined behavior. - Make some of the tests easier to debug by printing their command line. - Add ubsan blacklist to work around libstdc++ bug. - Example testcase also needs sanitizer because libsupport.a uses it.
* parse for loops in asm2wasm #60Alon Zakai2016-01-041-1/+13
|
* Fix / uniformize include guardsJF Bastien2015-12-221-3/+3
|
* Fix warnings found by GCCJF Bastien2015-12-221-16/+16
| | | | | | My previous patch addressed all LLVM warnings, this one addresses all the GCC ones as well (mostly signed / unsigned mix). The patch also turns on -Wall -Werror.
* Fix uninitialize variable warningJF Bastien2015-12-221-1/+3
|
* Fix the license headersJF Bastien2015-12-211-1/+15
| | | | This applies Apache 2.0 properly (as far as our lawyers have told me). We can do this early since all of the code was written by Alon Zakai.
* don't quote keys in object printing when not necessaryAlon Zakai2015-12-071-3/+14
|
* emit heap views in wasm2asmAlon Zakai2015-12-061-0/+7
|
* wasm2asm fixesAlon Zakai2015-12-041-0/+6
|
* fixes for wasm2asmAlon Zakai2015-12-031-1/+1
|
* refactoring, and wasm2asm arags and localsAlon Zakai2015-12-011-6/+61
|
* finish first pass on wasm2asmAlon Zakai2015-12-011-0/+6
|
* wasm2asm progressAlon Zakai2015-12-011-0/+6
|
* wasm2asm progressAlon Zakai2015-11-271-0/+8
|