summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Refactor type and function parsing (#2143)Heejin Ahn2019-05-241-187/+192
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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-32/+36
| | | | | 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-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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.
* Remove old import/export parsing routines (NFC) (#2127)Heejin Ahn2019-05-211-26/+1
| | | These formats don't seem to be used now.
* Refactor type/signature/local parsing methods (NFC) (#2129)Heejin Ahn2019-05-211-86/+105
| | | | | - Created `parseParamOrLocals`, `parseNamedParamOrLocals`, `parseResult`, and `parseTypeRef` and make other methods use them - Deleted some unnecessary member variables
* Add except_ref type (#2081)Heejin Ahn2019-05-071-0/+3
| | | | This adds except_ref type, which is a part of the exception handling proposal.
* Optimize mutable globals (#2066)Alon Zakai2019-05-021-4/+0
| | | | | | | If a global is marked mutable but not assigned to, make it immutable. If an immutable global is a copy of another, use the original, so we can remove the duplicates. Fixes #2011
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-151/+290
| | | 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-233/+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
* Passive segments (#1976)Thomas Lively2019-04-051-10/+18
| | | | | Adds support for the bulk memory proposal's passive segments. Uses a new (data passive ...) s-expression syntax to mark sections as passive.
* 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.
* Update v128.const text formats (#1934)Thomas Lively2019-03-191-27/+29
| | | | | Parse the formats allowed by the spec proposal and emit the i32x4 canonical format.
* Consistently optimize small added constants into load/store offsets (#1924)Alon Zakai2019-03-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | See #1919 - we did not do this consistently before. This adds a lowMemoryUnused option to PassOptions. It can be passed on the commandline with --low-memory-unused. If enabled, we run the new optimize-added-constants pass, which does the real work here, replacing older code in post-emscripten. Aside from running at the proper time (unlike the old pass, see #1919), this also has a -propagate mode, which can do stuff like this: y = x + 10 [..] load(y) [..] load(y) => y = x + 10 [..] load(x, offset=10) [..] load(x, offset=10) That is, it can propagate such offsets to the loads/stores. This pattern is common in big interpreter loops, where the pointers are offsets into a big struct of state. The pass does this propagation by using a new feature of LocalGraph, which can verify which locals are in SSA mode. Binaryen IR is not SSA (intentionally, since it's a later IR), but if a local only has a single set for all gets, that means that local is in such a state, and can be optimized. The tricky thing is that all locals are initialized to zero, so there are at minimum two sets. But if we verify that the real set dominates all the gets, then the zero initialization cannot reach them, and we are safe. This PR also makes safe-heap aware of lowMemoryUnused. If so, we check for not just an access of 0, but the range 0-1023. This makes zlib 5% faster, with either the wasm backend or asm2wasm. It also makes it 0.5% smaller. Also helps sqlite (1.5% faster) and lua (1% faster)
* throw an early error in s-expr-parsing makeBlock, if not inside a function ↵Alon Zakai2019-02-061-0/+1
| | | | | (#1894) Fixes #1893
* Bulk memory operations (#1892)Thomas Lively2019-02-051-0/+35
| | | | | | Bulk memory operations The only parts missing are the interpreter implementation and spec tests.
* More misc ASAN fixes (#1882)Alon Zakai2019-01-221-0/+3
| | | | | | | | | | * 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
* Misc minor ASAN fixes (#1869)Alon Zakai2019-01-161-4/+3
| | | | | | | | | | * handle end of input in skipWhitespace in s-parser. fixes #1863 * ignore debug locations when not in a function ; fixes #1867 * error properly on invalid user section sizes ; fixes #1866 * throw a proper error on invalid call offsets in binary reading ; fixes #1865
* Code style improvements (#1868)Alon Zakai2019-01-151-2/+2
| | | | * Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
* Require unique_ptr to Module::addFunctionType() (#1672)Paweł Bylica2019-01-101-2/+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.
* Massive renaming (#1855)Thomas Lively2019-01-071-5/+5
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* Rename `idx` to `index` in SIMD code for consistency (#1836)Thomas Lively2018-12-181-4/+4
|
* SIMD (#1820)Thomas Lively2018-12-131-2/+125
| | | | | | | | | Implement and test the following functionality for SIMD. - Parsing and printing - Assembling and disassembling - Interpretation - C API - JS API
* Fuzzing: log values during execution (#1779)Alon Zakai2018-11-301-1/+1
| | | | | | | | Before we just looked at function return values when looking for differences before and after running some passes, while fuzzing. This adds logging of values during execution, which can represent control flow, monitor locals, etc., giving a lot more opportunities for the fuzzer to find problems. Also: * Clean up the sigToFunctionType function, which allocated a struct and returned it. This makes it safer by returning the struct by value, which is also easier to use in this PR. * Fix printing of imported function calls without a function type - turns out we always generate function types in loading, so we didn't notice this was broken, but this new fuzzer feature hit it.
* Add support for a mutable globals as a Feature (#1785)Sam Clegg2018-11-301-2/+4
| | | | | This picks up from #1644 and indeed borrows the test case from there.
* Generate sexp instruction parser (#1754)Thomas Lively2018-11-191-290/+12
| | | Also fix broken tests surfaced by the new parser.
* Fix alignment in MixedAllocator (#1740)Alon Zakai2018-11-131-1/+1
| | | Necessary for simd, as we add a type with alignment >8. We were just broken on that before this PR.
* add support for new call_indirect syntax ; fixes #1724 (#1725)Alon Zakai2018-11-051-8/+29
|
* Support 4GB Memories (#1702)Alon Zakai2018-10-151-2/+5
| | | This fixes asm2wasm parsing of the max to allow 4GB, and also changes the internal Memory::kMaxValue values to reflect that. We used to use kMaxValue to also represent "no limit", so I split that out into kUnlimitedValue.
* Unify imported and non-imported things (#1678)Alon Zakai2018-09-191-95/+71
| | | | | | | | | | | | | | 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.
* Add debug information locations to the function prolog/epilog (#1674)Yury Delendik2018-09-171-13/+27
| | | | | | | The current patch: * Preserves the debug locations from function prolog and epilog * Preserves the debug locations of the nested blocks
* remove PageSize and HasFeature, which wasm removed a while back (#1667)Alon Zakai2018-09-121-7/+1
| | | From #1665 (a fuzz bug noticed they were not handled in stack.h).
* Fix parsing of memory attributes in s-expression parser (#1666)Alon Zakai2018-09-111-13/+21
| | | | | We need to check not to read past the length of the string. From #1665
* Some simple integer math opts (#1504)Alon Zakai2018-04-111-1/+1
| | | | | | | | | Stuff like x + 5 != 2 => x != -3. Also some cleanups of utility functions I noticed while writing this, isTypeFloat => isFloatType. Inspired by https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules
* check for errors when parsing s-expression load/store immediates (#1475)Alon Zakai2018-03-161-2/+6
|
* Fix -Wcatch-value from GCC 8 (#1400)Josh Stone2018-02-051-2/+2
| | | These instances may simply be caught by reference instead.
* Rename WasmType => Type (#1398)Alon Zakai2018-02-021-43/+43
| | | | * rename WasmType to Type. it's in the wasm:: namespace anyhow, and without Wasm- it fits in better alongside Index, Address, Expression, Module, etc.
* Update call_indirect text syntax to match spec update (#1281)Derek Schuff2017-11-131-1/+3
| | | | Function type gets its own element rather than being a part of the call_indirect (see WebAssembly/spec#599)
* 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).
* Update text syntax for shared memory limits (#1197)Derek Schuff2017-09-221-13/+16
| | | | Following WebAssembly/threads#58 e.g. (memory $0 23 256 shared) is now (memory $0 (shared 23 256))
* remove implicit fallthroughs (#1194) (#1196)Jeremy Day2017-09-201-0/+1
|
* Add support for sign-extension operators from threading proposal (#1167)Derek Schuff2017-09-061-1/+8
| | | 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).
* Add support for atomic wait and wake operators (#1140)Derek Schuff2017-08-241-0/+24
| | | According to spec at https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-wake-operators
* wasm2asm test generation (#1124)Thomas Lively2017-08-161-1/+1
| | | | | | | | | | | | | | | | | * 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
* add the option to seek named breaks, not just taken breaks; refactor headers ↵Alon Zakai (kripken)2017-07-111-2/+2
| | | | to make this practical
* Add IR, parsing, printing, and binary for atomic cmpxchg (#1083)Derek Schuff2017-07-101-5/+25
|
* Add IR, parsing and binary support for AtomicRMW instructions from wasm ↵Derek Schuff2017-07-061-60/+69
| | | | | threads proposal (#1082) Also leave a stub (but valid) visitAtomicRMW in the visitor template so that not all visitors need to implement this function yet.
* Add atomic loads and stores (#1077)Derek Schuff2017-06-281-5/+13
| | | | | Add IR, wast and binary support for atomic loads and stores. Currently all IR generated by means other than parsing wast and binary files always generates non-atomic accesses, and optimizations have not yet been made aware of atomics, so they are certainly not ready to be used yet.
* Add shared memories (#1069)Derek Schuff2017-06-271-14/+22
| | | | | Begin to implement wasm threading proposal in https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md This PR just has shared memory attribute with wast and binary support.
* Support new result syntax for if/loop/block (#1047)Sam Clegg2017-06-121-18/+28
| | | | | | Support both syntax formats in input since the old spec tests still need to be parsable.
* clean up unnecessary spacingAlon Zakai2017-06-011-1/+1
|