summaryrefslogtreecommitdiff
path: root/src/asmjs
Commit message (Collapse)AuthorAgeFilesLines
* wasm2js: Add Table operations (#6650)Alon Zakai2024-06-112-0/+5
| | | | | | | TableGet, Set, Size, Grow, Fill, Copy. Also move "null" into shared-constants, to make the code more consistent overall.
* wasm2js: Add basic reference operations (#6648)Alon Zakai2024-06-101-0/+4
| | | This adds ref.eq, ref.null, ref.is_null, ref.func.
* Make `Name` a pointer, length pair (#5122)Thomas Lively2022-10-112-5/+1
| | | | | | | | | | | | | | | | | | | | | | | 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.
* [NFC] Remove more `cashew::` namespaces from IString (#5127)Thomas Lively2022-10-111-78/+80
| | | Finishes work missed in #5126.
* [NFC] Remove `cashew::` namespace from IString (#5126)Thomas Lively2022-10-101-92/+94
| | | | As an NFC preliminary change that will minimize the diff in #5122, which moves IString to the wasm namespace.
* wasm2js: Don't assume that `env.abort` can always be impored. (#5049)Sam Clegg2022-09-162-2/+1
| | | | | | 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.
* Remove basic reference types (#4802)Thomas Lively2022-07-201-16/+0
| | | | | | | | | Basic reference types like `Type::funcref`, `Type::anyref`, etc. made it easy to accidentally forget to handle reference types with the same basic HeapTypes but the opposite nullability. In principle there is nothing special about the types with shorthands except in the binary and text formats. Removing these shorthands from the internal type representation by removing all basic reference types makes some code more complicated locally, but simplifies code globally and encourages properly handling both nullable and non-nullable reference types.
* Remove externref (#4633)Thomas Lively2022-05-041-3/+0
| | | | | | Remove `Type::externref` and `HeapType::ext` and replace them with uses of anyref and any, respectively, now that we have unified these types in the GC proposal. For backwards compatibility, continue to parse `extern` and `externref` and maintain their relevant C API functions.
* [Refactoring] Cleanup asm2wasm. Use JS instead ASM prefix where possible. ↵Max Graey2021-09-011-7/+7
| | | | NFC (#4090)
* Cleanup fallthrough warnings when building without asserts (#3598)walkingeyerobot2021-02-231-2/+3
|
* Remove exnref and br_on_exn (#3505)Heejin Ahn2021-01-221-3/+0
| | | This removes `exnref` type and `br_on_exn` instruction.
* [GC] Add dataref type (#3500)Alon Zakai2021-01-211-0/+3
| | | | | This is not 100% of everything, but is enough to get tests passing, which includes full binary and text format support, getting all switches to compile without error, and some additions to InstrumentLocals.
* [wasm2js] Use native JavaScript Math.trunc (#3329)Max Graey2020-11-102-5/+3
|
* Remove dead code and unused includes. NFC. (#3328)Sam Clegg2020-11-083-42/+0
| | | Specifically try to cleanup use of asm_v_wasm.h and asmjs constants.
* Remove OptimizeCalls from PostEmscripten. NFC. (#3326)Sam Clegg2020-11-062-2/+0
| | | We no longer build modules that import `global.Math`.
* wasm2js: Remove global dict arguments to asmFunc (#3325)Sam Clegg2020-11-052-8/+0
|
* GC: Integrate eqref and i31ref types (#3141)Daniel Wirtz2020-09-191-0/+6
| | | Adds the `eqref` and `i31ref` types to their respective code locations. Implements what can be implemented trivially and otherwise traps with a TODO for now. Integration of `eqref` is mostly complete due to it being nullable, just like `anyref`, but `i31ref` needs to remain disabled in the fuzzer because we are lacking the functionality to create trivial `i31ref` values, i.e. `(i31.new (i32.const 0))`, which is left for follow-ups to implement.
* Add anyref feature and type (#3109)Daniel Wirtz2020-09-101-0/+3
| | | Adds `anyref` type, which is enabled by a new feature `--enable-anyref`. This type is primarily used for testing that passes correctly handle subtype relationships so that the codebase will continue to be prepared for future subtyping. Since `--enable-anyref` is meaningless without also using `--enable-reference-types`, this PR also makes it a validation error to pass only the former (and similarly makes it a validation error to enable exception handling without enabling reference types).
* Update reference types (#3084)Daniel Wirtz2020-09-091-3/+0
| | | | | | | Align with the current state of the reference types proposal: * Remove `nullref` * Remove `externref` and `funcref` subtyping * A `Literal` of a nullable reference type can now represent `null` (previously was type `nullref`) * Update the tests and temporarily comment out those tests relying on subtyping
* Add new compound Signature, Struct and Array types (#3012)Daniel Wirtz2020-08-241-1/+1
| | | | | Extends the `Type` hash-consing infrastructure to handle type-parameterized and constructed types introduced in the typed function references and GC proposals. This should be a non-functional change since the new types are not used anywhere yet. Recursive type construction and canonicalization is also left as future work. Co-authored-by: Thomas Lively <tlively@google.com>
* Use const modifier when dealing with types (#3064)Daniel Wirtz2020-08-201-1/+1
| | | Since they make the code clearer and more self-documenting.
* Replace Type::expand() with an iterator-based approach (#3061)Daniel Wirtz2020-08-191-2/+2
| | | This leads to simpler code and is a prerequisite for #3012, which makes it so that not all `Type`s are backed by vectors that `expand` could return.
* Prepare for compound types that are single but not basic (#3046)Daniel Wirtz2020-08-171-2/+4
| | | | | | | | | | | | | | As a follow-up to https://github.com/WebAssembly/binaryen/pull/3012#pullrequestreview-459686171 this PR prepares for the new compound Signature, Struct and Array types that are single but not basic. This includes: * Renames `Type::getSingle` to `Type::getBasic` (NFC). Previously, its name was not representing its implementation (`isSingle` excluded `none` and `unreachable` while `getSingle` didn't, i.e. `getSingle` really was `getBasic`). Note that a hypothetical `Type::getSingle` cannot return `ValueType` anyway (new compound types are single but don't map to `ValueType`), so I figured it's best to skip implementing it until we actually need it. * Marks locations where we are (still) assuming that all single types are basic types, as suggested in https://github.com/WebAssembly/binaryen/pull/3012#discussion_r465356708, but using a macro, so we get useful errors once we start implementing the new types and can quickly traverse the affected locations. The macro is added where * there used to be a `switch (type.getSingle())` or similar that handled any basic type (NFC), but in the future will also have to handle single types that are not basic types. * we are not dealing with `Unary`, `Binary`, `Load`, `Store` or `AtomicXY` instructions, since these don't deal with compound types anyway.
* Added headers to CMake files (#3037)Wouter van Oortmerssen2020-08-101-0/+2
| | | This is needed for headers to show up in IDE projects, and has no other effect on the build.
* wasm2js: Avoid 64-bit scratch memory helpers in wasm-intrinsics (#2926)Alon Zakai2020-06-231-2/+0
| | | | | | | | | | | | | | That code originally used memory location 1024 to save 64 bits of data (as that is what rust does apparently). We refactored it manually to instead use a scratch memory helper, which is safer. However, that 64-bit function ends up legalized, which actually changes the interface between the module and the outside, which is confusing and causes problems with optimizations that can remove the getTempRet0 imports, see emscripten-core/emscripten#11456 Instead, just use a global i64 to stash those bits. This requires adding support for copying globals from the intrinsics module, but otherwise seems simpler overall.
* wasm2js: Bulk memory support (#2923)Alon Zakai2020-06-221-0/+7
| | | | | | | | | | | | | | Adds a special helper functions for data.drop etc., as unlike most wasm instructions these are too big to emit inline. Track passive segments at runtime in var memorySegments whose indexes are the segment indexes. Emit var bufferView even if the memory exists even without memory segments, as we do still need the view in order to operate on it. Also adds a few constants for atomics that will be useful in future PRs (as this PR updates the constant lists anyhow).
* Rename anyref to externref to match proposal change (#2900)Jay Phelps2020-06-101-3/+3
| | | | | | | anyref future semantics were changed to only represent opaque host values, and thus renamed to externref. [Chromium](https://bugs.chromium.org/p/v8/issues/detail?id=7748#c360) was just updated to today (not yet released). I couldn't find a Mozilla bugzilla ticket mentioning externref so I don't immediately know if they've updated yet. https://github.com/WebAssembly/reference-types/pull/87
* Reland "Link binaryen tools against the dylib" (#2892)Derek Schuff2020-06-032-0/+13
| | | | | Reland of #2864 Also ensure a relative install rpath by adding setup to each tool config. The CMake code is cribbed from LLVM's implementation.
* Revert "Link binaryen tools against the dylib (#2864)" (#2891)Derek Schuff2020-06-022-13/+0
| | | This reverts commit f6b7f0018ca5ce604e94cc6cf50ee712bb7e9b27.
* Link binaryen tools against the dylib (#2864)Derek Schuff2020-06-022-0/+13
| | | When building the libbinaryen dynamic library, also link the binaryen tools against it. This reduces combined tool size on mac from 76M to 2.8M
* Remove implicit conversion operators from Type (#2577)Thomas Lively2020-01-081-2/+2
| | | | | | | | | | * Remove implicit conversion operators from Type Now types must be explicitly converted to uint32_t with Type::getID or to ValueType with Type::getVT. This fixes #2572 for switches that use Type::getVT. * getVT => getSingle
* [NFC] Enforce use of `Type::` on type names (#2434)Thomas Lively2020-01-071-24/+24
|
* Add support for reference types proposal (#2451)Heejin Ahn2019-12-301-4/+9
| | | | | | | | | | | | This adds support for the reference type proposal. This includes support for all reference types (`anyref`, `funcref`(=`anyfunc`), and `nullref`) and four new instructions: `ref.null`, `ref.is_null`, `ref.func`, and new typed `select`. This also adds subtype relationship support between reference types. This does not include table instructions yet. This also does not include wasm2js support. Fixes #2444 and fixes #2447.
* Remove FunctionType (#2510)Thomas Lively2019-12-111-52/+8
| | | | | | | | | | | | | | | | | Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
* Add string parameter to WASM_UNREACHABLE (#2499)Sam Clegg2019-12-051-5/+5
| | | | | This works more like llvm's unreachable handler in that is preserves information even in release builds.
* cmake: Convert to using lowercase for and functions/macros (#2495)Sam Clegg2019-12-041-2/+2
| | | This is line with modern cmake conventions is much less SHOUTY!
* Collect all object files from the object libraries in a CMake variable (#2477)Immanuel Haffner2019-11-261-1/+1
| | | | | | | | | using the `$<TARGET_OBJECTS:objlib>` syntax. Use this variable when adding `libbinaryen` as static or shared library. Additionally, use the variable with the object files to simplify the `TARGET_LINK_LIBRARIES` commands: add the object libraries to the sources of executables and drop the use of our libraries in `TARGET_LINK_LIBRARIES`. (Object libraries cannot be linked but must be used as sources. See https://cmake.org/pipermail/cmake/2018-June/067721.html)
* Revert "Build libbinaryen as a monolithic statically/shared library (#2463)" ↵Alon Zakai2019-11-251-1/+1
| | | | | (#2474) This reverts commit bf8f36c31c0b8e6213bce840be66937dd6d0f6af.
* Build libbinaryen as a monolithic statically/shared library (#2463)Immanuel Haffner2019-11-221-1/+1
| | | | | | | | | | | | * Transform libraries created in subdirectories from statically linked libraries to CMake object libraries. * Link object libraries as `PRIVATE` to `libbinaryen`. According to CMake documentation: "Libraries and targets following PRIVATE are linked to, but are not made part of the link interface." This is exactly what we want, as we only want the C API to be part of the interface.
* Add initial support for anyref as an opaque type (#2294)Jay Phelps2019-08-201-1/+7
| | | | | | | | | | | | | 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.
* Support empty export names in wasm2js and JS mangling in general (#2290)Alon Zakai2019-08-091-0/+6
|
* Rename except_ref type to exnref (#2224)Heejin Ahn2019-07-141-4/+4
| | | | In WebAssembly/exception-handling#79 we agreed to rename `except_ref` type to `exnref`.
* Stop emitting "almost asm" in wasm2js output (#2221)Alon Zakai2019-07-122-4/+0
| | | We don't ever emit "use asm" anymore, so this similar annotation is not really useful, it just increases size.
* Refactor type and function parsing (#2143)Heejin Ahn2019-05-241-15/+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`.
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-212-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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.
* Add except_ref type (#2081)Heejin Ahn2019-05-071-0/+6
| | | | This adds except_ref type, which is a part of the exception handling proposal.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-265-286/+257
| | | 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: use scratch memory properly (#2033)Alon Zakai2019-04-221-0/+16
| | | | | | | 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.
* Require unique_ptr to Module::addFunctionType() (#1672)Paweł Bylica2019-01-101-3/+2
| | | | | 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.
* constant refactoring for STACKTOP and STACK_MAXAlon Zakai2018-12-112-0/+4
|