summaryrefslogtreecommitdiff
path: root/src/wasm/wasm.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Minify wasi imports and exports, and not just "env" (#2323)Alon Zakai2019-09-011-0/+2
| | | This makes the minification pass aware of "wasi_unstable" and "wasi" as well.
* Add atomic.fence instruction (#2307)Heejin Ahn2019-08-271-0/+2
| | | | | | | This adds `atomic.fence` instruction: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#fence-operator This also fix bugs in `atomic.wait` and `atomic.notify` instructions in binaryen.js and adds tests for them.
* Add initial support for anyref as an opaque type (#2294)Jay Phelps2019-08-201-0/+1
| | | | | | | | | | | | | Another round of trying to push upstream things from my fork. This PR only adds support for anyref itself as an opaque type. It does NOT implement the full [reference types proposal](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md)--so no table.get/set/grow/etc or ref.null, ref.func, etc. Figured it was easier to review and merge as we go, especially if I did something fundamentally wrong. *** I did put it under the `--enable-reference-types` flag as I imagine that even though this PR doesn't complete the full feature set, it probably is the right home. Lmk if not. I'll also be adding a few github comments to places I want to point out/question.
* Add basic exception handling support (#2282)Heejin Ahn2019-08-131-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds basic support for exception handling instructions, according to the spec: https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md This PR includes support for: - Binary reading/writing - Wast reading/writing - Stack IR - Validation - binaryen.js + C API - Few IR routines: branch-utils, type-updating, etc - Few passes: just enough to make `wasm-opt -O` pass - Tests This PR does not include support for many optimization passes, fuzzer, or interpreter. They will be follow-up PRs. Try-catch construct is modeled in Binaryen IR in a similar manner to that of if-else: each of try body and catch body will contain a block, which can be omitted if there is only a single instruction. This block will not be emitted in wast or binary, as in if-else. As in if-else, `class Try` contains two expressions each for try body and catch body, and `catch` is not modeled as an instruction. `exnref` value pushed by `catch` is get by `pop` instruction. `br_on_exn` is special: it returns different types of values when taken and not taken. We make `exnref`, the type `br_on_exn` pushes if not taken, as `br_on_exn`'s type.
* Finalize tail call support (#2246)Thomas Lively2019-07-231-1/+9
| | | | Adds tail call support to fuzzer and makes small changes to handle return calls in multiple utilities and passes. Makes larger changes to DAE and inlining passes to properly handle tail calls.
* Don't minify __stack_pointer import (#2219)Sam Clegg2019-07-111-0/+1
| | | This is core import like __memory_base and __table_base.
* Initial tail call implementation (#2197)Thomas Lively2019-07-031-0/+1
| | | | | | | | | | | Including parsing, printing, assembling, disassembling. TODO: - interpreting - effects - finalization and typing - fuzzing - JS/C API
* Clean up loose ends in feature handling (#2203)Thomas Lively2019-07-031-0/+1
| | | | | Fix and test mutable globals support, replace string literals with constants, and add a pass to emit the target features section.
* Minimal Push/Pop support (#2207)Alon Zakai2019-07-031-0/+12
| | | | | | | This is the first stage of adding support for stacky/multivaluey things. It adds new push/pop instructions, and so far just shows that they can be read and written, and that the optimizer doesn't do anything immediately wrong on them. No fuzzer support, since there isn't a "correct" way to use these yet. The current test shows some "incorrect" usages of them, which is nice to see that we can parse/emit them, but we should replace them with proper usages of push/pop once we actually have those (see comments in the tests). This should be enough to unblock exceptions (which needs a pop in try-catches). It is also a step towards multivalue (I added some docs about that), but most of multivalue is left to be done.
* Add event section (#2151)Heejin Ahn2019-05-311-0/+47
| | | | | | | | | | | | | | | | | | This adds support for the event and the event section, as specified in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model. Wasm events are features that suspend the current execution and transfer the control flow to a corresponding handler. Currently the only supported event kind is exceptions. For events, this includes support for - Binary file reading/writing - Wast file reading/writing - Binaryen.js API - Fuzzer - Validation - Metadce - Passes: metrics, minify-imports-and-exports, remove-unused-module-elements
* Refactor type and function parsing (#2143)Heejin Ahn2019-05-241-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Refactored & fixed typeuse parsing rules so now the rules more closely follow the spec. There have been multiple parsing rules that were different in subtle ways, which are supposed to be the same according to the spec. - Duplicate types, i.e., types with the same signature, in the type section are allowed as long as they don't have the same given name. If a name is given, we use it; if type name is not given, we generate one in the form of `$FUNCSIG$` + signature string. If the same generated name already exists in the type section, we append `_` at the end. This causes most of the changes in the autogenerated type names in test outputs. - A typeuse has to be in the order of (type) -> (param) -> (result), if more than one of them exist. In case of function definitions, (local) has to be after all of these. Fixed some test cases that violate this rule. - When only (param)/(result) are given, its type will be the type with the smallest existing type index whose parameter and result are the same. If there's no such type, a new type will be created and inserted. - Added a test case `duplicate_types.wast` to test type namings for duplicate types. - Refactored `parseFunction` function. - Add more overrides to helper functions: `getSig` and `ensureFunctionType`.
* Factor out elementStartsWith (NFC) (#2137)Heejin Ahn2019-05-231-0/+1
| | | | | Checking if a first string matches a certain string within a list element appears many times within the parser, so extracted it as a helper function.
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-211-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Reflected new renamed instruction names in code and tests: - `get_local` -> `local.get` - `set_local` -> `local.set` - `tee_local` -> `local.tee` - `get_global` -> `global.get` - `set_global` -> `global.set` - `current_memory` -> `memory.size` - `grow_memory` -> `memory.grow` - Removed APIs related to old instruction names in Binaryen.js and added APIs with new names if they are missing. - Renamed `typedef SortedVector LocalSet` to `SetsOfLocals` to prevent name clashes. - Resolved several TODO renaming items in wasm-binary.h: - `TableSwitch` -> `BrTable` - `I32ConvertI64` -> `I32WrapI64` - `I64STruncI32` -> `I64SExtendI32` - `I64UTruncI32` -> `I64UExtendI32` - `F32ConvertF64` -> `F32DemoteI64` - `F64ConvertF32` -> `F64PromoteF32` - Renamed `BinaryenGetFeatures` and `BinaryenSetFeatures` to `BinaryenModuleGetFeatures` and `BinaryenModuleSetFeatures` for consistency.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-13/+25
| | | 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-189/+262
| | | 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: support i64 globals (#2021)Alon Zakai2019-04-181-1/+3
| | | Split them into two i32 globals.
* Better memory fuzzing (#1987)Alon Zakai2019-04-081-5/+9
| | | | | | | | 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.
* Passive segments (#1976)Thomas Lively2019-04-051-1/+1
| | | | | Adds support for the bulk memory proposal's passive segments. Uses a new (data passive ...) s-expression syntax to mark sections as passive.
* Use target features section in wasm-opt (#1967)Thomas Lively2019-04-031-0/+6
| | | | | | | 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.
* wasm-emscripten-finalize: Improve shared library support (#1961)Sam Clegg2019-04-021-0/+1
| | | | | | | | | | | | | | | | | Convert PIC code generated by llvm to work with the current emscripten ABI for dynamic linking: - Convert mutable global imports from GOT.mem and GOT.func into internal globals. - Initialize these globals on started up in g$foo and f$foo imported functions to calculate addresses at runtime. Also: - Add a test case for linking and finalizing a shared library - Allow __stack_pointer global to be non-existent as can be case for a shared library. - Allow __stack_pointer global to be an import, as can be the case for a shared library.
* Rename atomic wait/notify instructions (#1972)Heejin Ahn2019-03-301-3/+3
| | | | | | | | This renames the following: - `i32.wait` -> `i32.atomic.wait` - `i64.wait` -> `i64.atomic.wait` - `wake` -> `atomic.notify` to match the spec.
* Add strip-target-features pass (#1946)Thomas Lively2019-03-141-0/+1
| | | And run it in wasm-emscripten-finalize. This will prevent the emscripten output from changing when the target features section lands in LLVM.
* Fix memory leaks (#1925)Bohdan2019-02-281-0/+12
| | | | | | Fixes #1921 Signed-off-by: Bogdan Vaneev <warchantua@gmail.com>
* Bulk memory operations (#1892)Thomas Lively2019-02-051-0/+32
| | | | | | Bulk memory operations The only parts missing are the interpreter implementation and spec tests.
* Strip the producers section in --strip-producers (#1875)Alon Zakai2019-01-311-0/+1
| | | | | | | | WebAssembly/tool-conventions#93 has a summary of emscripten's current thinking on this. For Binaryen, we don't want to do anything to the producers section by default, but do want it to be possible to optionally remove it. To achieve that, this PR * creates a --strip-producers pass that removes that section. * creates a --strip-debug pass that removes debug info, same as the old --strip, which is still around but deprecated. A followup in emscripten will use this pass by default.
* Require unique_ptr to Module::addFunctionType() (#1672)Paweł Bylica2019-01-101-3/+5
| | | | | This fixes the memory leak in WasmBinaryBuilder::readSignatures() caused probably the exception thrown there before the FunctionType object is safe. This also makes it clear that the Module becomes the owner of the FunctionType objects.
* Massive renaming (#1855)Thomas Lively2019-01-071-5/+5
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* SIMD (#1820)Thomas Lively2018-12-131-0/+88
| | | | | | | | | Implement and test the following functionality for SIMD. - Parsing and printing - Assembling and disassembling - Interpretation - C API - JS API
* Warn if linking section is present, as we cannot handle it yet (#1798)Alon Zakai2018-12-041-1/+1
|
* Implement nontrapping float-to-int instructions (#1780)Thomas Lively2018-12-041-0/+8
|
* Add --strip that removes debug info (#1787)Alon Zakai2018-12-031-0/+15
| | | | This is sort of like --strip on a native binary. The more specific use case for us is e.g. you link with a library that has -g in its CFLAGS, but you don't want debug info in your final executable (I hit this with poppler now). We can make emcc pass this to binaryen if emcc is not building an output with intended debug info.
* Cleanup shared constants (#1784)Sam Clegg2018-11-291-0/+2
|
* Remove default cases (#1757)Thomas Lively2018-11-271-3/+3
| | | | | | Where reasonable from a readability perspective, remove default cases in switches over types and instructions. This makes future feature additions easier by making the compiler complain about each location where new types and instructions are not yet handled.
* Rename tableBase/memoryBase to __table_base/__memory_base (#1731)Sam Clegg2018-11-081-2/+2
|
* Unify imported and non-imported things (#1678)Alon Zakai2018-09-191-47/+10
| | | | | | | | | | | | | | Fixes #1649 This moves us to a single object for functions, which can be imported or nor, and likewise for globals (as a result, GetGlobals do not need to check if the global is imported or not, etc.). All imported things now inherit from Importable, which has the module and base of the import, and if they are set then it is an import. For convenient iteration, there are a few helpers like ModuleUtils::iterDefinedGlobals(wasm, [&](Global* global) { .. use global .. }); as often iteration only cares about imported or defined (non-imported) things.
* remove PageSize and HasFeature, which wasm removed a while back (#1667)Alon Zakai2018-09-121-1/+1
| | | From #1665 (a fuzz bug noticed they were not handled in stack.h).
* Fix read-write of dylink section (#1648)Alon Zakai2018-08-311-0/+2
| | | | | | The 'dylink' user section must be emitted before all other sections, per the spec (to allow simple parsing by loaders) This PR makes reading and writing of a dynamic library remain a valid dynamic library.
* Proper error handling in add* and get* methods (#1570)Alon Zakai2018-07-101-32/+80
| | | | | | | See #1479 (comment) Also a one-line readme update, remove an obsolete compiler (mir2wasm) and add a new one (asterius). Also improve warning and error reporting in binaryen.js - show a stack trace when relevant (instead of node.js process.exit), and avoid atexit warning spam in debug builds.
* add missing atomics to getExpressionName, which is used in --metrics (#1529)Alon Zakai2018-05-041-0/+4
|
* when creating blocks in binary format parsing, we know if a block has a ↵Alon Zakai2018-04-051-9/+19
| | | | break to it - use that to avoid rescanning blocks for unreachability purposes (#1495)
* Rename WasmType => Type (#1398)Alon Zakai2018-02-021-11/+11
| | | | * rename WasmType to Type. it's in the wasm:: namespace anyhow, and without Wasm- it fits in better alongside Index, Address, Expression, Module, etc.
* Global optimization fixes (#1360)Alon Zakai2018-01-171-1/+11
| | | | | | | | | | | | | | | | * run dfe at the very end, as it may be more effective after inlining * optimize reorder-functions * do a final dfe in asm2wasm after all other opts * make inlining deterministic: std::atomic<T> values are not zero-initialized * do global post opts at the end of asm2wasm, and don't also do them in the module builder * fix function type removing * don't inline+optimize when preserving debug info
* notation change: AST => IR (#1245)Alon Zakai2017-10-241-1/+1
| | | The IR is indeed a tree, but not an "abstract syntax tree" since there is no language for which it is the syntax (except in the most trivial and meaningless sense).
* Atomics support in interpreter + optimizer + fuzz fixes for that (#1227)Alon Zakai2017-10-201-0/+2
|
* Make localNames into a map (#1189)Thomas Lively2017-09-231-7/+8
|
* Add support for sign-extension operators from threading proposal (#1167)Derek Schuff2017-09-061-1/+2
| | | These are not atomic operations, but are added with the atomic operations to keep from having to define atomic versions of all the sign-extending loads (an atomic zero-extending load + signext operation can be used instead).
* Return to more structured type rules for block and if (#1148)Alon Zakai2017-09-051-17/+34
| | | | | | | | * if a block has a concrete final element (or a break with a value), then even if it has an unreachable child, keep it with that concrete type. this means we no longe allow the silly case of a block with an unreachable in the middle and a concrete as the final element while the block is unreachable - after this change, the block would have the type of the final element * if an if has a concrete element in one arm, make it have that type as a result, even if the if condition is unreachable, to parallel block * make type rules for brs and switches simpler, ignore whether they are reachable or not. whether they are dead code should not affect how they influence other types in our IR.
* wasm-reduce tool (#1139)Alon Zakai2017-09-011-0/+10
| | | Reduce an interesting wasm to a smaller still interesting wasm. This takes an arbitrary command to run, and reduces the wasm as much as it can while keeping the behavior of that command fixed. This can be used to reduce compiler bugs in an arbitrary VM, etc.
* set the type of a set_local properly when it is unreachableAlon Zakai2017-08-251-0/+4
|
* Add support for atomic wait and wake operators (#1140)Derek Schuff2017-08-241-0/+12
| | | According to spec at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-wake-operators