├── .ahub └── sam │ └── exclude.txt ├── .clang-format ├── .flake8 ├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ └── actions.yml ├── .gitignore ├── .gitmodules ├── .style.yapf ├── CMakeLists.txt ├── LICENSE ├── README.md ├── build ├── config.cmake ├── target.cmake └── walrus.cmake ├── src ├── Walrus.h ├── api │ ├── wasm.cpp │ └── wasm.h ├── interpreter │ ├── ByteCode.cpp │ ├── ByteCode.h │ ├── Interpreter.cpp │ └── Interpreter.h ├── jit │ ├── Analysis.cpp │ ├── Backend.cpp │ ├── ByteCodeParser.cpp │ ├── CallInl.h │ ├── Compiler.h │ ├── FloatConvInl.h │ ├── FloatMathInl.h │ ├── InstList.cpp │ ├── IntMath32Inl.h │ ├── IntMath64Inl.h │ ├── MemoryInl.h │ ├── MemoryUtilInl.h │ ├── PerfDump.cpp │ ├── PerfDump.h │ ├── RegisterAlloc.cpp │ ├── SimdArm32Inl.h │ ├── SimdArm64Inl.h │ ├── SimdInl.h │ ├── SimdRiscvInl.h │ ├── SimdX86Inl.h │ ├── SljitLir.h │ ├── TableInl.h │ └── TryCatchInl.h ├── parser │ ├── WASMParser.cpp │ └── WASMParser.h ├── runtime │ ├── DefinedFunctionTypes.h │ ├── Engine.h │ ├── Exception.cpp │ ├── Exception.h │ ├── ExecutionState.h │ ├── Function.cpp │ ├── Function.h │ ├── Global.h │ ├── Instance.cpp │ ├── Instance.h │ ├── JITExec.cpp │ ├── JITExec.h │ ├── Memory.cpp │ ├── Memory.h │ ├── Module.cpp │ ├── Module.h │ ├── Object.h │ ├── ObjectType.cpp │ ├── ObjectType.h │ ├── Store.cpp │ ├── Store.h │ ├── Table.cpp │ ├── Table.h │ ├── Tag.h │ ├── Trap.cpp │ ├── Trap.h │ └── Value.h ├── shell │ └── Shell.cpp ├── util │ ├── BitOperation.h │ ├── MathOperation.h │ ├── Optional.h │ ├── Util.h │ ├── Vector.cpp │ └── Vector.h └── wasi │ ├── WASI.cpp │ └── WASI.h ├── test ├── basic │ ├── block.wast │ ├── br.wast │ ├── br_table.wast │ ├── ifelse.wast │ ├── local.wast │ ├── loop.wast │ ├── memory.wast │ ├── missing_end.wast │ ├── optimalisationCheck.wast │ ├── read_ahead_fix.wast │ ├── ref_local_twice_and_modify.wast │ ├── select.wast │ ├── trycatch.wast │ └── v128_select.wast ├── extended │ ├── relaxed-simd │ │ ├── i16x8_relaxed_q15mulr_s.wast │ │ ├── i32x4_relaxed_trunc.wast │ │ ├── i8x16_relaxed_swizzle.wast │ │ ├── relaxed_dot_product.wast │ │ ├── relaxed_laneselect.wast │ │ ├── relaxed_madd_nmadd.wast │ │ └── relaxed_min_max.wast │ └── threads │ │ ├── atomic.wast │ │ ├── atomic_wait_notify.wast │ │ ├── atomic_wait_notify_with_offsets.wast │ │ └── atomic_with_offsets.wast ├── jit │ ├── binary-base.wast │ ├── binary-divmod32.wast │ ├── binary-divmod64.wast │ ├── binary-logical.wast │ ├── binary-multiply.wast │ ├── binary-shift.wast │ ├── block1.wast │ ├── block2.wast │ ├── compare-simd.wast │ ├── compare.wast │ ├── convert.wast │ ├── extend.wast │ ├── f32-operations.wast │ ├── f64-operations.wast │ ├── global.wast │ ├── indirect_i64_const_store.wast │ ├── local-elim1.wast │ ├── locals-remap1.wast │ ├── memory.wast │ ├── memory_large.wast │ ├── select1.wast │ ├── simd-shuffle.wast │ ├── splat.wast │ ├── table.wast │ ├── trycatch-dep.wast │ ├── trycatch-mem.wast │ ├── trycatch.wast │ ├── unary.wast │ └── unreachable.wast ├── perf │ └── quicksort_recursive.wast ├── wasi │ ├── args.wast │ ├── clock.wast │ ├── environ.wast │ ├── fd_advise.wast │ ├── fd_fdstat_get.wast │ ├── fd_prestat.wast │ ├── fd_seek.wast │ ├── filesystem_functions.wast │ ├── hello_world.wast │ ├── print.wast │ ├── proc_exit.wast │ ├── proc_raise.wast │ ├── random_get.wast │ ├── read_from_file.wast │ ├── some_file.txt │ ├── text.txt │ ├── write_to_file.wast │ └── write_to_this.txt ├── wasm-spec │ ├── LICENSE │ ├── README.md │ └── core │ │ ├── address.wast │ │ ├── align.wast │ │ ├── binary-leb128.wast │ │ ├── binary.wast │ │ ├── block.wast │ │ ├── br.wast │ │ ├── br_if.wast │ │ ├── br_table.wast │ │ ├── bulk.wast │ │ ├── call.wast │ │ ├── call_indirect.wast │ │ ├── comments.wast │ │ ├── const.wast │ │ ├── conversions.wast │ │ ├── custom.wast │ │ ├── data.wast │ │ ├── elem.wast │ │ ├── endianness.wast │ │ ├── exports.wast │ │ ├── f32.wast │ │ ├── f32_bitwise.wast │ │ ├── f32_cmp.wast │ │ ├── f64.wast │ │ ├── f64_bitwise.wast │ │ ├── f64_cmp.wast │ │ ├── fac.wast │ │ ├── float_exprs.wast │ │ ├── float_literals.wast │ │ ├── float_memory.wast │ │ ├── float_misc.wast │ │ ├── forward.wast │ │ ├── func.wast │ │ ├── func_ptrs.wast │ │ ├── global.wast │ │ ├── i32.wast │ │ ├── i64.wast │ │ ├── if.wast │ │ ├── imports.wast │ │ ├── inline-module.wast │ │ ├── int_exprs.wast │ │ ├── int_literals.wast │ │ ├── labels.wast │ │ ├── left-to-right.wast │ │ ├── linking.wast │ │ ├── load.wast │ │ ├── local_get.wast │ │ ├── local_set.wast │ │ ├── local_tee.wast │ │ ├── loop.wast │ │ ├── memory.wast │ │ ├── memory_copy.wast │ │ ├── memory_fill.wast │ │ ├── memory_grow.wast │ │ ├── memory_init.wast │ │ ├── memory_redundancy.wast │ │ ├── memory_size.wast │ │ ├── memory_trap.wast │ │ ├── multi-memory │ │ ├── address0.wast │ │ ├── address1.wast │ │ ├── align0.wast │ │ ├── binary0.wast │ │ ├── data0.wast │ │ ├── data1.wast │ │ ├── data_drop0.wast │ │ ├── exports0.wast │ │ ├── float_exprs0.wast │ │ ├── float_exprs1.wast │ │ ├── float_memory0.wast │ │ ├── imports0.wast │ │ ├── imports1.wast │ │ ├── imports2.wast │ │ ├── imports3.wast │ │ ├── imports4.wast │ │ ├── linking0.wast │ │ ├── linking1.wast │ │ ├── linking2.wast │ │ ├── linking3.wast │ │ ├── load0.wast │ │ ├── load1.wast │ │ ├── load2.wast │ │ ├── memory_copy0.wast │ │ ├── memory_copy1.wast │ │ ├── memory_fill0.wast │ │ ├── memory_init0.wast │ │ ├── memory_size0.wast │ │ ├── memory_size1.wast │ │ ├── memory_size2.wast │ │ ├── memory_size3.wast │ │ ├── memory_trap0.wast │ │ ├── memory_trap1.wast │ │ ├── start0.wast │ │ ├── store0.wast │ │ ├── store1.wast │ │ └── traps0.wast │ │ ├── names.wast │ │ ├── nop.wast │ │ ├── ref_func.wast │ │ ├── ref_is_null.wast │ │ ├── ref_null.wast │ │ ├── return.wast │ │ ├── select.wast │ │ ├── simd │ │ ├── simd_address.wast │ │ ├── simd_align.wast │ │ ├── simd_bit_shift.wast │ │ ├── simd_bitwise.wast │ │ ├── simd_boolean.wast │ │ ├── simd_const.wast │ │ ├── simd_conversions.wast │ │ ├── simd_f32x4.wast │ │ ├── simd_f32x4_arith.wast │ │ ├── simd_f32x4_cmp.wast │ │ ├── simd_f32x4_pmin_pmax.wast │ │ ├── simd_f32x4_rounding.wast │ │ ├── simd_f64x2.wast │ │ ├── simd_f64x2_arith.wast │ │ ├── simd_f64x2_cmp.wast │ │ ├── simd_f64x2_pmin_pmax.wast │ │ ├── simd_f64x2_rounding.wast │ │ ├── simd_i16x8_arith.wast │ │ ├── simd_i16x8_arith2.wast │ │ ├── simd_i16x8_cmp.wast │ │ ├── simd_i16x8_extadd_pairwise_i8x16.wast │ │ ├── simd_i16x8_extmul_i8x16.wast │ │ ├── simd_i16x8_q15mulr_sat_s.wast │ │ ├── simd_i16x8_sat_arith.wast │ │ ├── simd_i32x4_arith.wast │ │ ├── simd_i32x4_arith2.wast │ │ ├── simd_i32x4_cmp.wast │ │ ├── simd_i32x4_dot_i16x8.wast │ │ ├── simd_i32x4_extadd_pairwise_i16x8.wast │ │ ├── simd_i32x4_extmul_i16x8.wast │ │ ├── simd_i32x4_trunc_sat_f32x4.wast │ │ ├── simd_i32x4_trunc_sat_f64x2.wast │ │ ├── simd_i64x2_arith.wast │ │ ├── simd_i64x2_arith2.wast │ │ ├── simd_i64x2_cmp.wast │ │ ├── simd_i64x2_extmul_i32x4.wast │ │ ├── simd_i8x16_arith.wast │ │ ├── simd_i8x16_arith2.wast │ │ ├── simd_i8x16_cmp.wast │ │ ├── simd_i8x16_sat_arith.wast │ │ ├── simd_int_to_int_extend.wast │ │ ├── simd_lane.wast │ │ ├── simd_linking.wast │ │ ├── simd_load.wast │ │ ├── simd_load16_lane.wast │ │ ├── simd_load32_lane.wast │ │ ├── simd_load64_lane.wast │ │ ├── simd_load8_lane.wast │ │ ├── simd_load_extend.wast │ │ ├── simd_load_splat.wast │ │ ├── simd_load_zero.wast │ │ ├── simd_splat.wast │ │ ├── simd_store.wast │ │ ├── simd_store16_lane.wast │ │ ├── simd_store32_lane.wast │ │ ├── simd_store64_lane.wast │ │ └── simd_store8_lane.wast │ │ ├── skip-stack-guard-page.wast │ │ ├── stack.wast │ │ ├── start.wast │ │ ├── store.wast │ │ ├── switch.wast │ │ ├── table-sub.wast │ │ ├── table.wast │ │ ├── table_copy.wast │ │ ├── table_fill.wast │ │ ├── table_get.wast │ │ ├── table_grow.wast │ │ ├── table_init.wast │ │ ├── table_set.wast │ │ ├── table_size.wast │ │ ├── token.wast │ │ ├── tokens.wast │ │ ├── traps.wast │ │ ├── try_catch.wast │ │ ├── type.wast │ │ ├── unreachable.wast │ │ ├── unreached-invalid.wast │ │ ├── unreached-valid.wast │ │ ├── unwind.wast │ │ ├── utf8-custom-section-id.wast │ │ ├── utf8-import-field.wast │ │ ├── utf8-import-module.wast │ │ └── utf8-invalid-encoding.wast └── wasmBenchmarker │ ├── benchmark.py │ └── ctests │ ├── change.c │ ├── factorial.c │ ├── fannkuch.c │ ├── fibonacci.c │ ├── gregory.c │ ├── hanoi.c │ ├── heapsort.c │ ├── huffman.c │ ├── include │ ├── mandelbrot.h │ ├── memory.h │ ├── random.h │ └── simdMandelbrot.h │ ├── kNucleotide.c │ ├── mandelbrotDouble.c │ ├── mandelbrotFloat.c │ ├── matrixMultiply.c │ ├── miniWalrus.c │ ├── nbody.c │ ├── nqueens.c │ ├── prime.c │ ├── quickSort.c │ ├── redBlack.c │ ├── rsa.c │ ├── salesman.c │ ├── simdMandelbrotDouble.c │ ├── simdMandelbrotFloat.c │ ├── simdMatrixMultiply.c │ ├── simdNbody.c │ └── ticTacToe.c ├── third_party ├── uvwasi │ └── CMakeLists.txt └── wabt │ ├── CMakeLists.txt │ ├── Contributing.md │ ├── LICENSE │ ├── Makefile │ ├── include │ ├── string-view-lite │ │ ├── LICENSE.txt │ │ └── string_view.h │ └── wabt │ │ ├── base-types.h │ │ ├── binary-reader-ir.h │ │ ├── binary-reader-logging.h │ │ ├── binary-reader-nop.h │ │ ├── binary-reader.h │ │ ├── binary-writer.h │ │ ├── binary.h │ │ ├── binding-hash.h │ │ ├── cast.h │ │ ├── common.h │ │ ├── error.h │ │ ├── expr-visitor.h │ │ ├── feature.def │ │ ├── feature.h │ │ ├── intrusive-list.h │ │ ├── ir.h │ │ ├── leb128.h │ │ ├── lexer-source-line-finder.h │ │ ├── lexer-source.h │ │ ├── literal.h │ │ ├── make-unique.h │ │ ├── opcode-code-table.h │ │ ├── opcode.def │ │ ├── opcode.h │ │ ├── option-parser.h │ │ ├── range.h │ │ ├── resolve-names.h │ │ ├── result.h │ │ ├── shared-validator.h │ │ ├── stream.h │ │ ├── string-format.h │ │ ├── token.def │ │ ├── token.h │ │ ├── tracing.h │ │ ├── type-checker.h │ │ ├── type.h │ │ ├── utf8.h │ │ ├── validator.h │ │ ├── walrus │ │ └── binary-reader-walrus.h │ │ ├── wast-lexer.h │ │ └── wast-parser.h │ ├── src │ ├── binary-reader-ir.cc │ ├── binary-reader-logging.cc │ ├── binary-reader.cc │ ├── binary-writer.cc │ ├── binary.cc │ ├── binding-hash.cc │ ├── common.cc │ ├── config.cc │ ├── config.h.in │ ├── expr-visitor.cc │ ├── feature.cc │ ├── ir.cc │ ├── leb128.cc │ ├── lexer-source.cc │ ├── literal.cc │ ├── opcode-code-table.c │ ├── opcode.cc │ ├── option-parser.cc │ ├── prebuilt │ │ ├── .clang-format │ │ └── lexer-keywords.cc │ ├── resolve-names.cc │ ├── shared-validator.cc │ ├── stream.cc │ ├── token.cc │ ├── type-checker.cc │ ├── utf8.cc │ ├── walrus │ │ └── binary-reader-walrus.cc │ ├── wast-lexer.cc │ └── wast-parser.cc │ └── ubsan.blacklist └── tools ├── check_tidy.py ├── jit_exclude_list.txt └── run-tests.py /.ahub/sam/exclude.txt: -------------------------------------------------------------------------------- 1 | # Exclude external third-party libraries 2 | /walrus/third_party/wabt/include/wabt/wast-parser.h 3 | /walrus/third_party/wabt/src/binary-reader.cc 4 | 5 | # Exclude parser/interpreter codes which have intensive control statements and similar patterns essentially used for compilation and execution 6 | /walrus/src/parser/WASMParser.cpp 7 | /walrus/src/runtime/Module.h 8 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = 3 | E501, # line too long 4 | W504 # line break after binary operator 5 | exclude = ./third_party ./out 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.c text 3 | *.h text 4 | *.js text 5 | *.l text 6 | *.md text 7 | *.py text 8 | *.rst text 9 | *.sh text 10 | *.txt text 11 | *.y text 12 | docs/demo/primer.css binary 13 | docs/demo/libwabt.js binary 14 | docs/demo/third_party/codemirror/codemirror.css binary 15 | docs/demo/third_party/codemirror/codemirror.js binary 16 | 17 | # Mark these tests as binary so git doesn't change the line endings: 18 | test/parse/bad-crlf.txt binary 19 | test/parse/bad-string-eof.txt binary 20 | test/regress/regress-31.txt binary 21 | 22 | # Highlight tests like .wast files when displayed on GitHub. 23 | test/**/*.txt linguist-language=WebAssembly 24 | 25 | # Mark test-files as "vendored". This tells GitHub to exclude them when it 26 | # calculates the repository's languages summary, and preserves the current 27 | # classification as a C++ project. See https://git.io/vr2pO 28 | test/**/*.txt linguist-vendored 29 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This is a comment. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | * @ksh8281 @clover2123 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /out 3 | /fuzz-out 4 | /emscripten 5 | *.pyc 6 | *.swp 7 | .idea/ 8 | .vscode 9 | /cmake-build-debug/ 10 | tags 11 | cscope.out 12 | CMakeCache.txt 13 | CMakeFiles 14 | cmake_install.cmake 15 | build.ninja 16 | rules.ninja 17 | .ninja_deps 18 | .ninja_log 19 | node_modules 20 | /test/wasmBenchmarker/ctests/wasm 21 | /test/wasmBenchmarker/emsdk 22 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/sljit"] 2 | path = third_party/sljit 3 | url = https://github.com/zherczeg/sljit 4 | ignore = untracked 5 | [submodule "third_party/wasm-c-api"] 6 | path = third_party/wasm-c-api 7 | url = https://github.com/WebAssembly/wasm-c-api 8 | ignore = untracked 9 | [submodule "third_party/uvwasi/uvwasi"] 10 | path = third_party/uvwasi/uvwasi 11 | url = https://github.com/nodejs/uvwasi 12 | ignore = untracked 13 | -------------------------------------------------------------------------------- /.style.yapf: -------------------------------------------------------------------------------- 1 | [style] 2 | split_before_named_assigns = False 3 | based_on_style = chromium 4 | column_limit = 79 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WALRUS: WebAssembly Lightweight RUntime 2 | 3 | [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 4 | [![Actions Status](https://github.com/Samsung/walrus/actions/workflows/actions.yml/badge.svg)](https://github.com/Samsung/walrus/actions) 5 | [![Coverity Scan Build Status](https://scan.coverity.com/projects/26942/badge.svg)](https://scan.coverity.com/projects/samsung-walrus) 6 | 7 | This project aims to provide a lightweight WebAssembly runtime engine. It now fully supports WebAssembly specs with an simple interpreter, but we plan to optimize interpreting as well as adopting JIT compiler for better performance. 8 | 9 | ## Cloning 10 | 11 | Clone as normal, but don't forget to get the submodules as well: 12 | 13 | ```console 14 | $ git clone --recursive https://github.com/Samsung/walrus 15 | $ cd walrus 16 | $ git submodule update --init 17 | ``` 18 | 19 | This will fetch the testsuite and gtest repos, which are needed for some tests. 20 | 21 | ## Building using CMake 22 | 23 | You'll need [CMake](https://cmake.org). You can then run CMake, the normal way: 24 | 25 | ```console 26 | $ cmake -H. -Bout/release/x64 -DWALRUS_ARCH=x64 -DWALRUS_HOST=linux -DWALRUS_MODE=release -DWALRUS_OUTPUT=shell -GNinja 27 | $ ninja -Cout/release/x64 28 | $ ./out/release/x64/walrus test.wasm // run walrus executable 29 | ``` 30 | 31 | This will produce build files using CMake's default build generator. Read the 32 | CMake documentation for more information. 33 | 34 | ## Perf 35 | 36 | You'll need [Perf](https://perf.wiki.kernel.org/index.php/Main_Page). 37 | 38 | 0. To compile with perf support, use `-DWALRUS_JITPERF=1` 39 | 40 | 1. Set the path where temporary files are created with `WALRUS_PERF_DIR` environment variable. 41 | Run Walrus with: `sudo perf record -k 1 walrus --jit WALRUS_PARAMETERS` 42 | The `-k 1` option sets the monotonic clock, `-k mono` is also correct. 43 | 44 | Three files are generated: 45 | - perf.data - it is generated by perf 46 | - jit-XXXXXX.dump - The dump of jit generated functions, XXXXXX is the PID of process 47 | - jit-XXXXXX-codedump.txt - Walrus ByteCode dump, XXXXXX is the PID of process 48 | 49 | 2. You should chown perf.data, because you don't need `sudo` after that. 50 | 51 | 3. Inject JITDump file into `perf.data` with `perf inject --jit -i perf.data -o perf.data.jitted` 52 | 53 | It'll generate many shared object files, and `perf.data.jitted` 54 | 55 | 4. View the report with `perf report -i perf.data.jitted` 56 | -------------------------------------------------------------------------------- /build/config.cmake: -------------------------------------------------------------------------------- 1 | ####################################################### 2 | # CONFIGURATION 3 | ####################################################### 4 | 5 | ####################################################### 6 | # PATH 7 | ####################################################### 8 | SET (WALRUS_ROOT ${PROJECT_SOURCE_DIR}) 9 | SET (WALRUS_THIRD_PARTY_ROOT ${WALRUS_ROOT}/third_party) 10 | SET (SLJIT_ROOT ${WALRUS_THIRD_PARTY_ROOT}/sljit) 11 | 12 | ####################################################### 13 | # FLAGS FOR TARGET 14 | ####################################################### 15 | INCLUDE (${WALRUS_ROOT}/build/target.cmake) 16 | 17 | ####################################################### 18 | # FLAGS FOR COMMON 19 | ####################################################### 20 | # WALRUS COMMON CXXFLAGS 21 | SET (WALRUS_DEFINITIONS 22 | ${WALRUS_DEFINITIONS} 23 | -DWALRUS 24 | ) 25 | 26 | SET (CXXFLAGS_FROM_ENV $ENV{CXXFLAGS}) 27 | SEPARATE_ARGUMENTS(CXXFLAGS_FROM_ENV) 28 | SET (LDFLAGS_FROM_ENV $ENV{LDFLAGS}) 29 | SEPARATE_ARGUMENTS(LDFLAGS_FROM_ENV) 30 | 31 | # these flags assigned from external should have the highest priority 32 | SET (CXXFLAGS_FROM_ENV ${CXXFLAGS_FROM_ENV} ${WALRUS_CXXFLAGS_FROM_EXTERNAL}) 33 | SET (LDFLAGS_FROM_ENV ${LDFLAGS_FROM_ENV} ${WALRUS_LDFLAGS_FROM_EXTERNAL}) 34 | 35 | IF (${WALRUS_OUTPUT} STREQUAL "shared_lib" AND ${WALRUS_HOST} STREQUAL "android") 36 | SET (WALRUS_LDFLAGS ${WALRUS_LDFLAGS} -shared) 37 | ENDIF() 38 | 39 | IF (NOT DEFINED WALRUS_JIT) 40 | SET (WALRUS_JIT ON) 41 | ENDIF() 42 | 43 | ####################################################### 44 | # FLAGS FOR ADDITIONAL FUNCTION 45 | ####################################################### 46 | SET (WALRUS_LIBRARIES) 47 | SET (WALRUS_INCDIRS) 48 | 49 | IF (WALRUS_JIT) 50 | SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} -DWALRUS_ENABLE_JIT) 51 | ENDIF() 52 | 53 | ####################################################### 54 | # FLAGS FOR TEST 55 | ####################################################### 56 | SET (WALRUS_DEFINITIONS_TEST -DWALRUS_ENABLE_TEST) 57 | 58 | ####################################################### 59 | # FLAGS FOR MEMORY PROFILING 60 | ####################################################### 61 | SET (PROFILER_FLAGS) 62 | 63 | IF (WALRUS_VALGRIND) 64 | SET (PROFILER_FLAGS ${PROFILER_FLAGS} -DWALRUS_VALGRIND) 65 | ENDIF() 66 | -------------------------------------------------------------------------------- /src/jit/PerfDump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #if defined WALRUS_JITPERF 18 | #ifndef __WalrusJITPERF__ 19 | #define __WalrusJITPERF_ 20 | 21 | #include "jit/Compiler.h" 22 | 23 | namespace Walrus { 24 | 25 | class PerfDump { 26 | public: 27 | static PerfDump& instance(); 28 | 29 | PerfDump(); 30 | bool perfEnabled() { return m_file != nullptr; } 31 | void dumpRecordHeader(const uint32_t recordType, const uint32_t entrySize); 32 | void dumpCodeLoad(const uint64_t vma, const uint64_t codeAddr, const uint64_t codeSize, const std::string& functionName, const uint8_t* nativeCode); 33 | #if !defined(NDEBUG) 34 | size_t dumpDebugInfo(std::vector& debugEntries, size_t debugEntryStart, const uint64_t codeAddr); 35 | #endif /* !NDEBUG */ 36 | void dumpCodeClose(); 37 | ~PerfDump(); 38 | 39 | #if !defined(NDEBUG) 40 | uint32_t dumpProlog(Module* module, ModuleFunction* function); 41 | uint32_t dumpByteCode(InstructionListItem* item); 42 | uint32_t dumpEpilog(); 43 | #endif /* !NDEBUG */ 44 | 45 | private: 46 | void dumpFileHeader(); 47 | 48 | FILE* m_file = nullptr; 49 | uint32_t m_pid; 50 | uint64_t m_codeLoadIndex; 51 | 52 | #if !defined(NDEBUG) 53 | std::string m_sourceFileName; 54 | FILE* m_sourceFile = nullptr; 55 | uint32_t m_line; 56 | #endif /* !NDEBUG */ 57 | }; 58 | 59 | } // namespace Walrus 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /src/jit/SljitLir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusSljitLir__ 18 | #define __WalrusSljitLir__ 19 | 20 | #if defined(WALRUS_ENABLE_JIT) 21 | 22 | // Setup the configuration 23 | #define SLJIT_CONFIG_AUTO 1 24 | #define SLJIT_CONFIG_STATIC 1 25 | #define SLJIT_VERBOSE 0 26 | 27 | #if defined(NDEBUG) 28 | #define SLJIT_DEBUG 0 29 | #else 30 | #define SLJIT_DEBUG 1 31 | #endif 32 | 33 | extern "C" { 34 | #include "../../third_party/sljit/sljit_src/sljitLir.h" 35 | } 36 | 37 | #endif // WALRUS_ENABLE_JIT 38 | #endif // __WalrusSljitLir__ 39 | -------------------------------------------------------------------------------- /src/parser/WASMParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusWASMParser__ 18 | #define __WalrusWASMParser__ 19 | 20 | #include "runtime/Module.h" 21 | 22 | namespace Walrus { 23 | 24 | class Module; 25 | class Store; 26 | 27 | struct WASMParsingResult { 28 | // should be allocated in the stack 29 | MAKE_STACK_ALLOCATED(); 30 | 31 | WASMParsingResult(); 32 | 33 | void clear(); 34 | 35 | bool m_seenStartAttribute; 36 | uint32_t m_version; 37 | uint32_t m_start; 38 | 39 | Vector m_imports; 40 | Vector m_exports; 41 | 42 | Vector m_functions; 43 | 44 | Vector m_datas; 45 | Vector m_elements; 46 | 47 | Vector m_functionTypes; 48 | Vector m_globalTypes; 49 | Vector m_tableTypes; 50 | Vector m_memoryTypes; 51 | Vector m_tagTypes; 52 | }; 53 | 54 | class WASMParser { 55 | public: 56 | // returns 57 | static std::pair, std::string> parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const uint32_t JITFlags = 0, const uint32_t featureFlags = 0); 58 | }; 59 | 60 | } // namespace Walrus 61 | 62 | #endif // __WalrusParser__ 63 | -------------------------------------------------------------------------------- /src/runtime/Engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusEngine__ 18 | #define __WalrusEngine__ 19 | 20 | namespace Walrus { 21 | 22 | class Engine { 23 | }; 24 | 25 | } // namespace Walrus 26 | 27 | #endif // __WalrusEngine__ 28 | -------------------------------------------------------------------------------- /src/runtime/Exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Walrus.h" 17 | 18 | #include "Exception.h" 19 | 20 | namespace Walrus { 21 | 22 | Exception::Exception(ExecutionState& state) 23 | { 24 | Optional s = &state; 25 | 26 | while (s) { 27 | if (s->m_programCounterPointer) { 28 | m_programCounterInfo.pushBack(std::make_pair(s.value(), *s->m_programCounterPointer.value())); 29 | } 30 | s = s->m_parent; 31 | } 32 | } 33 | } // namespace Walrus 34 | -------------------------------------------------------------------------------- /src/runtime/ExecutionState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusExecutionState__ 18 | #define __WalrusExecutionState__ 19 | 20 | #include "util/Optional.h" 21 | #include "util/Util.h" 22 | 23 | namespace Walrus { 24 | 25 | class Function; 26 | 27 | class ExecutionState { 28 | public: 29 | friend class Exception; 30 | friend class Trap; 31 | friend class Interpreter; 32 | 33 | ExecutionState(ExecutionState& parent) 34 | : m_parent(&parent) 35 | , m_stackLimit(parent.m_stackLimit) 36 | { 37 | } 38 | 39 | ExecutionState(ExecutionState& parent, Function* currentFunction) 40 | : m_parent(&parent) 41 | , m_currentFunction(currentFunction) 42 | , m_stackLimit(parent.m_stackLimit) 43 | { 44 | } 45 | 46 | Optional currentFunction() const 47 | { 48 | return m_currentFunction; 49 | } 50 | 51 | size_t stackLimit() const 52 | { 53 | return m_stackLimit; 54 | } 55 | 56 | private: 57 | friend class ByteCodeTable; 58 | ExecutionState() 59 | { 60 | m_stackLimit = (size_t)currentStackPointer(); 61 | 62 | #ifdef STACK_GROWS_DOWN 63 | m_stackLimit = m_stackLimit - STACK_LIMIT_FROM_BASE; 64 | #else 65 | m_stackLimit = m_stackLimit + STACK_LIMIT_FROM_BASE; 66 | #endif 67 | } 68 | 69 | Optional m_parent; 70 | Optional m_currentFunction; 71 | size_t m_stackLimit; 72 | Optional m_programCounterPointer; 73 | }; 74 | 75 | } // namespace Walrus 76 | 77 | #endif // __WalrusFunction__ 78 | -------------------------------------------------------------------------------- /src/runtime/Global.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusGlobal__ 18 | #define __WalrusGlobal__ 19 | 20 | #include "runtime/Store.h" 21 | #include "runtime/Object.h" 22 | 23 | namespace Walrus { 24 | 25 | class Global : public Extern { 26 | friend class JITFieldAccessor; 27 | 28 | public: 29 | static Global* createGlobal(Store* store, const Value& value, const bool& mut) 30 | { 31 | Global* glob = new Global(value, mut); 32 | store->appendExtern(glob); 33 | return glob; 34 | } 35 | 36 | virtual Object::Kind kind() const override 37 | { 38 | return Object::GlobalKind; 39 | } 40 | 41 | virtual bool isGlobal() const override 42 | { 43 | return true; 44 | } 45 | 46 | Value& value() 47 | { 48 | return m_value; 49 | } 50 | 51 | Value value() const 52 | { 53 | return m_value; 54 | } 55 | 56 | bool isMutable() const 57 | { 58 | return m_mutable; 59 | } 60 | 61 | void setValue(const Value& value) 62 | { 63 | ASSERT(value.type() == m_value.type()); 64 | m_value = value; 65 | } 66 | 67 | private: 68 | Global(const Value& value, const bool& mut) 69 | : m_value(value) 70 | , m_mutable(mut) 71 | { 72 | } 73 | 74 | Value m_value; 75 | bool m_mutable; 76 | }; 77 | 78 | } // namespace Walrus 79 | 80 | #endif // __WalrusGlobal__ 81 | -------------------------------------------------------------------------------- /src/runtime/ObjectType.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "Walrus.h" 18 | 19 | #include "runtime/ObjectType.h" 20 | #include "runtime/Module.h" 21 | 22 | namespace Walrus { 23 | 24 | bool FunctionType::equals(const FunctionType* other) const 25 | { 26 | if (this == other) { 27 | return true; 28 | } 29 | 30 | if (m_paramTypes->size() != other->param().size()) { 31 | return false; 32 | } 33 | 34 | if (memcmp(m_paramTypes->data(), other->param().data(), sizeof(Value::Type) * other->param().size())) { 35 | return false; 36 | } 37 | 38 | if (m_resultTypes->size() != other->result().size()) { 39 | return false; 40 | } 41 | 42 | if (memcmp(m_resultTypes->data(), other->result().data(), sizeof(Value::Type) * other->result().size())) { 43 | return false; 44 | } 45 | 46 | return true; 47 | } 48 | 49 | GlobalType::GlobalType(Value::Type type, bool mut) 50 | : ObjectType(ObjectType::GlobalKind) 51 | , m_type(type) 52 | , m_mutable(mut) 53 | , m_function(nullptr) 54 | { 55 | #ifndef NDEBUG 56 | switch (type) { 57 | case Value::I32: 58 | case Value::I64: 59 | case Value::F32: 60 | case Value::F64: 61 | case Value::V128: 62 | case Value::FuncRef: 63 | case Value::ExternRef: 64 | return; 65 | default: 66 | ASSERT_NOT_REACHED(); 67 | return; 68 | } 69 | #endif 70 | } 71 | 72 | GlobalType::~GlobalType() 73 | { 74 | if (m_function) { 75 | delete m_function; 76 | } 77 | } 78 | 79 | } // namespace Walrus 80 | -------------------------------------------------------------------------------- /src/runtime/Store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusStore__ 18 | #define __WalrusStore__ 19 | 20 | #include "util/Vector.h" 21 | #include "runtime/Value.h" 22 | #include 23 | #include 24 | 25 | namespace Walrus { 26 | 27 | class Engine; 28 | class Module; 29 | class Instance; 30 | class Extern; 31 | class FunctionType; 32 | 33 | struct Waiter { 34 | struct WaiterItem { 35 | WaiterItem(Waiter* waiter) 36 | : m_waiter(waiter) 37 | { 38 | } 39 | 40 | Waiter* m_waiter; 41 | }; 42 | 43 | Waiter(void* addr) 44 | : m_address(addr) 45 | { 46 | } 47 | 48 | void* m_address; 49 | std::mutex m_mutex; 50 | std::condition_variable m_condition; 51 | std::vector m_waiterItemList; 52 | }; 53 | 54 | class Store { 55 | public: 56 | Store(Engine* engine) 57 | : m_engine(engine) 58 | { 59 | } 60 | 61 | ~Store(); 62 | 63 | static void finalize(); 64 | static FunctionType* getDefaultFunctionType(Value::Type type); 65 | 66 | void appendModule(Module* module) 67 | { 68 | m_modules.push_back(module); 69 | } 70 | 71 | void appendInstance(Instance* instance) 72 | { 73 | m_instances.push_back(instance); 74 | } 75 | 76 | void appendExtern(Extern* ext) 77 | { 78 | m_externs.push_back(ext); 79 | } 80 | 81 | Instance* getLastInstance() 82 | { 83 | ASSERT(m_instances.size()); 84 | return m_instances.back(); 85 | } 86 | 87 | Waiter* getWaiter(void* address); 88 | 89 | private: 90 | Engine* m_engine; 91 | 92 | Vector m_modules; 93 | Vector m_instances; 94 | Vector m_externs; 95 | 96 | // default FunctionTypes used for initialization of Data, Element and Global 97 | static FunctionType* g_defaultFunctionTypes[Value::Type::NUM]; 98 | std::mutex m_waiterListLock; 99 | std::vector m_waiterList; 100 | }; 101 | 102 | } // namespace Walrus 103 | 104 | #endif // __WalrusStore__ 105 | -------------------------------------------------------------------------------- /src/runtime/Tag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusTag__ 18 | #define __WalrusTag__ 19 | 20 | #include "runtime/Store.h" 21 | #include "runtime/Object.h" 22 | 23 | namespace Walrus { 24 | 25 | class FunctionType; 26 | 27 | class Tag : public Extern { 28 | public: 29 | static Tag* createTag(Store* store, FunctionType* functionType) 30 | { 31 | Tag* tag = new Tag(functionType); 32 | store->appendExtern(tag); 33 | return tag; 34 | } 35 | 36 | virtual Object::Kind kind() const override 37 | { 38 | return Object::TagKind; 39 | } 40 | 41 | virtual bool isTag() const override 42 | { 43 | return true; 44 | } 45 | 46 | const FunctionType* functionType() const 47 | { 48 | return m_functionType; 49 | } 50 | 51 | private: 52 | Tag(FunctionType* functionType) 53 | : m_functionType(functionType) 54 | { 55 | } 56 | 57 | const FunctionType* m_functionType; 58 | }; 59 | 60 | } // namespace Walrus 61 | 62 | #endif // __WalrusTag__ 63 | -------------------------------------------------------------------------------- /src/runtime/Trap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Walrus.h" 17 | 18 | #include "Trap.h" 19 | 20 | namespace Walrus { 21 | 22 | Trap::TrapResult Trap::run(void (*runner)(ExecutionState&, void*), void* data) 23 | { 24 | Trap::TrapResult r; 25 | try { 26 | ExecutionState state; 27 | runner(state, data); 28 | } catch (std::unique_ptr& e) { 29 | r.exception = std::move(e); 30 | } 31 | 32 | return r; 33 | } 34 | 35 | void Trap::throwException(const std::string& message) 36 | { 37 | throw Exception::create(message); 38 | } 39 | 40 | void Trap::throwException(ExecutionState& state, const std::string& message) 41 | { 42 | throw Exception::create(state, message); 43 | } 44 | 45 | void Trap::throwException(ExecutionState& state, Tag* tag, Vector&& userExceptionData) 46 | { 47 | throw Exception::create(state, tag, std::move(userExceptionData)); 48 | } 49 | 50 | void Trap::throwException(ExecutionState& state, std::unique_ptr&& e) 51 | { 52 | throw std::move(e); 53 | } 54 | 55 | } // namespace Walrus 56 | -------------------------------------------------------------------------------- /src/runtime/Trap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusTrap__ 18 | #define __WalrusTrap__ 19 | 20 | #include "runtime/Value.h" 21 | #include "runtime/Object.h" 22 | #include "runtime/Exception.h" 23 | #include "runtime/ExecutionState.h" 24 | 25 | namespace Walrus { 26 | 27 | class Exception; 28 | class Module; 29 | class Tag; 30 | 31 | class Trap : public Object { 32 | public: 33 | struct TrapResult { 34 | std::unique_ptr exception; 35 | 36 | TrapResult() 37 | { 38 | } 39 | }; 40 | 41 | virtual Object::Kind kind() const override 42 | { 43 | return Object::TrapKind; 44 | } 45 | 46 | virtual bool isTrap() const override 47 | { 48 | return true; 49 | } 50 | 51 | TrapResult run(void (*runner)(ExecutionState&, void*), void* data); 52 | static void throwException(const std::string& message); 53 | static void throwException(ExecutionState& state, const std::string& message); 54 | static void throwException(ExecutionState& state, Tag* tag, Vector&& userExceptionData); 55 | static void throwException(ExecutionState& state, std::unique_ptr&& e); 56 | }; 57 | 58 | } // namespace Walrus 59 | 60 | #endif // __WalrusTrap__ 61 | -------------------------------------------------------------------------------- /src/util/Util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __WalrusUtil__ 18 | #define __WalrusUtil__ 19 | 20 | #if defined(COMPILER_MSVC) 21 | #include 22 | #endif 23 | 24 | namespace Walrus { 25 | 26 | #if defined(COMPILER_GCC) || defined(COMPILER_CLANG) 27 | inline void* currentStackPointer() 28 | { 29 | return __builtin_frame_address(0); 30 | } 31 | #elif defined(COMPILER_MSVC) 32 | inline void* currentStackPointer() 33 | { 34 | return _AddressOfReturnAddress(); 35 | } 36 | #else 37 | #error 38 | #endif 39 | 40 | } // namespace Walrus 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/util/Vector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "Walrus.h" 18 | 19 | #include "Vector.h" 20 | 21 | namespace Walrus { 22 | const size_t VectorUtil::invalidIndex = SIZE_MAX; 23 | } // namespace Walrus 24 | -------------------------------------------------------------------------------- /test/basic/block.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "block1")(param $num i32)(result i32) 3 | (block 4 | local.get 0 5 | i32.eqz 6 | br_if 0 7 | i32.const 42 8 | local.set 0) 9 | local.get 0 10 | ) 11 | (func (export "block2")(param i32)(result i32)(local i32) 12 | (block 13 | (block 14 | (block 15 | local.get 0 16 | i32.eqz 17 | br_if 0 18 | 19 | local.get 0 20 | i32.const 1 21 | i32.eq 22 | br_if 1 23 | 24 | i32.const 7 25 | local.set 1 26 | br 2) 27 | i32.const 42 28 | local.set 1 29 | br 1) 30 | i32.const 99 31 | local.set 1) 32 | local.get 1) 33 | ) 34 | 35 | (assert_return (invoke "block1" (i32.const 0)) (i32.const 0)) 36 | (assert_return (invoke "block1" (i32.const 1)) (i32.const 42)) 37 | 38 | (assert_return (invoke "block2" (i32.const 0)) (i32.const 42)) 39 | (assert_return (invoke "block2" (i32.const 1)) (i32.const 99)) 40 | (assert_return (invoke "block2" (i32.const 2)) (i32.const 7)) 41 | -------------------------------------------------------------------------------- /test/basic/br.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 7) 3 | (func (export "br0")(result i32 i32 i32) 4 | i32.const 1 5 | i32.const 2 6 | i32.const 3 7 | br 0 8 | i32.const 100 ;; the bytecode is not generated from here to function end 9 | drop 10 | drop 11 | drop 12 | memory.grow 13 | ) 14 | (func (export "br_if0")(param i32)(result i32 i32 i32) 15 | i32.const 1 16 | i32.const 2 17 | i32.const 3 18 | local.get 0 19 | br_if 0 20 | drop 21 | i32.const 100 22 | memory.grow 23 | ) 24 | (func (export "check")(result i32) 25 | memory.size 26 | ) 27 | (func (export "br0_1")(param i32)(result i32) 28 | local.get 0 29 | (if (then 30 | (i32.const 100) 31 | (br 1) 32 | )) 33 | i32.const 200 34 | ) 35 | (func (export "br_if_cmp")(param i32 i32 i64 f32 f64)(result i32 i32 i32 i32) 36 | block (result i32) 37 | i32.const -1 38 | local.get 0 39 | br_if 0 40 | drop 41 | local.get 1 42 | i32.const 100 43 | i32.eq 44 | end 45 | block (result i32) 46 | i32.const -1 47 | local.get 0 48 | br_if 0 49 | drop 50 | local.get 2 51 | i64.const 100 52 | i64.eq 53 | end 54 | block (result i32) 55 | i32.const -1 56 | local.get 0 57 | br_if 0 58 | drop 59 | local.get 3 60 | f32.const 100.0 61 | f32.eq 62 | end 63 | block (result i32) 64 | i32.const -1 65 | local.get 0 66 | br_if 0 67 | drop 68 | local.get 4 69 | f64.const 100.0 70 | f64.eq 71 | end 72 | ) 73 | (func (export "br_block_return") (result i32) 74 | (local i32) 75 | block (result i32) 76 | i32.const 20 77 | br 1 78 | local.set 0 ;; dead code 79 | end 80 | ) 81 | ) 82 | 83 | (assert_return (invoke "br0") (i32.const 1)(i32.const 2)(i32.const 3)) 84 | (assert_return (invoke "br_if0"(i32.const 1)) (i32.const 1)(i32.const 2)(i32.const 3)) 85 | (assert_return (invoke "check") (i32.const 7)) 86 | (assert_return (invoke "br_if0"(i32.const 0)) (i32.const 1)(i32.const 2)(i32.const 7)) 87 | (assert_return (invoke "check") (i32.const 107)) 88 | (assert_return (invoke "br0_1"(i32.const 1))(i32.const 100)) 89 | (assert_return (invoke "br0_1"(i32.const 0))(i32.const 200)) 90 | (assert_return (invoke "br_if_cmp"(i32.const 0)(i32.const 100)(i64.const 100)(f32.const 100.0)(f64.const 100.0)) 91 | (i32.const 1)(i32.const 1)(i32.const 1)(i32.const 1)) 92 | (assert_return (invoke "br_block_return") (i32.const 20)) 93 | -------------------------------------------------------------------------------- /test/basic/br_table.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 7) 3 | (func (export "check")(result i32) 4 | memory.size 5 | ) 6 | 7 | (func (export "nop") 8 | (i32.const 1) 9 | (br_table 0) 10 | (i32.const 3) 11 | (memory.grow) 12 | (drop) 13 | ) 14 | 15 | (func (export "early_exit") (result i32) 16 | (i32.const 21) 17 | (i32.const 0) 18 | (br_table 0) 19 | (drop) 20 | (drop) 21 | (drop) 22 | (i32.const 42) 23 | ) 24 | 25 | (func (export "switch_like") (param $p i32) (result i32) 26 | (block 27 | (block 28 | (block 29 | (block (local.get $p) 30 | (br_table 31 | 2 ;; p == 0 => (br 2) 32 | 1 ;; p == 1 => (br 1) 33 | 0 ;; p == 2 => (br 0) 34 | 3)) ;; else => (br 3) 35 | ;; Target for (br 0) 36 | (i32.const 100) 37 | (return)) 38 | ;; Target for (br 1) 39 | (i32.const 101) 40 | (return)) 41 | ;; Target for (br 2) 42 | (i32.const 102) 43 | (return)) 44 | ;; Target for (br 3) 45 | (i32.const 103) 46 | (return) 47 | ) 48 | ) 49 | 50 | (assert_return (invoke "nop")) 51 | (assert_return (invoke "check") (i32.const 7)) 52 | (assert_return (invoke "early_exit") (i32.const 21)) 53 | (assert_return (invoke "switch_like"(i32.const 0)) (i32.const 102)) 54 | (assert_return (invoke "switch_like"(i32.const 1)) (i32.const 101)) 55 | (assert_return (invoke "switch_like"(i32.const 2)) (i32.const 100)) 56 | (assert_return (invoke "switch_like"(i32.const 3)) (i32.const 103)) 57 | -------------------------------------------------------------------------------- /test/basic/ifelse.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "ifelse1")(param $num i32)(result i32) 3 | local.get $num 4 | i32.const 100 5 | i32.eq 6 | 7 | (if 8 | (then 9 | i32.const 123 10 | local.set $num 11 | ) 12 | (else 13 | i32.const 456 14 | local.set $num 15 | ) 16 | ) 17 | 18 | local.get $num 19 | ) 20 | 21 | (func (export "ifelse2")(param $num i32)(result i32) 22 | local.get $num 23 | i32.const 100 24 | i32.eq 25 | 26 | (if 27 | (then 28 | i32.const 123 29 | local.set $num 30 | ) 31 | (else 32 | i32.const 456 33 | local.set $num 34 | ) 35 | ) 36 | 37 | local.get $num 38 | ) 39 | 40 | 41 | (func (export "ifelse3")(param $num i32)(result i32) 42 | local.get $num 43 | i32.const 100 44 | i32.eq 45 | 46 | (if (result i32) 47 | (then 48 | i32.const 123 49 | ) 50 | (else 51 | i32.const 456 52 | ) 53 | ) 54 | ) 55 | ) 56 | 57 | (assert_return (invoke "ifelse1" (i32.const 100)) (i32.const 123)) 58 | (assert_return (invoke "ifelse1" (i32.const 200)) (i32.const 456)) 59 | 60 | (assert_return (invoke "ifelse2" (i32.const 100)) (i32.const 123)) 61 | (assert_return (invoke "ifelse2" (i32.const 200)) (i32.const 456)) 62 | 63 | (assert_return (invoke "ifelse3" (i32.const 100)) (i32.const 123)) 64 | (assert_return (invoke "ifelse3" (i32.const 200)) (i32.const 456)) 65 | 66 | 67 | -------------------------------------------------------------------------------- /test/basic/local.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $local_test (export "local_test")(param i32)(result i32) 3 | (local i32) 4 | (i32.const 444) 5 | (local.set 1) 6 | (local.get 0) 7 | (local.get 1) 8 | (i32.add) 9 | ) 10 | 11 | (func $local_test2 (export "local_test2")(param i32)(result i32) 12 | (local i32) 13 | (i32.const 444) 14 | (local.tee 1) 15 | (local.get 0) 16 | (i32.add) 17 | ) 18 | ) 19 | 20 | (assert_return (invoke "local_test" (i32.const 222)) (i32.const 666)) 21 | (assert_return (invoke "local_test2" (i32.const 222)) (i32.const 666)) 22 | -------------------------------------------------------------------------------- /test/basic/loop.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "spectest" "print_i32" (func $log_i32 (param i32))) 3 | (func (export "loop1")(param $num i32)(result i32)(local $sum i32) 4 | (loop $loop 5 | local.get $num 6 | local.get $sum 7 | i32.add 8 | local.set $sum 9 | 10 | local.get $num 11 | i32.const 1 12 | i32.sub 13 | local.set $num 14 | 15 | local.get $num 16 | i32.eqz 17 | (if 18 | (then 19 | ) 20 | (else 21 | br $loop 22 | ) 23 | ) 24 | ) 25 | 26 | local.get $sum 27 | ) 28 | 29 | (func (export "loop2")(param $num i32)(result i32)(local $sum i32) 30 | (loop $loop 31 | local.get $num 32 | local.get $sum 33 | i32.add 34 | local.set $sum 35 | 36 | local.get $num 37 | i32.const 1 38 | i32.sub 39 | local.set $num 40 | 41 | local.get $num 42 | br_if $loop 43 | ) 44 | 45 | local.get $sum 46 | ) 47 | 48 | (func (export "loop3")(param $num i32)(result i32)(local $sum i32) 49 | (loop $loop (result i32) 50 | local.get $num 51 | local.get $sum 52 | i32.add 53 | local.set $sum 54 | 55 | local.get $num 56 | i32.const 1 57 | i32.sub 58 | local.set $num 59 | 60 | local.get $num 61 | br_if $loop 62 | 63 | local.get $sum 64 | ) 65 | ) 66 | 67 | (func (export "loop4")(param $num i32)(result i32) 68 | (loop $outer_loop 69 | local.get $num 70 | i32.const 1 71 | i32.ge_s 72 | (if 73 | (then 74 | (loop $loop (result i32) 75 | local.get $num 76 | i32.const 1 77 | i32.sub 78 | local.set $num 79 | local.get $num 80 | local.get $num 81 | br_if $outer_loop 82 | ) 83 | drop 84 | ) 85 | ) 86 | ) 87 | local.get $num 88 | ) 89 | ) 90 | 91 | (assert_return (invoke "loop1" (i32.const 10)) (i32.const 55)) 92 | (assert_return (invoke "loop2" (i32.const 9)) (i32.const 45)) 93 | (assert_return (invoke "loop3" (i32.const 8)) (i32.const 36)) 94 | ;; br, br_if should shrink stack correctly 95 | (assert_return (invoke "loop4" (i32.const 100000)) (i32.const 0)) 96 | 97 | -------------------------------------------------------------------------------- /test/basic/memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 3) 3 | (func (export "func1")(result i32) 4 | memory.size 5 | ) 6 | 7 | (func (export "func2")(param i32)(result i32) 8 | local.get 0 9 | memory.grow 10 | ) 11 | ) 12 | (assert_return (invoke "func1") (i32.const 3)) 13 | (assert_return (invoke "func2" (i32.const 5)) (i32.const 3)) 14 | (assert_return (invoke "func1") (i32.const 8)) 15 | 16 | (module 17 | (memory 0) 18 | (func (export "grow") (param i32) (result i32) (memory.grow (local.get 0))) 19 | ) 20 | (assert_return (invoke "grow" (i32.const 0x1000)) (i32.const 0)) 21 | (assert_return (invoke "grow" (i32.const 0x10000)) (i32.const -1)) 22 | 23 | (module 24 | (memory 1) 25 | (func (export "loadInt64") (param $offset i32) (result i64) 26 | (i64.load (local.get $offset)) 27 | ) 28 | (func (export "storeInt64") (param $offset i32) (param $value i64) 29 | (i64.store (local.get $offset) (local.get $value)) 30 | ) 31 | (func (export "loadDouble") (param $offset i32) (result f64) 32 | (f64.load (local.get $offset)) 33 | ) 34 | (func (export "storeDouble") (param $offset i32) (param $value f64) 35 | (f64.store (local.get $offset) (local.get $value)) 36 | ) 37 | (func (export "loadUint8") (param $offset i32) (result i32) 38 | (i32.load8_u (local.get $offset)) 39 | ) 40 | ) 41 | ;; memory is 64 kilobyte aligned, therefore index 1 will not be four byte aligned. 42 | (assert_return (invoke "storeInt64" (i32.const 0x1) (i64.const 0x0123456789abcdef))) 43 | (assert_return (invoke "loadInt64" (i32.const 0x1)) (i64.const 0x0123456789abcdef)) 44 | (assert_return (invoke "loadUint8" (i32.const 0x1)) (i32.const 0xef)) 45 | (assert_return (invoke "storeDouble" (i32.const 0x1) (f64.const 0xfedcba9876543210))) 46 | (assert_return (invoke "loadDouble" (i32.const 0x1)) (f64.const 0xfedcba9876543210)) 47 | -------------------------------------------------------------------------------- /test/basic/missing_end.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module binary 3 | "\00asm" "\01\00\00\00" 4 | "\01\09" ;; import section 5 | "\02\60\00\00\60\01\7f\01\7f" ;; type section entry 6 | "\03\02" ;; function section 7 | "\01\00" ;; function section entry 8 | "\07\09" ;; export section 9 | "\01\05\6e\6f\65\6e\64\00\00" ;; export section entry (function 'noend') 10 | "\0a\18" ;; begin code section 11 | "\01\16\00" ;; begin function body 12 | "\02\40" ;; block 13 | "\03\40" ;; loop 14 | "\02\40" ;; block 15 | "\03\40" ;; loop 16 | "\0c\00" ;; br 0 17 | "\02\01" ;; block type[1] 18 | "\0b" ;; end 19 | "\0c\00" ;; br 0 20 | "\0b" ;; end 21 | "\00" ;; unreachable 22 | "\00" ;; unreachable 23 | "\00" ;; unreachable 24 | "\0b" ;; end 25 | "\0b" ;; end 26 | ) 27 | "function body must end with END opcode" 28 | ) 29 | -------------------------------------------------------------------------------- /test/basic/optimalisationCheck.wast: -------------------------------------------------------------------------------- 1 | ;; tests for Walrus where optimalisation shouldn't occure 2 | 3 | (module 4 | 5 | ;; in the following tests there will be an EqualZero, then 6 | ;; a JumpIfTrue/JumpIfFalse that should not be unified 7 | 8 | (func (export "test1") (param $input i32) (result i32) 9 | i32.const 1 10 | i32.eqz 11 | local.get $input 12 | br_if 0 13 | drop 14 | i32.const 1 15 | ) 16 | 17 | (func (export "test2") (param $input i32) (result i32) 18 | local.get $input 19 | i32.eqz 20 | i32.const 0 21 | if (result i32) 22 | i32.const 1 23 | else 24 | i32.const 0 25 | end 26 | i32.add 27 | ) 28 | 29 | (func (export "test3") (param $input i32) (result i32) 30 | i32.const 1 31 | block (result i32) 32 | i32.const 0 33 | local.get $input 34 | br_if 0 35 | drop 36 | i32.const 0 37 | i32.eqz 38 | end 39 | br_if 0 40 | drop 41 | i32.const 0 42 | ) 43 | ) 44 | 45 | (assert_return (invoke "test1" (i32.const 0)) (i32.const 1)) 46 | (assert_return (invoke "test1" (i32.const 1)) (i32.const 0)) 47 | (assert_return (invoke "test2" (i32.const 0)) (i32.const 1)) 48 | (assert_return (invoke "test2" (i32.const 1)) (i32.const 0)) 49 | (assert_return (invoke "test3" (i32.const 0)) (i32.const 1)) 50 | (assert_return (invoke "test3" (i32.const 1)) (i32.const 0)) 51 | -------------------------------------------------------------------------------- /test/basic/read_ahead_fix.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $some_func) 3 | (table 514 514 funcref) 4 | (elem (i32.const 1) func 5 | $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20 $21 $22 $23 $24 $25 $26 $27 $28 $29 $30 $31 $32 $33 6 | ) 7 | 8 | (func $0) 9 | (func $1) 10 | (func $2) 11 | (func $3) 12 | (func $4) 13 | (func $5) 14 | (func $6) 15 | (func $7) 16 | (func $8) 17 | (func $9) 18 | (func $10) 19 | (func $11) 20 | (func $12) 21 | (func $13) 22 | (func $14) 23 | (func $15) 24 | (func $16) 25 | (func $17) 26 | (func $18) 27 | (func $19) 28 | (func $20) 29 | (func $21) 30 | (func $22) 31 | (func $23) 32 | (func $24) 33 | (func $25) 34 | (func $26) 35 | (func $27) 36 | (func $28) 37 | (func $29) 38 | (func $30) 39 | (func $31) 40 | (func $32) 41 | (func $33) 42 | ) 43 | 44 | -------------------------------------------------------------------------------- /test/basic/select.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "func1") (param i32) (result i32) 3 | (i32.eqz (select (i32.const 0) (i32.const 1) (local.get 0))) 4 | ) 5 | 6 | (func (export "func2") (param i32) (result i32) 7 | (i32.mul 8 | (select (i32.const 1) (i32.const 2) (local.get 0)) 9 | (select (i32.const 1) (i32.const 2) (local.get 0)) 10 | ) 11 | ) 12 | ) 13 | 14 | (assert_return (invoke "func1" (i32.const 0)) (i32.const 0)) 15 | (assert_return (invoke "func1" (i32.const 1)) (i32.const 1)) 16 | (assert_return (invoke "func2" (i32.const 0)) (i32.const 4)) 17 | (assert_return (invoke "func2" (i32.const 1)) (i32.const 1)) 18 | -------------------------------------------------------------------------------- /test/basic/trycatch.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (tag $e0) 3 | (tag $e1) 4 | (func (export "sss") (param i32)(result i32) 5 | (try 6 | (do 7 | (local.get 0) 8 | (i32.const 1) 9 | (if (i32.eq) 10 | (then (throw $e0) ) 11 | ) 12 | ) 13 | (catch $e0 14 | (i32.const 100) 15 | return 16 | ) 17 | ) 18 | (try 19 | (do 20 | (local.get 0) 21 | (i32.const 2) 22 | (if (i32.eq) 23 | (then (throw $e1) ) 24 | ) 25 | ) 26 | (catch $e1 27 | (i32.const 200) 28 | return 29 | ) 30 | ) 31 | (i32.const 300) 32 | ) 33 | 34 | (func (export "dead-code")(result i32) 35 | (block (result i32) 36 | i32.const 5 37 | 38 | (try (param i32) (result i32) 39 | (do 40 | br 1 41 | ) 42 | (catch $e0 43 | i32.const 1 44 | br 1 45 | ) 46 | (catch_all 47 | i32.const 2 48 | br 1 49 | ) 50 | ) 51 | 52 | i32.const 6 53 | i32.add 54 | ) 55 | ) 56 | ) 57 | 58 | (assert_return (invoke "sss" (i32.const 1))(i32.const 100)) 59 | (assert_return (invoke "sss" (i32.const 2))(i32.const 200)) 60 | (assert_return (invoke "sss" (i32.const 3))(i32.const 300)) 61 | (assert_return (invoke "dead-code")(i32.const 5)) 62 | -------------------------------------------------------------------------------- /test/basic/v128_select.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "select128") (param i32) (result v128) 3 | v128.const i64x2 0xaaaaaaaaaaaaaaaa 0xaaaaaaaaaaaaaaaa 4 | v128.const i64x2 0xbbbbbbbbbbbbbbbb 0xbbbbbbbbbbbbbbbb 5 | local.get 0 6 | select 7 | ) 8 | 9 | (func (export "cmp_select128") (param i32) (result v128) 10 | v128.const i64x2 0xaaaaaaaaaaaaaaaa 0xaaaaaaaaaaaaaaaa 11 | v128.const i64x2 0xbbbbbbbbbbbbbbbb 0xbbbbbbbbbbbbbbbb 12 | local.get 0 13 | i32.const 1234 14 | i32.eq 15 | select 16 | ) 17 | ) 18 | 19 | (assert_return (invoke "select128" (i32.const -1)) (v128.const i64x2 0xaaaaaaaaaaaaaaaa 0xaaaaaaaaaaaaaaaa)) 20 | (assert_return (invoke "select128" (i32.const 0)) (v128.const i64x2 0xbbbbbbbbbbbbbbbb 0xbbbbbbbbbbbbbbbb)) 21 | (assert_return (invoke "cmp_select128" (i32.const 1234)) (v128.const i64x2 0xaaaaaaaaaaaaaaaa 0xaaaaaaaaaaaaaaaa)) 22 | (assert_return (invoke "cmp_select128" (i32.const 0)) (v128.const i64x2 0xbbbbbbbbbbbbbbbb 0xbbbbbbbbbbbbbbbb)) 23 | -------------------------------------------------------------------------------- /test/extended/relaxed-simd/i16x8_relaxed_q15mulr_s.wast: -------------------------------------------------------------------------------- 1 | ;; Tests for i16x8.relaxed_q15mulr_s. 2 | ;; `either` comes from https://github.com/WebAssembly/threads. 3 | 4 | (module 5 | (func (export "i16x8.relaxed_q15mulr_s") (param v128 v128) (result v128) (i16x8.relaxed_q15mulr_s (local.get 0) (local.get 1))) 6 | 7 | (func (export "i16x8.relaxed_q15mulr_s_cmp") (param v128 v128) (result v128) 8 | (i16x8.eq 9 | (i16x8.relaxed_q15mulr_s (local.get 0) (local.get 1)) 10 | (i16x8.relaxed_q15mulr_s (local.get 0) (local.get 1)))) 11 | ) 12 | 13 | ;; INT16_MIN = -32768 14 | (assert_return (invoke "i16x8.relaxed_q15mulr_s" 15 | (v128.const i16x8 -32768 -32767 32767 0 0 0 0 0) 16 | (v128.const i16x8 -32768 -32768 32767 0 0 0 0 0)) 17 | ;; overflows, return either INT16_MIN or INT16_MAX 18 | (either (v128.const i16x8 -32768 32767 32766 0 0 0 0 0) 19 | (v128.const i16x8 32767 32767 32766 0 0 0 0 0))) 20 | 21 | ;; Check that multiple calls to the relaxed instruction with same inputs returns same results. 22 | 23 | (assert_return (invoke "i16x8.relaxed_q15mulr_s_cmp" 24 | (v128.const i16x8 -32768 -32767 32767 0 0 0 0 0) 25 | (v128.const i16x8 -32768 -32768 32767 0 0 0 0 0)) 26 | ;; overflows, return either INT16_MIN or INT16_MAX 27 | (v128.const i16x8 -1 -1 -1 -1 -1 -1 -1 -1)) 28 | 29 | -------------------------------------------------------------------------------- /test/extended/relaxed-simd/i8x16_relaxed_swizzle.wast: -------------------------------------------------------------------------------- 1 | ;; Tests for relaxed i8x16 swizzle. 2 | ;; `either` comes from https://github.com/WebAssembly/threads. 3 | 4 | (module 5 | (func (export "i8x16.relaxed_swizzle") (param v128 v128) (result v128) (i8x16.relaxed_swizzle (local.get 0) (local.get 1))) 6 | 7 | (func (export "i8x16.relaxed_swizzle_cmp") (param v128 v128) (result v128) 8 | (i8x16.eq 9 | (i8x16.relaxed_swizzle (local.get 0) (local.get 1)) 10 | (i8x16.relaxed_swizzle (local.get 0) (local.get 1)))) 11 | ) 12 | 13 | (assert_return (invoke "i8x16.relaxed_swizzle" 14 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 15 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) 16 | (either (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 17 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))) 18 | 19 | ;; out of range, returns 0 or modulo 15 if < 128 20 | (assert_return (invoke "i8x16.relaxed_swizzle" 21 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 22 | (v128.const i8x16 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31)) 23 | (either (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 24 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))) 25 | 26 | ;; out of range, returns 0 if >= 128 27 | (assert_return (invoke "i8x16.relaxed_swizzle" 28 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 29 | (v128.const i8x16 128 129 130 131 132 133 134 135 248 249 250 251 252 253 254 255)) 30 | (either (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) 31 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))) 32 | 33 | ;; Check that multiple calls to the relaxed instruction with same inputs returns same results. 34 | 35 | ;; out of range, returns 0 or modulo 15 if < 128 36 | (assert_return (invoke "i8x16.relaxed_swizzle_cmp" 37 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 38 | (v128.const i8x16 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31)) 39 | (v128.const i8x16 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1)) 40 | 41 | ;; out of range, returns 0 if >= 128 42 | (assert_return (invoke "i8x16.relaxed_swizzle_cmp" 43 | (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) 44 | (v128.const i8x16 128 129 130 131 132 133 134 135 248 249 250 251 252 253 254 255)) 45 | (v128.const i8x16 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1)) 46 | -------------------------------------------------------------------------------- /test/extended/threads/atomic_wait_notify_with_offsets.wast: -------------------------------------------------------------------------------- 1 | ;; wait/notify with non-zero offsets 2 | (module 3 | (memory 1 1 shared) 4 | 5 | (func (export "initOffset") (param $value i64) (param $offset i32) (i64.store offset=0 (local.get $offset) (local.get $value))) 6 | 7 | (func (export "memory.atomic.notify") (param $addr i32) (param $count i32) (result i32) 8 | (memory.atomic.notify offset=245 (local.get 0) (local.get 1))) 9 | (func (export "memory.atomic.wait32") (param $addr i32) (param $expected i32) (param $timeout i64) (result i32) 10 | (memory.atomic.wait32 offset=57822 (local.get 0) (local.get 1) (local.get 2))) 11 | (func (export "memory.atomic.wait64") (param $addr i32) (param $expected i64) (param $timeout i64) (result i32) 12 | (memory.atomic.wait64 offset=32456 (local.get 0) (local.get 1) (local.get 2))) 13 | ) 14 | 15 | ;; non-zero offsets 16 | 17 | (invoke "initOffset" (i64.const 0xffffffffffff) (i32.const 368)) 18 | (assert_return (invoke "memory.atomic.notify" (i32.const 123) (i32.const 10)) (i32.const 0)) 19 | 20 | (invoke "initOffset" (i64.const 0xffffffffffff) (i32.const 57944)) 21 | (assert_return (invoke "memory.atomic.wait32" (i32.const 122) (i32.const 0) (i64.const 0)) (i32.const 1)) 22 | 23 | (invoke "initOffset" (i64.const 0xffffffffffff) (i32.const 32584)) 24 | (assert_return (invoke "memory.atomic.wait64" (i32.const 128) (i64.const 0xffffffffffff) (i64.const 10)) (i32.const 2)) 25 | -------------------------------------------------------------------------------- /test/jit/binary-base.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (result i64 i64) (local i64) 3 | i64.const 020030040050060070 4 | local.set 0 5 | i64.const 100200300400500600 6 | local.get 0 7 | i64.add 8 | local.tee 0 9 | i64.const 220330440550660770 10 | local.get 0 11 | i64.sub 12 | 13 | (; 120230340450560670, 100100100100100100 ;) 14 | ) 15 | ) 16 | 17 | (assert_return (invoke "test1") (i64.const 120230340450560670) (i64.const 100100100100100100)) 18 | -------------------------------------------------------------------------------- /test/jit/binary-logical.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (result i64 i64 i64) (local i64 i64) 3 | i64.const 0xff00ff00ff00ff00 4 | local.set 0 5 | i64.const 0x0ff00ff00ff00ff0 6 | local.set 1 7 | 8 | local.get 0 9 | i64.const 0x0ff00ff00ff00ff0 10 | i64.and 11 | 12 | i64.const 0xff00ff00ff00ff00 13 | local.get 1 14 | i64.or 15 | 16 | local.get 0 17 | local.get 1 18 | i64.xor 19 | 20 | (; 1080880403494997760, 18442521884633399280, 17361641481138401520 ;) 21 | ) 22 | 23 | (func (export "test2") (param i32 i32) (result i32) 24 | block 25 | local.get 0 26 | local.get 1 27 | i32.and 28 | br_if 0 29 | i32.const 5 30 | return 31 | end 32 | 33 | i32.const 6 34 | ) 35 | 36 | (func (export "test3") (param i32 i32) (result i32) 37 | i32.const 10 38 | i32.const 11 39 | 40 | local.get 0 41 | local.get 1 42 | i32.and 43 | select 44 | ) 45 | ) 46 | 47 | (assert_return (invoke "test1") (i64.const 1080880403494997760) (i64.const 18442521884633399280) (i64.const 17361641481138401520)) 48 | (assert_return (invoke "test2" (i32.const 0x100) (i32.const 0x200)) (i32.const 5)) 49 | (assert_return (invoke "test2" (i32.const 0x0ff0) (i32.const 0x1f)) (i32.const 6)) 50 | (assert_return (invoke "test3" (i32.const 0xff) (i32.const 0xff00)) (i32.const 11)) 51 | (assert_return (invoke "test3" (i32.const 0x1ff) (i32.const 0xff00)) (i32.const 10)) 52 | -------------------------------------------------------------------------------- /test/jit/binary-multiply.wast: -------------------------------------------------------------------------------- 1 | (module 2 | 3 | (func (export "test1") (param i64) (result i64 i64 i64) 4 | i64.const 10000000 5 | local.get 0 6 | i64.mul 7 | 8 | i64.const -10000000 9 | local.get 0 10 | i64.mul 11 | 12 | i64.const -10000000 13 | local.set 0 14 | 15 | local.get 0 16 | local.get 0 17 | i64.mul 18 | 19 | (; 100000000000000, 18446644073709551616, 100000000000000 ;) 20 | ) 21 | 22 | (func (export "test2") (param i32) (result i32 i32 i32) 23 | i32.const 10000 24 | local.get 0 25 | i32.mul 26 | 27 | i32.const -10000 28 | local.get 0 29 | i32.mul 30 | 31 | i32.const -10000 32 | local.set 0 33 | 34 | local.get 0 35 | local.get 0 36 | i32.mul 37 | 38 | (; 100000000, 4194967296, 100000000 ;) 39 | ) 40 | 41 | (func (export "test3") (param i64) (result i64 i64) 42 | i64.const 0x3bc5600000000 43 | local.get 0 44 | i64.mul 45 | 46 | i64.const 0x2d961e00000001 47 | local.get 0 48 | i64.mul 49 | ) 50 | 51 | (func (export "test4") (param i64) (result i64 i64) 52 | i64.const 0x572c3 53 | local.get 0 54 | i64.mul 55 | 56 | i64.const 0x160452d48 57 | local.get 0 58 | i64.mul 59 | ) 60 | 61 | (func (export "test5") (param i32 i64) (result i64) 62 | local.get 0 63 | i32.const 4 64 | i32.add 65 | 66 | local.get 1 67 | i64.const 0x1234 68 | i64.add 69 | local.set 1 70 | 71 | local.set 0 72 | 73 | local.get 1 74 | local.get 1 75 | i64.mul 76 | ) 77 | 78 | (func (export "test6") (param i32 i64) (result i64) 79 | local.get 0 80 | i32.const 4 81 | i32.add 82 | 83 | local.get 1 84 | i64.const 0x4321 85 | i64.add 86 | local.set 1 87 | 88 | local.set 0 89 | 90 | local.get 1 91 | i64.const 0x48b71cd0253 92 | i64.mul 93 | ) 94 | ) 95 | 96 | (assert_return (invoke "test1" (i64.const 10000000)) (i64.const 100000000000000) (i64.const 18446644073709551616) (i64.const 100000000000000)) 97 | (assert_return (invoke "test2" (i32.const 10000)) (i32.const 100000000) (i32.const 4194967296) (i32.const 100000000)) 98 | (assert_return (invoke "test3" (i64.const 0x34b74b74b74b74b7)) (i64.const 0x5b34997a00000000) (i64.const 0x6a1d32e6b74b74b7)) 99 | (assert_return (invoke "test4" (i64.const 0x580f80f80f80f80f)) (i64.const 0x8016016015fea16d) (i64.const 0x5635635583eb6738)) 100 | (assert_return (invoke "test5" (i32.const 0) (i64.const 0xc48a2406a2e5)) (i64.const 0x219b6a1005485c71)) 101 | (assert_return (invoke "test6" (i32.const 0) (i64.const 0xd4b913dfe24a)) (i64.const 0x5733424463a5f7b1)) 102 | -------------------------------------------------------------------------------- /test/jit/block1.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $test1 3 | block 4 | i32.const 1 5 | i32.const 2 6 | i32.const 3 7 | br 0 8 | 9 | drop 10 | i32.add 11 | drop 12 | 13 | i32.const 1 14 | if 15 | loop 16 | i32.const 2 17 | if (result i32) 18 | i32.const 3 19 | else 20 | i32.const 4 21 | end 22 | br 1 23 | end 24 | else 25 | i32.const 5 26 | i32.const 6 27 | if (param i32) (result i32) 28 | drop 29 | i32.const 7 30 | end 31 | drop 32 | end 33 | end 34 | ) 35 | 36 | (func $test2 37 | i32.const 5 38 | loop (param i32) 39 | br 0 40 | end 41 | ) 42 | ) 43 | -------------------------------------------------------------------------------- /test/jit/block2.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $test1 (local i32) 3 | block 4 | i32.const 1 5 | if (result i32) 6 | i32.const 2 7 | else 8 | i32.const 3 9 | if (result i32) 10 | i32.const 2 11 | else 12 | i32.const 2 13 | i32.const 5 14 | br_if 1 15 | end 16 | 17 | local.set 0 18 | br 1 19 | end 20 | 21 | local.set 0 22 | end 23 | ) 24 | 25 | (func $test2 (local i32) 26 | block 27 | i32.const 1 28 | if (result i32) 29 | local.get 0 30 | else 31 | i32.const 3 32 | if (result i32) 33 | local.get 0 34 | else 35 | local.get 0 36 | i32.const 5 37 | br_if 1 38 | end 39 | 40 | local.set 0 41 | br 1 42 | end 43 | 44 | local.set 0 45 | end 46 | ) 47 | 48 | (func $test3 (local i32) 49 | block 50 | i32.const 1 51 | if (result i32) 52 | i32.const 2 53 | else 54 | i32.const 3 55 | if (result i32) 56 | local.get 0 57 | else 58 | local.get 0 59 | i32.const 5 60 | br_if 1 61 | end 62 | 63 | local.set 0 64 | br 1 65 | end 66 | 67 | local.set 0 68 | end 69 | ) 70 | 71 | (func $test4 (local i32 i32) 72 | block 73 | i32.const 1 74 | if (result i32) 75 | i32.const 2 76 | else 77 | i32.const 3 78 | if (result i32) 79 | local.get 0 80 | else 81 | local.get 0 82 | i32.const 5 83 | br_if 1 84 | end 85 | 86 | local.set 0 87 | br 1 88 | end 89 | 90 | local.set 1 91 | end 92 | ) 93 | ) 94 | -------------------------------------------------------------------------------- /test/jit/compare-simd.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (param v128) (result i32 i32 i32 i32 i32) 3 | block (result i32) 4 | i32.const 1 5 | local.get 0 6 | v128.any_true 7 | br_if 0 8 | drop 9 | i32.const 0 10 | end 11 | 12 | block (result i32) 13 | i32.const 1 14 | local.get 0 15 | i8x16.all_true 16 | br_if 0 17 | drop 18 | i32.const 0 19 | end 20 | 21 | block (result i32) 22 | i32.const 1 23 | local.get 0 24 | i16x8.all_true 25 | br_if 0 26 | drop 27 | i32.const 0 28 | end 29 | 30 | block (result i32) 31 | i32.const 1 32 | local.get 0 33 | i32x4.all_true 34 | br_if 0 35 | drop 36 | i32.const 0 37 | end 38 | 39 | block (result i32) 40 | i32.const 1 41 | local.get 0 42 | i64x2.all_true 43 | br_if 0 44 | drop 45 | i32.const 0 46 | end 47 | ) 48 | 49 | (func (export "test2") (param v128) (result i32 i32 i32 i32 i32) 50 | block (result i32) 51 | i32.const 1 52 | i32.const 0 53 | local.get 0 54 | v128.any_true 55 | select 56 | end 57 | 58 | block (result i32) 59 | i32.const 1 60 | i32.const 0 61 | local.get 0 62 | i8x16.all_true 63 | select 64 | end 65 | 66 | block (result i32) 67 | i32.const 1 68 | i32.const 0 69 | local.get 0 70 | i16x8.all_true 71 | select 72 | end 73 | 74 | block (result i32) 75 | i32.const 1 76 | i32.const 0 77 | local.get 0 78 | i32x4.all_true 79 | select 80 | end 81 | 82 | block (result i32) 83 | i32.const 1 84 | i32.const 0 85 | local.get 0 86 | i64x2.all_true 87 | select 88 | end 89 | ) 90 | ) 91 | 92 | (assert_return (invoke "test1" (v128.const i64x2 -1 -1)) 93 | (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1)) 94 | (assert_return (invoke "test1" (v128.const i64x2 0 0)) 95 | (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)) 96 | 97 | (assert_return (invoke "test2" (v128.const i64x2 -1 -1)) 98 | (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1)) 99 | (assert_return (invoke "test2" (v128.const i64x2 0 0)) 100 | (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)) 101 | -------------------------------------------------------------------------------- /test/jit/compare.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (result i32 i32 i32 i32) (local i64) 3 | i64.const 0x0 4 | local.set 0 5 | 6 | i64.const 0xff00000000 7 | i64.eqz 8 | 9 | i64.const 0x1 10 | i64.eqz 11 | 12 | local.get 0 13 | i64.eqz 14 | 15 | local.get 0 16 | i64.eqz 17 | if (result i32) 18 | block (result i32) 19 | i32.const 3 20 | 21 | local.get 0 22 | i64.eqz 23 | br_if 0 24 | 25 | drop 26 | i32.const 4 27 | end 28 | else 29 | i32.const 6 30 | end 31 | 32 | (; 0, 0, 1, 3 ;) 33 | ) 34 | ) 35 | 36 | (assert_return (invoke "test1") (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 3)) 37 | -------------------------------------------------------------------------------- /test/jit/convert.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (result i32 i64 i64) (local i64 i32) 3 | i64.const 0x7fffffff80000001 4 | local.set 0 5 | 6 | i32.const 0x80000001 7 | local.set 1 8 | 9 | local.get 0 10 | i32.wrap_i64 11 | 12 | local.get 1 13 | i64.extend_i32_s 14 | 15 | local.get 1 16 | i64.extend_i32_u 17 | 18 | (; 2147483649, 18446744071562067969, 2147483649 ;) 19 | ) 20 | 21 | (func (export "test2") (result i32) 22 | f32.const 1234 23 | i32.trunc_f32_u 24 | ) 25 | 26 | (func (export "test3") (result i32) 27 | f32.const 4567 28 | i32.trunc_sat_f32_u 29 | ) 30 | 31 | (func (export "test4") (param i32) (result f32 i32) 32 | local.get 0 33 | f32.reinterpret_i32 34 | i32.const 0xaaaa 35 | i32.popcnt 36 | ) 37 | ) 38 | 39 | (assert_return (invoke "test1") (i32.const 2147483649) (i64.const 18446744071562067969) (i64.const 2147483649)) 40 | (assert_return (invoke "test2") (i32.const 1234)) 41 | (assert_return (invoke "test3") (i32.const 4567)) 42 | (assert_return (invoke "test4" (i32.const 0x45580000)) (f32.const 3456.0) (i32.const 8)) 43 | -------------------------------------------------------------------------------- /test/jit/extend.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (result i32 i32 i32 i32) (local i32 i32 i32 i32) 3 | i32.const 0x8880 4 | local.set 0 5 | 6 | i32.const 0xae7f 7 | local.set 1 8 | 9 | i32.const 0x228000 10 | local.set 2 11 | 12 | i32.const 0xae7fff 13 | local.set 3 14 | 15 | local.get 0 16 | i32.extend8_s 17 | 18 | local.get 1 19 | i32.extend8_s 20 | 21 | local.get 2 22 | i32.extend16_s 23 | 24 | local.get 3 25 | i32.extend16_s 26 | 27 | (; 4294967168, 127, 4294934528, 32767 ;) 28 | ) 29 | 30 | (func (export "test2") (result i64 i64 i64 i64) (local i64 i64 i64 i64) 31 | i64.const 0x8880 32 | local.set 0 33 | 34 | i64.const 0xae7f 35 | local.set 1 36 | 37 | i64.const 0x228000 38 | local.set 2 39 | 40 | i64.const 0xae7fff 41 | local.set 3 42 | 43 | local.get 0 44 | i64.extend8_s 45 | 46 | local.get 1 47 | i64.extend8_s 48 | 49 | local.get 2 50 | i64.extend16_s 51 | 52 | local.get 3 53 | i64.extend16_s 54 | 55 | (; 18446744073709551488, 127, 18446744073709518848, 32767 ;) 56 | ) 57 | 58 | (func (export "test3") (result i64 i64) (local i64 i64) 59 | i64.const 0x8880000000 60 | local.set 0 61 | 62 | i64.const 0xae7fffffff 63 | local.set 1 64 | 65 | local.get 0 66 | i64.extend32_s 67 | 68 | local.get 1 69 | i64.extend32_s 70 | 71 | (; 18446744071562067968, 2147483647 ;) 72 | ) 73 | ) 74 | 75 | (assert_return (invoke "test1") (i32.const 4294967168) (i32.const 127) (i32.const 4294934528) (i32.const 32767)) 76 | (assert_return (invoke "test2") (i64.const 18446744073709551488) (i64.const 127) (i64.const 18446744073709518848) (i64.const 32767)) 77 | (assert_return (invoke "test3") (i64.const 18446744071562067968) (i64.const 2147483647)) 78 | -------------------------------------------------------------------------------- /test/jit/global.wast: -------------------------------------------------------------------------------- 1 | (module 2 | 3 | (global $a (mut i32) (i32.const 1)) 4 | (global $b (mut i64) (i64.const 2)) 5 | (global (;2;) i32 (i32.const 3)) 6 | (global (;3;) i64 (i64.const 4)) 7 | (global $c (mut f32) (f32.const 5.5)) 8 | (global $d (mut f64) (f64.const 6.6)) 9 | (global (;6;) f32 (f32.const 7.7)) 10 | (global (;7;) f64 (f64.const 8.8)) 11 | 12 | (func (export "global_a") (result i32) global.get $a ) 13 | (func (export "global_b") (result i64) global.get $b ) 14 | (func (export "global_c") (result f32) global.get $c ) 15 | (func (export "global_d") (result f64) global.get $d ) 16 | 17 | (func (export "global_2") (result i32) global.get 2 ) 18 | (func (export "global_3") (result i64) global.get 3 ) 19 | (func (export "global_6") (result f32) global.get 6 ) 20 | (func (export "global_7") (result f64) global.get 7 ) 21 | 22 | (func (export "global_set_a") (param i32) (global.set $a (local.get 0)) ) 23 | (func (export "global_set_b") (param i64) (global.set $b (local.get 0)) ) 24 | (func (export "global_set_c") (param f32) (global.set $c (local.get 0)) ) 25 | (func (export "global_set_d") (param f64) (global.set $d (local.get 0)) ) 26 | 27 | (global $r externref (ref.null extern)) 28 | (global $mr externref (ref.null extern)) 29 | (global $fr funcref (ref.null func)) 30 | 31 | (func (export "global_r") (result externref) global.get $r ) 32 | (func (export "global_mr") (result externref) global.get $mr ) 33 | (func (export "global_fr") (result funcref) global.get $fr ) 34 | 35 | ) 36 | 37 | (assert_return (invoke "global_a" ) (i32.const 1)) 38 | (assert_return (invoke "global_b" ) (i64.const 2)) 39 | (assert_return (invoke "global_c" ) (f32.const 5.5)) 40 | (assert_return (invoke "global_d" ) (f64.const 6.6)) 41 | (assert_return (invoke "global_2" ) (i32.const 3)) 42 | (assert_return (invoke "global_3" ) (i64.const 4)) 43 | (assert_return (invoke "global_6" ) (f32.const 7.7)) 44 | (assert_return (invoke "global_7" ) (f64.const 8.8)) 45 | (assert_return (invoke "global_set_a" (i32.const 11))) 46 | (assert_return (invoke "global_a" ) (i32.const 11)) 47 | (assert_return (invoke "global_set_b" (i64.const 22))) 48 | (assert_return (invoke "global_b" ) (i64.const 22)) 49 | (assert_return (invoke "global_set_c" (f32.const 55.5))) 50 | (assert_return (invoke "global_c" ) (f32.const 55.5)) 51 | (assert_return (invoke "global_set_d" (f64.const 66.6))) 52 | (assert_return (invoke "global_d" ) (f64.const 66.6)) 53 | 54 | (assert_return (invoke "global_r") (ref.null extern)) 55 | (assert_return (invoke "global_mr") (ref.null extern)) 56 | (assert_return (invoke "global_fr") ( ref.null func)) 57 | -------------------------------------------------------------------------------- /test/jit/indirect_i64_const_store.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1 1) 3 | ;; regression test for 32bit JIT 4 | (func (export "i64_indirect_store_const") (param i32) 5 | (i64.store 6 | (local.get 0) 7 | (i64.const 0xcafebabe) 8 | ) 9 | ) 10 | (func (export "i64_load") (param i32) (result i64) 11 | (i64.load (local.get 0)) 12 | ) 13 | ) 14 | (invoke "i64_indirect_store_const" (i32.const 10)) 15 | (assert_return (invoke "i64_load" (i32.const 10)) (i64.const 0xcafebabe)) 16 | -------------------------------------------------------------------------------- /test/jit/local-elim1.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $test1 (local i32 i32) 3 | local.get 0 4 | local.set 1 5 | 6 | i32.const 5 7 | local.set 0 8 | 9 | local.get 1 10 | i32.const 5 11 | i32.add 12 | local.set 0 13 | ) 14 | 15 | (func $test2 (local i32) 16 | i32.const 1 17 | if (result i32) 18 | local.get 0 19 | else 20 | local.get 0 21 | end 22 | 23 | local.set 0 24 | ) 25 | 26 | (func $test3 (local i32) 27 | i32.const 1 28 | if (result i32) 29 | i32.const 3 30 | else 31 | i32.const 3 32 | end 33 | 34 | local.set 0 35 | ) 36 | 37 | (func $test4 (local i32) 38 | i32.const 1 39 | if (result i32) 40 | local.get 0 41 | else 42 | i32.const 3 43 | end 44 | 45 | local.set 0 46 | ) 47 | ) 48 | -------------------------------------------------------------------------------- /test/jit/locals-remap1.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (result i32) (local i32 i32) 3 | i32.const 1 4 | local.set 0 5 | 6 | i32.const 5 7 | if 8 | i32.const 1 9 | local.set 0 10 | 11 | local.get 0 12 | drop 13 | else 14 | i32.const 1 15 | local.set 1 16 | end 17 | 18 | local.get 1 19 | drop 20 | 21 | local.get 0 22 | ) 23 | 24 | (func (local i32) 25 | i32.const 1 26 | drop 27 | 28 | i32.const 1 29 | local.set 0 30 | 31 | loop 32 | loop 33 | i32.const 1 34 | local.set 0 35 | 36 | i32.const 0 37 | br_if 1 38 | 39 | i32.const 0 40 | br_if 0 41 | end 42 | end 43 | ) 44 | 45 | (func (local i32) 46 | loop 47 | i32.const 0 48 | br_if 0 49 | end 50 | 51 | loop 52 | loop 53 | i32.const 0 54 | br_if 1 55 | 56 | i32.const 0 57 | if 58 | i32.const 1 59 | local.set 0 60 | else 61 | local.get 0 62 | br_if 1 63 | end 64 | end 65 | end 66 | 67 | loop 68 | i32.const 0 69 | br_if 0 70 | end 71 | ) 72 | 73 | (func (local i32) 74 | loop 75 | i32.const 0 76 | if 77 | i32.const 0 78 | local.set 0 79 | else 80 | i32.const 0 81 | local.set 0 82 | end 83 | local.get 0 84 | br_if 0 85 | end 86 | ) 87 | 88 | (func (local i32 i32 i32) 89 | i32.const 0 90 | local.set 2 91 | local.get 2 92 | local.set 1 93 | local.get 1 94 | local.set 0 95 | local.get 0 96 | drop 97 | ) 98 | 99 | (func (param i32 i32) (local i32 i32 i32) 100 | i32.const 0 101 | local.set 4 102 | local.get 4 103 | local.set 0 104 | ) 105 | ) 106 | -------------------------------------------------------------------------------- /test/jit/memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1) 3 | (func (export "storeload_f32") (param i32) (param f32) (result f32) 4 | (f32.store offset=1 (i32.const 0) (local.get 1)) 5 | (f32.load offset=1 (i32.const 0)) 6 | ) 7 | ) 8 | 9 | (assert_return (invoke "storeload_f32" (i32.const 0) (f32.const 1234)) (f32.const 1234)) 10 | -------------------------------------------------------------------------------- /test/jit/memory_large.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (; 1GB memory, can be quite large for a 32 bit system. ;) 3 | (memory 16384 16384) 4 | 5 | (func (export "set") (param i32 i32) 6 | local.get 0 7 | local.get 1 8 | i32.store8 9 | ) 10 | 11 | (func (export "get") (param i32) (result i32) 12 | local.get 0 13 | i32.load8_u 14 | ) 15 | ) 16 | 17 | (invoke "set" (i32.const 0x3fffffff) (i32.const 0xaa)) 18 | (assert_return (invoke "get" (i32.const 0x3fffffff)) (i32.const 0xaa)) 19 | (assert_trap (invoke "get" (i32.const 0x40000000)) "out of bounds memory access") 20 | -------------------------------------------------------------------------------- /test/jit/simd-shuffle.wast: -------------------------------------------------------------------------------- 1 | (module 2 | 3 | (func (export "test1") (param v128 v128) (result v128) 4 | local.get 0 5 | 6 | local.get 1 7 | local.get 1 8 | i64x2.add 9 | 10 | local.get 1 11 | v128.not 12 | local.set 1 13 | 14 | i8x16.shuffle 31 15 29 13 27 11 25 9 23 7 21 5 19 3 17 1 15 | ) 16 | 17 | (func (export "test2") (param v128 v128) (result v128) (local v128) 18 | local.get 1 19 | local.get 0 20 | 21 | local.get 1 22 | v128.not 23 | local.set 2 24 | 25 | i8x16.shuffle 30 14 28 12 26 10 24 8 22 6 20 4 18 2 16 0 26 | 27 | local.get 2 28 | v128.not 29 | local.set 2 30 | ) 31 | 32 | (func (export "test3") (param v128) (result v128) 33 | local.get 0 34 | local.get 0 35 | i8x16.shuffle 30 14 28 12 26 10 24 8 22 6 20 4 18 2 16 0 36 | ) 37 | ) 38 | 39 | (assert_return (invoke "test1" 40 | (v128.const i64x2 0x0807060504030201 0x100f0e0d0c0b0a09) 41 | (v128.const i64x2 0x1817161514131211 0x201f1e1d1c1b1a19)) 42 | (v128.const i64x2 0x0a340c380e3c1040 0x02240428062c0830)) 43 | 44 | (assert_return (invoke "test2" 45 | (v128.const i64x2 0x0807060504030201 0x100f0e0d0c0b0a09) 46 | (v128.const i64x2 0x1817161514131211 0x201f1e1d1c1b1a19)) 47 | (v128.const i64x2 0x19091b0b1d0d1f0f 0x1101130315051707)) 48 | 49 | (assert_return (invoke "test3" 50 | (v128.const i64x2 0x8182838485868788 0x2122232425262728)) 51 | (v128.const i64x2 0x2828262624242222 0x8888868684848282)) 52 | -------------------------------------------------------------------------------- /test/jit/splat.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (table $t 10 externref) 3 | 4 | (func (export "splat_f32") (result v128) 5 | f32.const 1234.75 6 | f32x4.splat 7 | ) 8 | 9 | (func (export "splat_f64") (result v128) 10 | f64.const -123456.75 11 | f64x2.splat 12 | ) 13 | ) 14 | 15 | (assert_return (invoke "splat_f32") (v128.const f32x4 1234.75 1234.75 1234.75 1234.75)) 16 | (assert_return (invoke "splat_f64") (v128.const f64x2 -123456.75 -123456.75)) 17 | -------------------------------------------------------------------------------- /test/jit/trycatch-dep.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1) 3 | 4 | (tag $except0 (param i32 i64)) 5 | (tag $except1 (param f32 f64)) 6 | (tag $except3) 7 | 8 | (func $throw1 (param i64) 9 | i32.const 1234 10 | local.get 0 11 | throw $except0 12 | ) 13 | 14 | (func $throw2 (param i64) 15 | f32.const 2345.0 16 | local.get 0 17 | f64.convert_i64_s 18 | throw $except1 19 | ) 20 | 21 | (func $throw3 (param i64) 22 | throw $except3 23 | ) 24 | 25 | (func (export "try1") (param i64) (result i64 i32) (local $l1 i64) (local $l2 i32) 26 | i32.const 123456 27 | local.set $l2 28 | (try 29 | (do 30 | (try 31 | (do 32 | local.get 0 33 | local.set $l1 34 | 35 | local.get $l1 36 | i32.wrap_i64 37 | i32.const 100 38 | i32.add 39 | local.set $l2 40 | 41 | i64.const 1000 42 | local.get $l1 43 | i64.lt_s 44 | if 45 | local.get $l1 46 | call $throw1 47 | end 48 | 49 | local.get $l1 50 | i64.const 500 51 | i64.gt_s 52 | if 53 | local.get $l1 54 | call $throw2 55 | end 56 | 57 | local.get $l1 58 | i64.const 250 59 | i64.gt_s 60 | if 61 | local.get $l1 62 | call $throw3 63 | end 64 | 65 | local.get $l1 66 | i64.const 17 67 | i64.sub 68 | i32.const -678 69 | return 70 | ) 71 | (catch $except0 72 | local.set $l1 73 | i64.extend_i32_s 74 | local.get $l1 75 | i64.add 76 | local.set $l1 77 | ) 78 | ) 79 | ) 80 | (catch $except1 81 | i64.trunc_sat_f64_s 82 | local.set $l1 83 | 84 | i64.trunc_sat_f32_s 85 | local.get $l1 86 | i64.add 87 | local.set $l1 88 | ) 89 | (catch_all 90 | i64.const 888 91 | local.set $l1 92 | ) 93 | ) 94 | 95 | local.get $l1 96 | local.get $l2 97 | ) 98 | ) 99 | 100 | (assert_return (invoke "try1" (i64.const 99)) (i64.const 82) (i32.const -678)) 101 | (assert_return (invoke "try1" (i64.const 2000)) (i64.const 3234) (i32.const 2100)) 102 | (assert_return (invoke "try1" (i64.const 600)) (i64.const 2945) (i32.const 700)) 103 | (assert_return (invoke "try1" (i64.const 300)) (i64.const 888) (i32.const 400)) 104 | -------------------------------------------------------------------------------- /test/jit/trycatch-mem.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1) 3 | (tag $except0 (param i32 i64 i32)) 4 | 5 | (func $throw1 (param i64 i32) 6 | local.get 1 7 | memory.grow 8 | 9 | local.get 0 10 | i64.const 0xffffffffffff 11 | i64.add 12 | 13 | memory.size 14 | throw $except0 15 | ) 16 | 17 | (func (export "try1") (result i32 i64 i32 i32 i32) 18 | (try (result i32 i64 i32 i32 i32) 19 | (do 20 | i64.const 0x123456781234 21 | i32.const 1 22 | call $throw1 23 | 24 | i32.const 0 25 | i64.const 0 26 | i32.const 0 27 | i32.const 0 28 | i32.const 0 29 | ) 30 | (catch $except0 31 | i32.const 2 32 | memory.grow 33 | memory.size 34 | ) 35 | ) 36 | ) 37 | ) 38 | 39 | (assert_return (invoke "try1") (i32.const 1) (i64.const 0x1123456781233) (i32.const 2) (i32.const 2) (i32.const 4)) 40 | -------------------------------------------------------------------------------- /test/jit/trycatch.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (tag $except0 (param i32 i64 f32 f64)) 3 | 4 | (func $throw1 (param i64 f64) 5 | local.get 0 6 | i32.wrap_i64 7 | local.get 0 8 | i64.const 10 9 | i64.add 10 | 11 | local.get 1 12 | f32.demote_f64 13 | local.get 1 14 | f64.const 10 15 | f64.sub 16 | 17 | throw $except0 18 | ) 19 | 20 | (func $throw2 21 | i32.const 1234 22 | i64.const 4321 23 | f32.const 6789.5 24 | f64.const -9876.75 25 | 26 | throw $except0 27 | ) 28 | 29 | (func (export "try1") (param i64 f64) (result i32 i64 f32 f64) 30 | (try 31 | (do 32 | local.get 0 33 | local.get 1 34 | call $throw1 35 | ) 36 | (catch $except0 37 | return 38 | ) 39 | ) 40 | 41 | i32.const 0 42 | i64.const 0 43 | f32.const 0 44 | f64.const 0 45 | ) 46 | 47 | (func (export "try2") (result i32 i64 f32 f64) 48 | (try 49 | (do 50 | call $throw2 51 | ) 52 | (catch $except0 53 | return 54 | ) 55 | ) 56 | 57 | i32.const 0 58 | i64.const 0 59 | f32.const 0 60 | f64.const 0 61 | ) 62 | ) 63 | 64 | (assert_return (invoke "try1" (i64.const 1234567) (f64.const 123456.5)) 65 | (i32.const 1234567) (i64.const 1234577) (f32.const 123456.5) (f64.const 123446.5)) 66 | (assert_return (invoke "try2") (i32.const 1234) (i64.const 4321) (f32.const 6789.5) (f64.const -9876.75)) 67 | -------------------------------------------------------------------------------- /test/jit/unary.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test1") (result i64 i64 i64 i64 i64 i64) (local i64) 3 | i64.const 0 4 | local.set 0 5 | 6 | i64.const 0 7 | i64.clz 8 | 9 | local.get 0 10 | i64.ctz 11 | 12 | i64.const 0x800000000000 13 | local.tee 0 14 | i64.clz 15 | 16 | local.get 0 17 | i64.ctz 18 | 19 | i64.const 0x100 20 | local.tee 0 21 | i64.clz 22 | 23 | local.get 0 24 | i64.ctz 25 | (; 64, 64, 16, 47, 55, 8 ;) 26 | ) 27 | ) 28 | 29 | (assert_return (invoke "test1") (i64.const 64) (i64.const 64) (i64.const 16) (i64.const 47) (i64.const 55) (i64.const 8)) 30 | -------------------------------------------------------------------------------- /test/jit/unreachable.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $f1 3 | unreachable 4 | ) 5 | 6 | (func $f2 7 | call $f1 8 | ) 9 | 10 | (func $test2 (export "test1") 11 | call $f2 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/wasi/clock.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "clock_res_get" (func $clock_res_get (param i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "clock_time_get" (func $clock_time_get (param i32 i64 i32) (result i32))) 4 | (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) 5 | (memory 1) 6 | (export "_start" (func $_start)) 7 | (func $_start 8 | (call $clock_res_get (i32.const 0) (i32.const 0)) 9 | (if 10 | (then 11 | i32.const 1 12 | call $proc_exit 13 | ) 14 | ) 15 | 16 | (call $clock_time_get (i32.const 0) (i64.const 1000000) (i32.const 0)) 17 | i32.eqz 18 | i32.eqz 19 | call $proc_exit 20 | ) 21 | ) 22 | 23 | (assert_return (invoke "_start")) 24 | -------------------------------------------------------------------------------- /test/wasi/environ.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "fd_write" (func $wasi_fd_write (param i32 i32 i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "environ_get" (func $wasi_environ_get (param i32 i32) (result i32))) 4 | (import "wasi_snapshot_preview1" "environ_sizes_get" (func $wasi_environ_sizes_get (param i32 i32) (result i32))) 5 | (memory 1) 6 | 7 | (export "memory" (memory 0)) 8 | (export "environ" (func $environ)) 9 | (data (i32.const 100) "500" ) 10 | 11 | (func $environ 12 | (local $i i32) 13 | i32.const 0 ;; environment variables count 14 | i32.const 12 ;; environment variables overall size in characters 15 | call $wasi_environ_sizes_get 16 | drop 17 | 18 | i32.const 500 ;; envp 19 | i32.const 500 ;; envp[0] 20 | call $wasi_environ_get 21 | drop 22 | 23 | ;; Memory + 50 = 500, start of output string. 24 | i32.const 50 25 | i32.const 500 26 | i32.store 27 | 28 | ;; Memory + 54 = size of output string. 29 | i32.const 54 30 | i32.const 12 31 | i32.load 32 | i32.store 33 | 34 | ;; Replace '\0' with '\n' for readable printing. 35 | i32.const 0 36 | local.set $i 37 | (loop $loop 38 | i32.const 500 39 | local.get $i 40 | i32.add 41 | i32.load8_u 42 | 43 | i32.eqz 44 | (if 45 | (then 46 | i32.const 500 47 | local.get $i 48 | i32.add 49 | i32.const 10 50 | i32.store8 51 | ) 52 | ) 53 | 54 | local.get $i 55 | i32.const 1 56 | i32.add 57 | local.tee $i 58 | 59 | i32.const 12 60 | i32.load 61 | i32.lt_u 62 | br_if $loop 63 | ) 64 | 65 | (call $wasi_fd_write 66 | (i32.const 1) ;;file descriptor 67 | (i32.const 50) ;;offset of str offset 68 | (i32.const 1) ;;iovec length 69 | (i32.const 200) ;;result offset 70 | ) 71 | drop 72 | ) 73 | ) 74 | 75 | (assert_return (invoke "environ")) 76 | -------------------------------------------------------------------------------- /test/wasi/fd_advise.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "path_open" (func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "fd_advise" (func $fd_advise (param i32 i64 i64 i32) (result i32))) 4 | 5 | (memory $mem 1) 6 | (data (i32.const 300) "./write_to_this.txt") ;; Filename in current directory (where Walrus is ran from) 7 | 8 | (func (export "test_advise") (param i32) (result i32) ;; advice is passed as param, return is if the function returned succesfully 9 | i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory 10 | i32.const 1 ;; lookupflags: directory 11 | i32.const 300 ;; Offset of file name in memory 12 | i32.const 19 ;; Length of file name 13 | i32.const 0 ;; oflags: none 14 | i64.const 128 ;; rights: fd_advise 15 | i64.const 128 ;; rights_inheriting: fd_advise 16 | i32.const 0 ;; fdflags: none 17 | i32.const 0 ;; Offset to store at the opened file descriptor in memory 18 | call $path_open 19 | 20 | i32.eqz ;; fail if file could not be opened 21 | (if 22 | (then) 23 | (else 24 | i32.const 1 25 | return 26 | ) 27 | ) 28 | 29 | i32.const 0 30 | i32.load ;; Get the file descriptor 31 | i64.const 0 ;; Start for 0 offset 32 | i64.const 0 ;; For the entire file 33 | local.get 0 ;; Advise 34 | call $fd_advise 35 | return 36 | ) 37 | 38 | (export "memory" (memory 0)) 39 | ) 40 | 41 | (assert_return (invoke "test_advise" (i32.const 0)) (i32.const 0)) 42 | (assert_return (invoke "test_advise" (i32.const 1)) (i32.const 0)) 43 | (assert_return (invoke "test_advise" (i32.const 2)) (i32.const 0)) 44 | (assert_return (invoke "test_advise" (i32.const 3)) (i32.const 0)) 45 | (assert_return (invoke "test_advise" (i32.const 4)) (i32.const 0)) 46 | (assert_return (invoke "test_advise" (i32.const 5)) (i32.const 0)) 47 | 48 | (assert_return (invoke "test_advise" (i32.const 6)) (i32.const 28)) ;; Returns invalid function argument, as it should 49 | 50 | -------------------------------------------------------------------------------- /test/wasi/fd_fdstat_get.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "path_open" (func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "fd_close" (func $fd_close (param i32) (result i32))) 4 | (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $fd_fdstat_get (param i32 i32) (result i32))) 5 | 6 | (memory 1 1) 7 | (data (i32.const 100) "./fd_fdstat_get.wast") 8 | 9 | (func (export "fdstatGet") (result i32 i32 i32) 10 | i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory 11 | i32.const 1 ;; uvwasi_lookupflags_t: UVWASI_LOOKUP_SYMLINK_FOLLOW 12 | i32.const 100 ;; Offset of file name in memory 13 | i32.const 20 ;; Length of file name 14 | i32.const 0 ;; uvwasi_oflags_t: none 15 | i64.const 0x42000 ;; base uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET 16 | i64.const 0x42000 ;; inherited uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET 17 | i32.const 0 ;; uvwasi_fdflags_t: none 18 | i32.const 0 ;; Offset to store at the opened file descriptor in memory 19 | call $path_open 20 | 21 | i32.const 0 22 | i32.load 23 | i32.const 200 24 | call $fd_fdstat_get 25 | 26 | i32.const 0 27 | i32.load 28 | call $fd_close 29 | ) 30 | 31 | (func (export "fdstatGetBad") (result i32 i32 i32 i32) 32 | i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory 33 | i32.const 1 ;; uvwasi_lookupflags_t: UVWASI_LOOKUP_SYMLINK_FOLLOW 34 | i32.const 100 ;; Offset of file name in memory 35 | i32.const 20 ;; Length of file name 36 | i32.const 0 ;; uvwasi_oflags_t: none 37 | i64.const 0x42000 ;; base uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET 38 | i64.const 0x42000 ;; inherited uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET 39 | i32.const 0 ;; uvwasi_fdflags_t: none 40 | i32.const 0 ;; Offset to store at the opened file descriptor in memory 41 | call $path_open 42 | 43 | i32.const 0 44 | i32.load 45 | i32.const 65535 46 | call $fd_fdstat_get 47 | 48 | i32.const -1 49 | i32.const 200 50 | call $fd_fdstat_get 51 | 52 | i32.const 0 53 | i32.load 54 | call $fd_close 55 | ) 56 | ) 57 | 58 | (assert_return (invoke "fdstatGet") (i32.const 0) (i32.const 0) (i32.const 0)) 59 | (assert_return (invoke "fdstatGetBad") (i32.const 0) (i32.const 28) (i32.const 8) (i32.const 0)) 60 | 61 | -------------------------------------------------------------------------------- /test/wasi/fd_prestat.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "fd_prestat_get" (func $fd_prestat_get (param i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "fd_prestat_dir_name" (func $fd_prestat_dir_name (param i32 i32 i32) (result i32))) 4 | (memory $mem 1) 5 | 6 | (; fd_prestat_get return information about a preopened file, 7 | meaning one that was passed with '--mapdirs' ;) 8 | 9 | (func (export "test_prestat_get") (param i32) (result i32) 10 | local.get 0 ;; file descriptor 11 | i32.const 0 ;; stored information offset in memory 12 | call $fd_prestat_get 13 | ) 14 | 15 | (func (export "test_prestat_dir_name") (param i32) (result i32) 16 | local.get 0 ;; file descriptor 17 | i32.const 0 ;; stored information offset in memory 18 | i32.const 128 ;; max lenght of file path 19 | call $fd_prestat_dir_name 20 | ) 21 | ) 22 | 23 | (assert_return (invoke "test_prestat_get" (i32.const 3)) (i32.const 0)) 24 | (assert_return (invoke "test_prestat_get" (i32.const 4)) (i32.const 8)) ;; Error 8: bad file descriptor because it does not exist 25 | (assert_return (invoke "test_prestat_dir_name" (i32.const 3)) (i32.const 0)) ;; mapped directory 26 | (assert_return (invoke "test_prestat_dir_name" (i32.const 0)) (i32.const 8)) ;; Error 8: bad file descriptor because stdin is not a mapped directory 27 | (assert_return (invoke "test_prestat_dir_name" (i32.const 4)) (i32.const 8)) ;; Error 8: bad file descriptor because it does not exist 28 | 29 | -------------------------------------------------------------------------------- /test/wasi/hello_world.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "fd_write" (func $wasi_fd_write (param i32 i32 i32 i32) (result i32))) 3 | (memory 1) 4 | 5 | (export "memory" (memory 0)) 6 | (export "hello_world" (func $hello_world)) 7 | (data (i32.const 0) "Hello World!\n") 8 | 9 | (func $hello_world 10 | (i32.store (i32.const 100) (i32.const 0)) 11 | (i32.store (i32.const 104) (i32.const 13)) 12 | (i32.store (i32.const 200) (i32.const 0)) 13 | (call $wasi_fd_write 14 | (i32.const 1) ;;file descriptor 15 | (i32.const 100) ;;offset of str offset 16 | (i32.const 1) ;;iovec length 17 | (i32.const 200) ;;result offset 18 | ) 19 | drop 20 | ) 21 | ) 22 | 23 | (assert_return (invoke "hello_world")) 24 | -------------------------------------------------------------------------------- /test/wasi/print.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) 3 | 4 | (memory $memory 1 1) 5 | (data (i32.const 100) "Hello ") 6 | (data (i32.const 200) "World!\n") 7 | 8 | (func (export "writeToStdout") (result i32 i32) 9 | ;; Write iovs into memory from offset 16 10 | i32.const 16 11 | i32.const 100 12 | i32.store 13 | 14 | i32.const 20 15 | i32.const 6 16 | i32.store 17 | 18 | i32.const 24 19 | i32.const 200 20 | i32.store 21 | 22 | i32.const 28 23 | i32.const 7 24 | i32.store 25 | 26 | i32.const 1 ;; stdout 27 | i32.const 16 ;; iovs offset 28 | i32.const 2 ;; iovsLen 29 | i32.const 8 ;; nwritten 30 | 31 | call $fd_write 32 | 33 | i32.const 8 34 | i32.load 35 | ) 36 | 37 | (func (export "badWrite") (result i32 i32 i32 i32) 38 | i32.const 100000 ;; invalid descriptor 39 | i32.const 8 ;; iovs offset 40 | i32.const 1 ;; iovsLen 41 | i32.const 4 ;; nwritten 42 | 43 | call $fd_write 44 | 45 | i32.const 1 ;; stdout 46 | i32.const 65529 ;; bad iovs offset 47 | i32.const 1 ;; iovsLen 48 | i32.const 8 ;; nwritten 49 | 50 | call $fd_write 51 | 52 | i32.const 1 ;; stdout 53 | i32.const 16 ;; iovs offset 54 | i32.const 1 ;; iovsLen 55 | i32.const 65533 ;; bad nwritten 56 | 57 | call $fd_write 58 | 59 | i32.const 1 ;; stdout 60 | i32.const 8 ;; iovs offset 61 | i32.const 8192 ;; bad iovsLen 62 | i32.const 0 ;; nwritten 63 | 64 | call $fd_write 65 | ) 66 | ) 67 | 68 | (assert_return (invoke "writeToStdout") (i32.const 0) (i32.const 13)) 69 | (assert_return (invoke "badWrite") (i32.const 8) (i32.const 28) (i32.const 28) (i32.const 28)) 70 | -------------------------------------------------------------------------------- /test/wasi/proc_exit.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "proc_exit" (func $wasi_proc_exit (param i32))) 3 | 4 | (func (export "proc_exit") 5 | i32.const 0 6 | call $wasi_proc_exit 7 | ) 8 | ) 9 | 10 | (assert_return (invoke "proc_exit")) 11 | -------------------------------------------------------------------------------- /test/wasi/proc_raise.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "proc_raise" (func $wasi_proc_raise (param i32) (result i32))) 3 | 4 | (func (export "proc_raise") (result i32) 5 | i32.const 0 ;; illegal signal ID 6 | call $wasi_proc_raise 7 | ) 8 | ) 9 | 10 | (assert_return (invoke "proc_raise") (i32.const 52)) 11 | -------------------------------------------------------------------------------- /test/wasi/random_get.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "random_get" (func $random (param i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) 4 | (memory 1) 5 | (export "_start" (func $_start)) 6 | (func $_start 7 | (call $random (i32.const 10) (i32.const 5)) 8 | i32.eqz 9 | (if 10 | (then 11 | i32.const 0 12 | call $proc_exit 13 | ) 14 | (else 15 | i32.const 1 16 | call $proc_exit 17 | ) 18 | ) 19 | ) 20 | ) 21 | 22 | (assert_return (invoke "_start")) 23 | -------------------------------------------------------------------------------- /test/wasi/read_from_file.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "path_open" (func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "fd_write" (func $wasi_fd_write (param i32 i32 i32 i32) (result i32))) 4 | (import "wasi_snapshot_preview1" "fd_read" (func $wasi_fd_read (param i32 i32 i32 i32) (result i32))) 5 | (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) 6 | 7 | (memory 1) 8 | 9 | (export "memory" (memory 0)) 10 | (export "read_from_file" (func $read_from_file)) 11 | (data (i32.const 300) "./write_to_this.txt") 12 | 13 | (; 14 | This test searches for the file 'write_to_this.txt' in the first opened directory 15 | and reads 13 characters out of it. 16 | It will only read from the file if the directories were mapped correctly. 17 | ;) 18 | 19 | (func $read_from_file 20 | i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory 21 | i32.const 1 ;;lookupflags: directory 22 | i32.const 300 ;; Offset of file name in memory 23 | i32.const 19 ;; Length of file name 24 | i32.const 0 ;; oflags: none 25 | i64.const 4098 ;; rights: path_open, fd_read 26 | i64.const 4098 ;; rights_inheriting: path_open, fd_read 27 | i32.const 0 ;; fdflags: none 28 | i32.const 0 ;; Offset to store at the opened file descriptor in memory 29 | call $path_open 30 | 31 | i32.eqz ;; fail if file could not be opened 32 | (if 33 | (then) 34 | (else 35 | i32.const 1 36 | call $proc_exit 37 | ) 38 | ) 39 | 40 | (i32.store (i32.const 104) (i32.const 13)) 41 | (i32.store (i32.const 100) (i32.const 0)) 42 | (i32.store (i32.const 200) (i32.const 500)) 43 | 44 | (call $wasi_fd_read 45 | (i32.const 0) 46 | (i32.load) ;; opened file descriptor 47 | 48 | (i32.const 100) ;; store content at this location 49 | (i32.const 1) ;; make it into a single buffer 50 | (i32.const 200) ;; store number of read characters to this location 51 | ) 52 | drop 53 | 54 | (call $wasi_fd_write 55 | (i32.const 1) ;;file descriptor 56 | (i32.const 100) ;;offset of str offset 57 | (i32.const 1) ;;iovec length 58 | (i32.const 200) ;;result offset 59 | ) 60 | drop 61 | ) 62 | ) 63 | 64 | (assert_return (invoke "read_from_file")) 65 | -------------------------------------------------------------------------------- /test/wasi/some_file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samsung/walrus/023b7bd2cc267a5b4e83aeccf263ab5e5dfa7dd3/test/wasi/some_file.txt -------------------------------------------------------------------------------- /test/wasi/text.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /test/wasi/write_to_file.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "path_open" (func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) 3 | (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) 4 | (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) 5 | 6 | (memory $memory 1) 7 | (data (i32.const 200) "Hello World!\n") ;; String we want to write to file 8 | (data (i32.const 300) "./write_to_this.txt") ;; Filename in current directory (where Walrus is ran from) 9 | 10 | (; This test searches for the file 'write_to_this.txt' in the first opened directory. 11 | It will only write into the file if the directories were mapped correctly. ;) 12 | 13 | (func $write_to_file 14 | i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory 15 | i32.const 1 ;; lookupflags: directory 16 | i32.const 300 ;; Offset of file name in memory 17 | i32.const 19 ;; Length of file name 18 | i32.const 0 ;; oflags: none 19 | i64.const 8256 ;; rights: path_open, fd_write 20 | i64.const 8256 ;; rights_inheriting: path_open, fd_write 21 | i32.const 0 ;; fdflags: none 22 | i32.const 0 ;; Offset to store at the opened file descriptor in memory 23 | call $path_open 24 | 25 | i32.eqz ;; fail if file could not be opened 26 | (if 27 | (then) 28 | (else 29 | i32.const 1 30 | call $proc_exit 31 | ) 32 | ) 33 | 34 | i32.const 500 ;; offset of str offset 35 | i32.const 200 ;; offset of str 36 | i32.store 37 | 38 | i32.const 504 ;; str length offset 39 | i32.const 13 40 | i32.store 41 | 42 | i32.const 0 ;; load file descriptior 43 | i32.load 44 | i32.const 500 ;; offset of str offset 45 | i32.const 1 ;; iovec length 46 | i32.const 0 ;; offset of written characters 47 | call $fd_write 48 | drop 49 | ) 50 | 51 | (export "_start" (func $write_to_file)) 52 | (export "memory" (memory 0)) 53 | ) 54 | -------------------------------------------------------------------------------- /test/wasi/write_to_this.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /test/wasm-spec/README.md: -------------------------------------------------------------------------------- 1 | these tests are copied from https://github.com/WebAssembly/spec/tree/main/test 2 | -------------------------------------------------------------------------------- /test/wasm-spec/core/comments.wast: -------------------------------------------------------------------------------- 1 | ;; Test comment syntax 2 | 3 | ;;comment 4 | 5 | ;;;;;;;;;;; 6 | 7 | ;;comment 8 | 9 | ( ;;comment 10 | module;;comment 11 | );;comment 12 | 13 | ;;) 14 | ;;;) 15 | ;; ;) 16 | ;; (; 17 | 18 | (;;) 19 | 20 | (;comment;) 21 | 22 | (;;comment;) 23 | 24 | (;;;comment;) 25 | 26 | (;;;;;;;;;;;;;;) 27 | 28 | (;(((((((((( ;) 29 | 30 | (;)))))))))));) 31 | 32 | (;comment";) 33 | 34 | (;comment"";) 35 | 36 | (;comment""";) 37 | 38 | ;; ASCII 00-1F, 7F 39 | (; 40 | ;) 41 | 42 | ;; null-byte followed immediately by end-of-comment delimiter 43 | (;;) 44 | 45 | 46 | (;Heiße Würstchen;) 47 | 48 | (;;) 49 | 50 | (;comment 51 | comment;) 52 | 53 | (;comment;) 54 | 55 | (;comment;)((;comment;) 56 | (;comment;)module(;comment;) 57 | (;comment;))(;comment;) 58 | 59 | (;comment(;nested;)comment;) 60 | 61 | (;comment 62 | (;nested 63 | ;)comment 64 | ;) 65 | 66 | (module 67 | (;comment(;nested(;further;)nested;)comment;) 68 | ) 69 | 70 | (;comment;;comment;) 71 | 72 | (;comment;;comment 73 | ;) 74 | 75 | (module 76 | (;comment;;comment(;nested;)comment;) 77 | ) 78 | -------------------------------------------------------------------------------- /test/wasm-spec/core/forward.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $even (export "even") (param $n i32) (result i32) 3 | (if (result i32) (i32.eq (local.get $n) (i32.const 0)) 4 | (then (i32.const 1)) 5 | (else (call $odd (i32.sub (local.get $n) (i32.const 1)))) 6 | ) 7 | ) 8 | 9 | (func $odd (export "odd") (param $n i32) (result i32) 10 | (if (result i32) (i32.eq (local.get $n) (i32.const 0)) 11 | (then (i32.const 0)) 12 | (else (call $even (i32.sub (local.get $n) (i32.const 1)))) 13 | ) 14 | ) 15 | ) 16 | 17 | (assert_return (invoke "even" (i32.const 13)) (i32.const 0)) 18 | (assert_return (invoke "even" (i32.const 20)) (i32.const 1)) 19 | (assert_return (invoke "odd" (i32.const 13)) (i32.const 1)) 20 | (assert_return (invoke "odd" (i32.const 20)) (i32.const 0)) 21 | -------------------------------------------------------------------------------- /test/wasm-spec/core/inline-module.wast: -------------------------------------------------------------------------------- 1 | (func) (memory 0) (func (export "f")) 2 | -------------------------------------------------------------------------------- /test/wasm-spec/core/memory_redundancy.wast: -------------------------------------------------------------------------------- 1 | ;; Test that optimizers don't do redundant-load, store-to-load, or dead-store 2 | ;; optimizations when there are interfering stores, even of different types 3 | ;; and to non-identical addresses. 4 | 5 | (module 6 | (memory 1 1) 7 | 8 | (func (export "zero_everything") 9 | (i32.store (i32.const 0) (i32.const 0)) 10 | (i32.store (i32.const 4) (i32.const 0)) 11 | (i32.store (i32.const 8) (i32.const 0)) 12 | (i32.store (i32.const 12) (i32.const 0)) 13 | ) 14 | 15 | (func (export "test_store_to_load") (result i32) 16 | (i32.store (i32.const 8) (i32.const 0)) 17 | (f32.store (i32.const 5) (f32.const -0.0)) 18 | (i32.load (i32.const 8)) 19 | ) 20 | 21 | (func (export "test_redundant_load") (result i32) 22 | (local $t i32) 23 | (local $s i32) 24 | (local.set $t (i32.load (i32.const 8))) 25 | (i32.store (i32.const 5) (i32.const 0x80000000)) 26 | (local.set $s (i32.load (i32.const 8))) 27 | (i32.add (local.get $t) (local.get $s)) 28 | ) 29 | 30 | (func (export "test_dead_store") (result f32) 31 | (local $t f32) 32 | (i32.store (i32.const 8) (i32.const 0x23232323)) 33 | (local.set $t (f32.load (i32.const 11))) 34 | (i32.store (i32.const 8) (i32.const 0)) 35 | (local.get $t) 36 | ) 37 | 38 | ;; A function named "malloc" which implementations nonetheless shouldn't 39 | ;; assume behaves like C malloc. 40 | (func $malloc (export "malloc") 41 | (param $size i32) 42 | (result i32) 43 | (i32.const 16) 44 | ) 45 | 46 | ;; Call malloc twice, but unlike C malloc, we don't get non-aliasing pointers. 47 | (func (export "malloc_aliasing") 48 | (result i32) 49 | (local $x i32) 50 | (local $y i32) 51 | (local.set $x (call $malloc (i32.const 4))) 52 | (local.set $y (call $malloc (i32.const 4))) 53 | (i32.store (local.get $x) (i32.const 42)) 54 | (i32.store (local.get $y) (i32.const 43)) 55 | (i32.load (local.get $x)) 56 | ) 57 | ) 58 | 59 | (assert_return (invoke "test_store_to_load") (i32.const 0x00000080)) 60 | (invoke "zero_everything") 61 | (assert_return (invoke "test_redundant_load") (i32.const 0x00000080)) 62 | (invoke "zero_everything") 63 | (assert_return (invoke "test_dead_store") (f32.const 0x1.18p-144)) 64 | (invoke "zero_everything") 65 | (assert_return (invoke "malloc_aliasing") (i32.const 43)) 66 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/align0.wast: -------------------------------------------------------------------------------- 1 | ;; Test aligned and unaligned read/write 2 | 3 | (module 4 | (memory $mem0 0) 5 | (memory $mem1 1) 6 | (memory $mem2 0) 7 | 8 | ;; $default: natural alignment, $1: align=1, $2: align=2, $4: align=4, $8: align=8 9 | 10 | (func (export "f32_align_switch") (param i32) (result f32) 11 | (local f32 f32) 12 | (local.set 1 (f32.const 10.0)) 13 | (block $4 14 | (block $2 15 | (block $1 16 | (block $default 17 | (block $0 18 | (br_table $0 $default $1 $2 $4 (local.get 0)) 19 | ) ;; 0 20 | (f32.store $mem1 (i32.const 0) (local.get 1)) 21 | (local.set 2 (f32.load $mem1 (i32.const 0))) 22 | (br $4) 23 | ) ;; default 24 | (f32.store $mem1 align=1 (i32.const 0) (local.get 1)) 25 | (local.set 2 (f32.load $mem1 align=1 (i32.const 0))) 26 | (br $4) 27 | ) ;; 1 28 | (f32.store $mem1 align=2 (i32.const 0) (local.get 1)) 29 | (local.set 2 (f32.load $mem1 align=2 (i32.const 0))) 30 | (br $4) 31 | ) ;; 2 32 | (f32.store $mem1 align=4 (i32.const 0) (local.get 1)) 33 | (local.set 2 (f32.load $mem1 align=4 (i32.const 0))) 34 | ) ;; 4 35 | (local.get 2) 36 | ) 37 | ) 38 | 39 | (assert_return (invoke "f32_align_switch" (i32.const 0)) (f32.const 10.0)) 40 | (assert_return (invoke "f32_align_switch" (i32.const 1)) (f32.const 10.0)) 41 | (assert_return (invoke "f32_align_switch" (i32.const 2)) (f32.const 10.0)) 42 | (assert_return (invoke "f32_align_switch" (i32.const 3)) (f32.const 10.0)) 43 | 44 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/data0.wast: -------------------------------------------------------------------------------- 1 | ;; Test the data section 2 | 3 | ;; Syntax 4 | 5 | (module 6 | (memory $mem0 1) 7 | (memory $mem1 1) 8 | (memory $mem2 1) 9 | 10 | (data (i32.const 0)) 11 | (data (i32.const 1) "a" "" "bcd") 12 | (data (offset (i32.const 0))) 13 | (data (offset (i32.const 0)) "" "a" "bc" "") 14 | (data (memory 0) (i32.const 0)) 15 | (data (memory 0x0) (i32.const 1) "a" "" "bcd") 16 | (data (memory 0x000) (offset (i32.const 0))) 17 | (data (memory 0) (offset (i32.const 0)) "" "a" "bc" "") 18 | (data (memory $mem0) (i32.const 0)) 19 | (data (memory $mem1) (i32.const 1) "a" "" "bcd") 20 | (data (memory $mem2) (offset (i32.const 0))) 21 | (data (memory $mem0) (offset (i32.const 0)) "" "a" "bc" "") 22 | 23 | (data $d1 (i32.const 0)) 24 | (data $d2 (i32.const 1) "a" "" "bcd") 25 | (data $d3 (offset (i32.const 0))) 26 | (data $d4 (offset (i32.const 0)) "" "a" "bc" "") 27 | (data $d5 (memory 0) (i32.const 0)) 28 | (data $d6 (memory 0x0) (i32.const 1) "a" "" "bcd") 29 | (data $d7 (memory 0x000) (offset (i32.const 0))) 30 | (data $d8 (memory 0) (offset (i32.const 0)) "" "a" "bc" "") 31 | (data $d9 (memory $mem0) (i32.const 0)) 32 | (data $d10 (memory $mem1) (i32.const 1) "a" "" "bcd") 33 | (data $d11 (memory $mem2) (offset (i32.const 0))) 34 | (data $d12 (memory $mem0) (offset (i32.const 0)) "" "a" "bc" "") 35 | ) 36 | 37 | ;; Basic use 38 | 39 | (module 40 | (memory 1) 41 | (data (i32.const 0) "a") 42 | ) 43 | (module 44 | (import "spectest" "memory" (memory 1)) 45 | (import "spectest" "memory" (memory 1)) 46 | (import "spectest" "memory" (memory 1)) 47 | (data (memory 0) (i32.const 0) "a") 48 | (data (memory 1) (i32.const 0) "a") 49 | (data (memory 2) (i32.const 0) "a") 50 | ) 51 | 52 | (module 53 | (global (import "spectest" "global_i32") i32) 54 | (memory 1) 55 | (data (global.get 0) "a") 56 | ) 57 | (module 58 | (global (import "spectest" "global_i32") i32) 59 | (import "spectest" "memory" (memory 1)) 60 | (data (global.get 0) "a") 61 | ) 62 | 63 | (module 64 | (global $g (import "spectest" "global_i32") i32) 65 | (memory 1) 66 | (data (global.get $g) "a") 67 | ) 68 | (module 69 | (global $g (import "spectest" "global_i32") i32) 70 | (import "spectest" "memory" (memory 1)) 71 | (data (global.get $g) "a") 72 | ) 73 | 74 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/data_drop0.wast: -------------------------------------------------------------------------------- 1 | ;; data.drop 2 | (module 3 | (memory $mem0 0) 4 | (memory $mem1 1) 5 | (memory $mem2 0) 6 | (data $p "x") 7 | (data $a (memory 1) (i32.const 0) "x") 8 | 9 | (func (export "drop_passive") (data.drop $p)) 10 | (func (export "init_passive") (param $len i32) 11 | (memory.init $mem1 $p (i32.const 0) (i32.const 0) (local.get $len))) 12 | 13 | (func (export "drop_active") (data.drop $a)) 14 | (func (export "init_active") (param $len i32) 15 | (memory.init $mem1 $a (i32.const 0) (i32.const 0) (local.get $len))) 16 | ) 17 | 18 | (invoke "init_passive" (i32.const 1)) 19 | (invoke "drop_passive") 20 | (invoke "drop_passive") 21 | (assert_return (invoke "init_passive" (i32.const 0))) 22 | (assert_trap (invoke "init_passive" (i32.const 1)) "out of bounds memory access") 23 | (invoke "init_passive" (i32.const 0)) 24 | (invoke "drop_active") 25 | (assert_return (invoke "init_active" (i32.const 0))) 26 | (assert_trap (invoke "init_active" (i32.const 1)) "out of bounds memory access") 27 | (invoke "init_active" (i32.const 0)) 28 | 29 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/exports0.wast: -------------------------------------------------------------------------------- 1 | ;; Memories 2 | 3 | (module (memory 0) (export "a" (memory 0))) 4 | (module (memory 0) (export "a" (memory 0)) (export "b" (memory 0))) 5 | (module (memory 0) (memory 0) (export "a" (memory 0)) (export "b" (memory 1))) 6 | (module 7 | (memory $mem0 0) 8 | (memory $mem1 0) 9 | (memory $mem2 0) 10 | (memory $mem3 0) 11 | (memory $mem4 0) 12 | (memory $mem5 0) 13 | (memory $mem6 0) 14 | 15 | (export "a" (memory $mem0)) 16 | (export "b" (memory $mem1)) 17 | (export "ac" (memory $mem2)) 18 | (export "bc" (memory $mem3)) 19 | (export "ad" (memory $mem4)) 20 | (export "bd" (memory $mem5)) 21 | (export "be" (memory $mem6)) 22 | 23 | (export "za" (memory $mem0)) 24 | (export "zb" (memory $mem1)) 25 | (export "zac" (memory $mem2)) 26 | (export "zbc" (memory $mem3)) 27 | (export "zad" (memory $mem4)) 28 | (export "zbd" (memory $mem5)) 29 | (export "zbe" (memory $mem6)) 30 | ) 31 | 32 | (module 33 | (export "a" (memory 0)) 34 | (memory 6) 35 | 36 | (export "b" (memory 1)) 37 | (memory 3) 38 | ) 39 | 40 | (module 41 | (export "a" (memory 0)) 42 | (memory 0 1) 43 | (memory 0 1) 44 | (memory 0 1) 45 | (memory 0 1) 46 | 47 | (export "b" (memory 3)) 48 | ) 49 | (module (export "a" (memory $a)) (memory $a 0)) 50 | (module (export "a" (memory $a)) (memory $a 0 1)) 51 | 52 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/float_exprs0.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 0 0) 3 | (memory $m 1 1) 4 | (memory 0 0) 5 | (func (export "init") (param $i i32) (param $x f64) 6 | (f64.store $m (local.get $i) (local.get $x))) 7 | 8 | (func (export "run") (param $n i32) (param $z f64) 9 | (local $i i32) 10 | (block $exit 11 | (loop $cont 12 | (f64.store $m 13 | (local.get $i) 14 | (f64.div (f64.load $m (local.get $i)) (local.get $z)) 15 | ) 16 | (local.set $i (i32.add (local.get $i) (i32.const 8))) 17 | (br_if $cont (i32.lt_u (local.get $i) (local.get $n))) 18 | ) 19 | ) 20 | ) 21 | 22 | (func (export "check") (param $i i32) (result f64) (f64.load $m (local.get $i))) 23 | ) 24 | 25 | (invoke "init" (i32.const 0) (f64.const 15.1)) 26 | (invoke "init" (i32.const 8) (f64.const 15.2)) 27 | (invoke "init" (i32.const 16) (f64.const 15.3)) 28 | (invoke "init" (i32.const 24) (f64.const 15.4)) 29 | (assert_return (invoke "check" (i32.const 0)) (f64.const 15.1)) 30 | (assert_return (invoke "check" (i32.const 8)) (f64.const 15.2)) 31 | (assert_return (invoke "check" (i32.const 16)) (f64.const 15.3)) 32 | (assert_return (invoke "check" (i32.const 24)) (f64.const 15.4)) 33 | (invoke "run" (i32.const 32) (f64.const 3.0)) 34 | (assert_return (invoke "check" (i32.const 0)) (f64.const 0x1.4222222222222p+2)) 35 | (assert_return (invoke "check" (i32.const 8)) (f64.const 0x1.4444444444444p+2)) 36 | (assert_return (invoke "check" (i32.const 16)) (f64.const 0x1.4666666666667p+2)) 37 | (assert_return (invoke "check" (i32.const 24)) (f64.const 0x1.4888888888889p+2)) 38 | 39 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/float_memory0.wast: -------------------------------------------------------------------------------- 1 | ;; Test that floating-point load and store are bit-preserving. 2 | 3 | ;; Test that load and store do not canonicalize NaNs as x87 does. 4 | 5 | (module 6 | (memory 0 0) 7 | (memory 0 0) 8 | (memory 0 0) 9 | (memory $m (data "\00\00\a0\7f")) 10 | (memory 0 0) 11 | (memory 0 0) 12 | 13 | (func (export "f32.load") (result f32) (f32.load $m (i32.const 0))) 14 | (func (export "i32.load") (result i32) (i32.load $m (i32.const 0))) 15 | (func (export "f32.store") (f32.store $m (i32.const 0) (f32.const nan:0x200000))) 16 | (func (export "i32.store") (i32.store $m (i32.const 0) (i32.const 0x7fa00000))) 17 | (func (export "reset") (i32.store $m (i32.const 0) (i32.const 0))) 18 | ) 19 | 20 | (assert_return (invoke "i32.load") (i32.const 0x7fa00000)) 21 | (assert_return (invoke "f32.load") (f32.const nan:0x200000)) 22 | (invoke "reset") 23 | (assert_return (invoke "i32.load") (i32.const 0x0)) 24 | (assert_return (invoke "f32.load") (f32.const 0.0)) 25 | (invoke "f32.store") 26 | (assert_return (invoke "i32.load") (i32.const 0x7fa00000)) 27 | (assert_return (invoke "f32.load") (f32.const nan:0x200000)) 28 | (invoke "reset") 29 | (assert_return (invoke "i32.load") (i32.const 0x0)) 30 | (assert_return (invoke "f32.load") (f32.const 0.0)) 31 | (invoke "i32.store") 32 | (assert_return (invoke "i32.load") (i32.const 0x7fa00000)) 33 | (assert_return (invoke "f32.load") (f32.const nan:0x200000)) 34 | 35 | (module 36 | (memory 0 0) 37 | (memory $m (data "\00\00\00\00\00\00\f4\7f")) 38 | 39 | (func (export "f64.load") (result f64) (f64.load $m (i32.const 0))) 40 | (func (export "i64.load") (result i64) (i64.load $m (i32.const 0))) 41 | (func (export "f64.store") (f64.store $m (i32.const 0) (f64.const nan:0x4000000000000))) 42 | (func (export "i64.store") (i64.store $m (i32.const 0) (i64.const 0x7ff4000000000000))) 43 | (func (export "reset") (i64.store $m (i32.const 0) (i64.const 0))) 44 | ) 45 | 46 | (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000)) 47 | (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000)) 48 | (invoke "reset") 49 | (assert_return (invoke "i64.load") (i64.const 0x0)) 50 | (assert_return (invoke "f64.load") (f64.const 0.0)) 51 | (invoke "f64.store") 52 | (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000)) 53 | (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000)) 54 | (invoke "reset") 55 | (assert_return (invoke "i64.load") (i64.const 0x0)) 56 | (assert_return (invoke "f64.load") (f64.const 0.0)) 57 | (invoke "i64.store") 58 | (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000)) 59 | (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000)) 60 | 61 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/imports0.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "func")) 3 | (func (export "func-i32") (param i32)) 4 | (func (export "func-f32") (param f32)) 5 | (func (export "func->i32") (result i32) (i32.const 22)) 6 | (func (export "func->f32") (result f32) (f32.const 11)) 7 | (func (export "func-i32->i32") (param i32) (result i32) (local.get 0)) 8 | (func (export "func-i64->i64") (param i64) (result i64) (local.get 0)) 9 | (global (export "global-i32") i32 (i32.const 55)) 10 | (global (export "global-f32") f32 (f32.const 44)) 11 | (global (export "global-mut-i64") (mut i64) (i64.const 66)) 12 | (table (export "table-10-inf") 10 funcref) 13 | (table (export "table-10-20") 10 20 funcref) 14 | (memory (export "memory-2-inf") 2) 15 | (memory (export "memory-2-4") 2 4) 16 | ) 17 | 18 | (register "test") 19 | 20 | (assert_unlinkable 21 | (module (import "test" "memory-2-inf" (func))) 22 | "incompatible import type" 23 | ) 24 | (assert_unlinkable 25 | (module (import "test" "memory-2-4" (func))) 26 | "incompatible import type" 27 | ) 28 | 29 | (assert_unlinkable 30 | (module (import "test" "memory-2-inf" (global i32))) 31 | "incompatible import type" 32 | ) 33 | (assert_unlinkable 34 | (module (import "test" "memory-2-4" (global i32))) 35 | "incompatible import type" 36 | ) 37 | 38 | (assert_unlinkable 39 | (module (import "test" "memory-2-inf" (table 10 funcref))) 40 | "incompatible import type" 41 | ) 42 | (assert_unlinkable 43 | (module (import "test" "memory-2-4" (table 10 funcref))) 44 | "incompatible import type" 45 | ) 46 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/imports1.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "spectest" "memory" (memory 1 2)) 3 | (import "spectest" "memory" (memory 1 2)) 4 | (memory $m (import "spectest" "memory") 1 2) 5 | (import "spectest" "memory" (memory 1 2)) 6 | 7 | (data (memory 2) (i32.const 10) "\10") 8 | 9 | (func (export "load") (param i32) (result i32) (i32.load $m (local.get 0))) 10 | ) 11 | 12 | (assert_return (invoke "load" (i32.const 0)) (i32.const 0)) 13 | (assert_return (invoke "load" (i32.const 10)) (i32.const 16)) 14 | (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000)) 15 | (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access") 16 | 17 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/imports2.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory (export "z") 0 0) 3 | (memory (export "memory-2-inf") 2) 4 | (memory (export "memory-2-4") 2 4) 5 | ) 6 | 7 | (register "test") 8 | 9 | (module 10 | (import "test" "z" (memory 0)) 11 | (memory $m (import "spectest" "memory") 1 2) 12 | (data (memory 1) (i32.const 10) "\10") 13 | 14 | (func (export "load") (param i32) (result i32) (i32.load $m (local.get 0))) 15 | ) 16 | 17 | (assert_return (invoke "load" (i32.const 0)) (i32.const 0)) 18 | (assert_return (invoke "load" (i32.const 10)) (i32.const 16)) 19 | (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000)) 20 | (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access") 21 | 22 | (module 23 | (memory (import "spectest" "memory") 1 2) 24 | (data (memory 0) (i32.const 10) "\10") 25 | 26 | (func (export "load") (param i32) (result i32) (i32.load (local.get 0))) 27 | ) 28 | (assert_return (invoke "load" (i32.const 0)) (i32.const 0)) 29 | (assert_return (invoke "load" (i32.const 10)) (i32.const 16)) 30 | (assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000)) 31 | (assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access") 32 | 33 | (module 34 | (import "test" "memory-2-inf" (memory 2)) 35 | (import "test" "memory-2-inf" (memory 1)) 36 | (import "test" "memory-2-inf" (memory 0)) 37 | ) 38 | 39 | (module 40 | (import "spectest" "memory" (memory 1)) 41 | (import "spectest" "memory" (memory 0)) 42 | (import "spectest" "memory" (memory 1 2)) 43 | (import "spectest" "memory" (memory 0 2)) 44 | (import "spectest" "memory" (memory 1 3)) 45 | (import "spectest" "memory" (memory 0 3)) 46 | ) 47 | 48 | (assert_unlinkable 49 | (module (import "test" "unknown" (memory 1))) 50 | "unknown import" 51 | ) 52 | (assert_unlinkable 53 | (module (import "spectest" "unknown" (memory 1))) 54 | "unknown import" 55 | ) 56 | 57 | (assert_unlinkable 58 | (module (import "test" "memory-2-inf" (memory 3))) 59 | "incompatible import type" 60 | ) 61 | (assert_unlinkable 62 | (module (import "test" "memory-2-inf" (memory 2 3))) 63 | "incompatible import type" 64 | ) 65 | (assert_unlinkable 66 | (module (import "spectest" "memory" (memory 2))) 67 | "incompatible import type" 68 | ) 69 | (assert_unlinkable 70 | (module (import "spectest" "memory" (memory 1 1))) 71 | "incompatible import type" 72 | ) 73 | 74 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/imports3.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "func")) 3 | (func (export "func-i32") (param i32)) 4 | (func (export "func-f32") (param f32)) 5 | (func (export "func->i32") (result i32) (i32.const 22)) 6 | (func (export "func->f32") (result f32) (f32.const 11)) 7 | (func (export "func-i32->i32") (param i32) (result i32) (local.get 0)) 8 | (func (export "func-i64->i64") (param i64) (result i64) (local.get 0)) 9 | (global (export "global-i32") i32 (i32.const 55)) 10 | (global (export "global-f32") f32 (f32.const 44)) 11 | (global (export "global-mut-i64") (mut i64) (i64.const 66)) 12 | (table (export "table-10-inf") 10 funcref) 13 | (table (export "table-10-20") 10 20 funcref) 14 | (memory (export "memory-2-inf") 2) 15 | (memory (export "memory-2-4") 2 4) 16 | ) 17 | 18 | (register "test") 19 | (assert_unlinkable 20 | (module 21 | (import "test" "memory-2-4" (memory 1)) 22 | (import "test" "func-i32" (memory 1)) 23 | ) 24 | "incompatible import type" 25 | ) 26 | (assert_unlinkable 27 | (module 28 | (import "test" "memory-2-4" (memory 1)) 29 | (import "test" "global-i32" (memory 1)) 30 | ) 31 | "incompatible import type" 32 | ) 33 | (assert_unlinkable 34 | (module 35 | (import "test" "memory-2-4" (memory 1)) 36 | (import "test" "table-10-inf" (memory 1)) 37 | ) 38 | "incompatible import type" 39 | ) 40 | (assert_unlinkable 41 | (module 42 | (import "test" "memory-2-4" (memory 1)) 43 | (import "spectest" "print_i32" (memory 1)) 44 | ) 45 | "incompatible import type" 46 | ) 47 | (assert_unlinkable 48 | (module 49 | (import "test" "memory-2-4" (memory 1)) 50 | (import "spectest" "global_i32" (memory 1)) 51 | ) 52 | "incompatible import type" 53 | ) 54 | (assert_unlinkable 55 | (module 56 | (import "test" "memory-2-4" (memory 1)) 57 | (import "spectest" "table" (memory 1)) 58 | ) 59 | "incompatible import type" 60 | ) 61 | 62 | (assert_unlinkable 63 | (module 64 | (import "test" "memory-2-4" (memory 1)) 65 | (import "spectest" "memory" (memory 2)) 66 | ) 67 | "incompatible import type" 68 | ) 69 | (assert_unlinkable 70 | (module 71 | (import "test" "memory-2-4" (memory 1)) 72 | (import "spectest" "memory" (memory 1 1)) 73 | ) 74 | "incompatible import type" 75 | ) 76 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/imports4.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory (export "memory-2-inf") 2) 3 | (memory (export "memory-2-4") 2 4) 4 | ) 5 | 6 | (register "test") 7 | 8 | (module 9 | (import "test" "memory-2-4" (memory 1)) 10 | (memory $m (import "spectest" "memory") 0 3) ;; actual has max size 2 11 | (func (export "grow") (param i32) (result i32) (memory.grow $m (local.get 0))) 12 | ) 13 | (assert_return (invoke "grow" (i32.const 0)) (i32.const 1)) 14 | (assert_return (invoke "grow" (i32.const 1)) (i32.const 1)) 15 | (assert_return (invoke "grow" (i32.const 0)) (i32.const 2)) 16 | (assert_return (invoke "grow" (i32.const 1)) (i32.const -1)) 17 | (assert_return (invoke "grow" (i32.const 0)) (i32.const 2)) 18 | 19 | (module $Mgm 20 | (memory 0) 21 | (memory 0) 22 | (memory $m (export "memory") 1) ;; initial size is 1 23 | (func (export "grow") (result i32) (memory.grow $m (i32.const 1))) 24 | ) 25 | (register "grown-memory" $Mgm) 26 | (assert_return (invoke $Mgm "grow") (i32.const 1)) ;; now size is 2 27 | 28 | (module $Mgim1 29 | ;; imported memory limits should match, because external memory size is 2 now 30 | (import "test" "memory-2-4" (memory 1)) 31 | (memory $m (export "memory") (import "grown-memory" "memory") 2) 32 | (memory 0) 33 | (memory 0) 34 | (func (export "grow") (result i32) (memory.grow $m (i32.const 1))) 35 | ) 36 | (register "grown-imported-memory" $Mgim1) 37 | (assert_return (invoke $Mgim1 "grow") (i32.const 2)) ;; now size is 3 38 | 39 | (module $Mgim2 40 | ;; imported memory limits should match, because external memory size is 3 now 41 | (import "test" "memory-2-4" (memory 1)) 42 | (memory $m (import "grown-imported-memory" "memory") 3) 43 | (memory 0) 44 | (memory 0) 45 | (func (export "size") (result i32) (memory.size $m)) 46 | ) 47 | (assert_return (invoke $Mgim2 "size") (i32.const 3)) 48 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/linking0.wast: -------------------------------------------------------------------------------- 1 | (module $Mt 2 | (type (func (result i32))) 3 | (type (func)) 4 | 5 | (table (export "tab") 10 funcref) 6 | (elem (i32.const 2) $g $g $g $g) 7 | (func $g (result i32) (i32.const 4)) 8 | (func (export "h") (result i32) (i32.const -4)) 9 | 10 | (func (export "call") (param i32) (result i32) 11 | (call_indirect (type 0) (local.get 0)) 12 | ) 13 | ) 14 | (register "Mt" $Mt) 15 | 16 | (assert_unlinkable 17 | (module 18 | (table (import "Mt" "tab") 10 funcref) 19 | (memory (import "spectest" "memory") 1) 20 | (memory (import "Mt" "mem") 1) ;; does not exist 21 | (func $f (result i32) (i32.const 0)) 22 | (elem (i32.const 7) $f) 23 | (elem (i32.const 9) $f) 24 | ) 25 | "unknown import" 26 | ) 27 | (assert_trap (invoke $Mt "call" (i32.const 7)) "uninitialized element") 28 | 29 | 30 | (assert_trap 31 | (module 32 | (table (import "Mt" "tab") 10 funcref) 33 | (func $f (result i32) (i32.const 0)) 34 | (elem (i32.const 7) $f) 35 | (memory 0) 36 | (memory $m 1) 37 | (memory 0) 38 | (data $m (i32.const 0x10000) "d") ;; out of bounds 39 | ) 40 | "out of bounds memory access" 41 | ) 42 | (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0)) 43 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/linking1.wast: -------------------------------------------------------------------------------- 1 | (module $Mm 2 | (memory $mem0 (export "mem0") 0 0) 3 | (memory $mem1 (export "mem1") 1 5) 4 | (memory $mem2 (export "mem2") 0 0) 5 | 6 | (data (memory 1) (i32.const 10) "\00\01\02\03\04\05\06\07\08\09") 7 | 8 | (func (export "load") (param $a i32) (result i32) 9 | (i32.load8_u $mem1 (local.get 0)) 10 | ) 11 | ) 12 | (register "Mm" $Mm) 13 | 14 | (module $Nm 15 | (func $loadM (import "Mm" "load") (param i32) (result i32)) 16 | (memory (import "Mm" "mem0") 0) 17 | 18 | (memory $m 1) 19 | (data (memory 1) (i32.const 10) "\f0\f1\f2\f3\f4\f5") 20 | 21 | (export "Mm.load" (func $loadM)) 22 | (func (export "load") (param $a i32) (result i32) 23 | (i32.load8_u $m (local.get 0)) 24 | ) 25 | ) 26 | 27 | (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 2)) 28 | (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 2)) 29 | (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2)) 30 | 31 | (module $Om 32 | (memory (import "Mm" "mem1") 1) 33 | (data (i32.const 5) "\a0\a1\a2\a3\a4\a5\a6\a7") 34 | 35 | (func (export "load") (param $a i32) (result i32) 36 | (i32.load8_u (local.get 0)) 37 | ) 38 | ) 39 | 40 | (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 0xa7)) 41 | (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 0xa7)) 42 | (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2)) 43 | (assert_return (invoke $Om "load" (i32.const 12)) (i32.const 0xa7)) 44 | 45 | (module 46 | (memory (import "Mm" "mem1") 0) 47 | (data (i32.const 0xffff) "a") 48 | ) 49 | 50 | (assert_trap 51 | (module 52 | (memory (import "Mm" "mem0") 0) 53 | (data (i32.const 0xffff) "a") 54 | ) 55 | "out of bounds memory access" 56 | ) 57 | 58 | (assert_trap 59 | (module 60 | (memory (import "Mm" "mem1") 0) 61 | (data (i32.const 0x10000) "a") 62 | ) 63 | "out of bounds memory access" 64 | ) 65 | 66 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/linking2.wast: -------------------------------------------------------------------------------- 1 | (module $Mm 2 | (memory $mem0 (export "mem0") 0 0) 3 | (memory $mem1 (export "mem1") 1 5) 4 | (memory $mem2 (export "mem2") 0 0) 5 | 6 | (data (memory 1) (i32.const 10) "\00\01\02\03\04\05\06\07\08\09") 7 | 8 | (func (export "load") (param $a i32) (result i32) 9 | (i32.load8_u $mem1 (local.get 0)) 10 | ) 11 | ) 12 | (register "Mm" $Mm) 13 | 14 | (module $Pm 15 | (memory (import "Mm" "mem1") 1 8) 16 | 17 | (func (export "grow") (param $a i32) (result i32) 18 | (memory.grow (local.get 0)) 19 | ) 20 | ) 21 | 22 | (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 1)) 23 | (assert_return (invoke $Pm "grow" (i32.const 2)) (i32.const 1)) 24 | (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 3)) 25 | (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const 3)) 26 | (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const 4)) 27 | (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) 28 | (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const -1)) 29 | (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) 30 | 31 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/linking3.wast: -------------------------------------------------------------------------------- 1 | (module $Mm 2 | (memory $mem0 (export "mem0") 0 0) 3 | (memory $mem1 (export "mem1") 5 5) 4 | (memory $mem2 (export "mem2") 0 0) 5 | 6 | (data (memory 1) (i32.const 10) "\00\01\02\03\04\05\06\07\08\09") 7 | 8 | (func (export "load") (param $a i32) (result i32) 9 | (i32.load8_u $mem1 (local.get 0)) 10 | ) 11 | ) 12 | (register "Mm" $Mm) 13 | 14 | (assert_unlinkable 15 | (module 16 | (func $host (import "spectest" "print")) 17 | (memory (import "Mm" "mem1") 1) 18 | (table (import "Mm" "tab") 0 funcref) ;; does not exist 19 | (data (i32.const 0) "abc") 20 | ) 21 | "unknown import" 22 | ) 23 | (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 0)) 24 | 25 | ;; Unlike in v1 spec, active data segments written before an 26 | ;; out-of-bounds access persist after the instantiation failure. 27 | (assert_trap 28 | (module 29 | ;; Note: the memory is 5 pages large by the time we get here. 30 | (memory (import "Mm" "mem1") 1) 31 | (data (i32.const 0) "abc") 32 | (data (i32.const 327670) "zzzzzzzzzzzzzzzzzz") ;; (partially) out of bounds 33 | ) 34 | "out of bounds memory access" 35 | ) 36 | (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) 37 | (assert_return (invoke $Mm "load" (i32.const 327670)) (i32.const 0)) 38 | 39 | (assert_trap 40 | (module 41 | (memory (import "Mm" "mem1") 1) 42 | (data (i32.const 0) "abc") 43 | (table 0 funcref) 44 | (func) 45 | (elem (i32.const 0) 0) ;; out of bounds 46 | ) 47 | "out of bounds table access" 48 | ) 49 | (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) 50 | 51 | ;; Store is modified if the start function traps. 52 | (module $Ms 53 | (type $t (func (result i32))) 54 | (memory (export "memory") 1) 55 | (table (export "table") 1 funcref) 56 | (func (export "get memory[0]") (type $t) 57 | (i32.load8_u (i32.const 0)) 58 | ) 59 | (func (export "get table[0]") (type $t) 60 | (call_indirect (type $t) (i32.const 0)) 61 | ) 62 | ) 63 | (register "Ms" $Ms) 64 | 65 | (assert_trap 66 | (module 67 | (import "Ms" "memory" (memory 1)) 68 | (import "Ms" "table" (table 1 funcref)) 69 | (data (i32.const 0) "hello") 70 | (elem (i32.const 0) $f) 71 | (func $f (result i32) 72 | (i32.const 0xdead) 73 | ) 74 | (func $main 75 | (unreachable) 76 | ) 77 | (start $main) 78 | ) 79 | "unreachable" 80 | ) 81 | 82 | (assert_return (invoke $Ms "get memory[0]") (i32.const 104)) ;; 'h' 83 | (assert_return (invoke $Ms "get table[0]") (i32.const 0xdead)) 84 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/load0.wast: -------------------------------------------------------------------------------- 1 | ;; Multiple memories 2 | 3 | (module 4 | (memory $mem1 1) 5 | (memory $mem2 1) 6 | 7 | (func (export "load1") (param i32) (result i64) 8 | (i64.load $mem1 (local.get 0)) 9 | ) 10 | (func (export "load2") (param i32) (result i64) 11 | (i64.load $mem2 (local.get 0)) 12 | ) 13 | 14 | (data (memory $mem1) (i32.const 0) "\01") 15 | (data (memory $mem2) (i32.const 0) "\02") 16 | ) 17 | 18 | (assert_return (invoke "load1" (i32.const 0)) (i64.const 1)) 19 | (assert_return (invoke "load2" (i32.const 0)) (i64.const 2)) 20 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/load1.wast: -------------------------------------------------------------------------------- 1 | (module $M 2 | (memory (export "mem") 2) 3 | 4 | (func (export "read") (param i32) (result i32) 5 | (i32.load8_u (local.get 0)) 6 | ) 7 | ) 8 | (register "M") 9 | 10 | (module 11 | (memory $mem1 (import "M" "mem") 2) 12 | (memory $mem2 3) 13 | 14 | (data (memory $mem1) (i32.const 20) "\01\02\03\04\05") 15 | (data (memory $mem2) (i32.const 50) "\0A\0B\0C\0D\0E") 16 | 17 | (func (export "read1") (param i32) (result i32) 18 | (i32.load8_u $mem1 (local.get 0)) 19 | ) 20 | (func (export "read2") (param i32) (result i32) 21 | (i32.load8_u $mem2 (local.get 0)) 22 | ) 23 | ) 24 | 25 | (assert_return (invoke $M "read" (i32.const 20)) (i32.const 1)) 26 | (assert_return (invoke $M "read" (i32.const 21)) (i32.const 2)) 27 | (assert_return (invoke $M "read" (i32.const 22)) (i32.const 3)) 28 | (assert_return (invoke $M "read" (i32.const 23)) (i32.const 4)) 29 | (assert_return (invoke $M "read" (i32.const 24)) (i32.const 5)) 30 | 31 | (assert_return (invoke "read1" (i32.const 20)) (i32.const 1)) 32 | (assert_return (invoke "read1" (i32.const 21)) (i32.const 2)) 33 | (assert_return (invoke "read1" (i32.const 22)) (i32.const 3)) 34 | (assert_return (invoke "read1" (i32.const 23)) (i32.const 4)) 35 | (assert_return (invoke "read1" (i32.const 24)) (i32.const 5)) 36 | 37 | (assert_return (invoke "read2" (i32.const 50)) (i32.const 10)) 38 | (assert_return (invoke "read2" (i32.const 51)) (i32.const 11)) 39 | (assert_return (invoke "read2" (i32.const 52)) (i32.const 12)) 40 | (assert_return (invoke "read2" (i32.const 53)) (i32.const 13)) 41 | (assert_return (invoke "read2" (i32.const 54)) (i32.const 14)) 42 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_copy1.wast: -------------------------------------------------------------------------------- 1 | ;; test memory.copy across different memories. 2 | (module 3 | (memory $mem0 (data "\ff\11\44\ee")) 4 | (memory $mem1 (data "\ee\22\55\ff")) 5 | (memory $mem2 (data "\dd\33\66\00")) 6 | (memory $mem3 (data "\aa\bb\cc\dd")) 7 | 8 | (func (export "copy") (param i32 i32 i32) 9 | (memory.copy $mem0 $mem3 10 | (local.get 0) 11 | (local.get 1) 12 | (local.get 2))) 13 | 14 | (func (export "load8_u") (param i32) (result i32) 15 | (i32.load8_u $mem0 (local.get 0))) 16 | ) 17 | 18 | ;; Non-overlapping copy. 19 | (invoke "copy" (i32.const 10) (i32.const 0) (i32.const 4)) 20 | 21 | (assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0)) 22 | (assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xaa)) 23 | (assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xbb)) 24 | (assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc)) 25 | (assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd)) 26 | (assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0)) 27 | 28 | ;; Copy ending at memory limit is ok. 29 | (invoke "copy" (i32.const 0xff00) (i32.const 0) (i32.const 0x100)) 30 | (invoke "copy" (i32.const 0xfe00) (i32.const 0xff00) (i32.const 0x100)) 31 | 32 | ;; Succeed when copying 0 bytes at the end of the region. 33 | (invoke "copy" (i32.const 0x10000) (i32.const 0) (i32.const 0)) 34 | (invoke "copy" (i32.const 0) (i32.const 0x10000) (i32.const 0)) 35 | 36 | ;; Copying 0 bytes outside the memory traps. 37 | (assert_trap (invoke "copy" (i32.const 0x10001) (i32.const 0) (i32.const 0)) 38 | "out of bounds memory access") 39 | (assert_trap (invoke "copy" (i32.const 0) (i32.const 0x10001) (i32.const 0)) 40 | "out of bounds memory access") 41 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_fill0.wast: -------------------------------------------------------------------------------- 1 | ;; memory.fill 2 | (module 3 | (memory $mem0 0) 4 | (memory $mem1 0) 5 | (memory $mem2 1) 6 | 7 | (func (export "fill") (param i32 i32 i32) 8 | (memory.fill $mem2 9 | (local.get 0) 10 | (local.get 1) 11 | (local.get 2))) 12 | 13 | (func (export "load8_u") (param i32) (result i32) 14 | (i32.load8_u $mem2 (local.get 0))) 15 | ) 16 | 17 | ;; Basic fill test. 18 | (invoke "fill" (i32.const 1) (i32.const 0xff) (i32.const 3)) 19 | (assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0)) 20 | (assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xff)) 21 | (assert_return (invoke "load8_u" (i32.const 2)) (i32.const 0xff)) 22 | (assert_return (invoke "load8_u" (i32.const 3)) (i32.const 0xff)) 23 | (assert_return (invoke "load8_u" (i32.const 4)) (i32.const 0)) 24 | 25 | ;; Fill value is stored as a byte. 26 | (invoke "fill" (i32.const 0) (i32.const 0xbbaa) (i32.const 2)) 27 | (assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0xaa)) 28 | (assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xaa)) 29 | 30 | ;; Fill all of memory 31 | (invoke "fill" (i32.const 0) (i32.const 0) (i32.const 0x10000)) 32 | 33 | ;; Out-of-bounds writes trap, and nothing is written 34 | (assert_trap (invoke "fill" (i32.const 0xff00) (i32.const 1) (i32.const 0x101)) 35 | "out of bounds memory access") 36 | (assert_return (invoke "load8_u" (i32.const 0xff00)) (i32.const 0)) 37 | (assert_return (invoke "load8_u" (i32.const 0xffff)) (i32.const 0)) 38 | 39 | ;; Succeed when writing 0 bytes at the end of the region. 40 | (invoke "fill" (i32.const 0x10000) (i32.const 0) (i32.const 0)) 41 | 42 | ;; Writing 0 bytes outside the memory traps. 43 | (assert_trap (invoke "fill" (i32.const 0x10001) (i32.const 0) (i32.const 0)) 44 | "out of bounds memory access") 45 | 46 | 47 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_init0.wast: -------------------------------------------------------------------------------- 1 | ;; memory.init 2 | (module 3 | (memory $mem0 0) 4 | (memory $mem1 0) 5 | (memory $mem2 1) 6 | (memory $mem3 0) 7 | (data $mem2 "\aa\bb\cc\dd") 8 | 9 | (func (export "init") (param i32 i32 i32) 10 | (memory.init $mem2 0 11 | (local.get 0) 12 | (local.get 1) 13 | (local.get 2))) 14 | 15 | (func (export "load8_u") (param i32) (result i32) 16 | (i32.load8_u $mem2 (local.get 0))) 17 | ) 18 | 19 | (invoke "init" (i32.const 0) (i32.const 1) (i32.const 2)) 20 | (assert_return (invoke "load8_u" (i32.const 0)) (i32.const 0xbb)) 21 | (assert_return (invoke "load8_u" (i32.const 1)) (i32.const 0xcc)) 22 | (assert_return (invoke "load8_u" (i32.const 2)) (i32.const 0)) 23 | 24 | ;; Init ending at memory limit and segment limit is ok. 25 | (invoke "init" (i32.const 0xfffc) (i32.const 0) (i32.const 4)) 26 | 27 | ;; Out-of-bounds writes trap, and nothing is written. 28 | (assert_trap (invoke "init" (i32.const 0xfffe) (i32.const 0) (i32.const 3)) 29 | "out of bounds memory access") 30 | (assert_return (invoke "load8_u" (i32.const 0xfffe)) (i32.const 0xcc)) 31 | (assert_return (invoke "load8_u" (i32.const 0xffff)) (i32.const 0xdd)) 32 | 33 | ;; Succeed when writing 0 bytes at the end of either region. 34 | (invoke "init" (i32.const 0x10000) (i32.const 0) (i32.const 0)) 35 | (invoke "init" (i32.const 0) (i32.const 4) (i32.const 0)) 36 | 37 | ;; Writing 0 bytes outside the memory traps. 38 | (assert_trap (invoke "init" (i32.const 0x10001) (i32.const 0) (i32.const 0)) 39 | "out of bounds memory access") 40 | (assert_trap (invoke "init" (i32.const 0) (i32.const 5) (i32.const 0)) 41 | "out of bounds memory access") 42 | 43 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_size0.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 0) 3 | (memory 0) 4 | (memory 0) 5 | (memory 0) 6 | (memory $m 0) 7 | 8 | (func (export "size") (result i32) (memory.size $m)) 9 | (func (export "grow") (param $sz i32) (drop (memory.grow $m (local.get $sz)))) 10 | ) 11 | 12 | (assert_return (invoke "size") (i32.const 0)) 13 | (assert_return (invoke "grow" (i32.const 1))) 14 | (assert_return (invoke "size") (i32.const 1)) 15 | (assert_return (invoke "grow" (i32.const 4))) 16 | (assert_return (invoke "size") (i32.const 5)) 17 | (assert_return (invoke "grow" (i32.const 0))) 18 | (assert_return (invoke "size") (i32.const 5)) 19 | 20 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_size1.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 0) 3 | (memory 0) 4 | (memory $n 0) 5 | (memory 0) 6 | (memory $m 0) 7 | 8 | (func (export "size") (result i32) (memory.size $m)) 9 | (func (export "grow") (param $sz i32) (drop (memory.grow $m (local.get $sz)))) 10 | 11 | (func (export "sizen") (result i32) (memory.size $n)) 12 | (func (export "grown") (param $sz i32) (drop (memory.grow $n (local.get $sz)))) 13 | ) 14 | 15 | (assert_return (invoke "size") (i32.const 0)) 16 | (assert_return (invoke "sizen") (i32.const 0)) 17 | (assert_return (invoke "grow" (i32.const 1))) 18 | (assert_return (invoke "size") (i32.const 1)) 19 | (assert_return (invoke "sizen") (i32.const 0)) 20 | (assert_return (invoke "grow" (i32.const 4))) 21 | (assert_return (invoke "size") (i32.const 5)) 22 | (assert_return (invoke "sizen") (i32.const 0)) 23 | (assert_return (invoke "grow" (i32.const 0))) 24 | (assert_return (invoke "size") (i32.const 5)) 25 | (assert_return (invoke "sizen") (i32.const 0)) 26 | 27 | (assert_return (invoke "grown" (i32.const 1))) 28 | (assert_return (invoke "size") (i32.const 5)) 29 | (assert_return (invoke "sizen") (i32.const 1)) 30 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_size2.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 0 0) 3 | (memory 0 0) 4 | (memory $n 0 0) 5 | (memory $m 0 2) 6 | 7 | (func (export "size") (result i32) (memory.size $m)) 8 | (func (export "grow") (param $sz i32) (drop (memory.grow $m (local.get $sz)))) 9 | 10 | (func (export "sizen") (result i32) (memory.size $n)) 11 | (func (export "grown") (param $sz i32) (drop (memory.grow $n (local.get $sz)))) 12 | ) 13 | 14 | (assert_return (invoke "size") (i32.const 0)) 15 | (assert_return (invoke "sizen") (i32.const 0)) 16 | (assert_return (invoke "grow" (i32.const 3))) 17 | (assert_return (invoke "sizen") (i32.const 0)) 18 | (assert_return (invoke "size") (i32.const 0)) 19 | (assert_return (invoke "grow" (i32.const 1))) 20 | (assert_return (invoke "sizen") (i32.const 0)) 21 | (assert_return (invoke "size") (i32.const 1)) 22 | (assert_return (invoke "grow" (i32.const 0))) 23 | (assert_return (invoke "sizen") (i32.const 0)) 24 | (assert_return (invoke "size") (i32.const 1)) 25 | (assert_return (invoke "grow" (i32.const 4))) 26 | (assert_return (invoke "sizen") (i32.const 0)) 27 | (assert_return (invoke "size") (i32.const 1)) 28 | (assert_return (invoke "grow" (i32.const 1))) 29 | (assert_return (invoke "sizen") (i32.const 0)) 30 | (assert_return (invoke "size") (i32.const 2)) 31 | 32 | (assert_return (invoke "grown" (i32.const 1))) 33 | (assert_return (invoke "sizen") (i32.const 0)) 34 | (assert_return (invoke "size") (i32.const 2)) 35 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_size3.wast: -------------------------------------------------------------------------------- 1 | ;; Type errors 2 | 3 | (assert_invalid 4 | (module 5 | (memory 0) 6 | (memory $m 1) 7 | (memory 0) 8 | (func $type-result-i32-vs-empty 9 | (memory.size $m) 10 | ) 11 | ) 12 | "type mismatch" 13 | ) 14 | (assert_invalid 15 | (module 16 | (memory 0) 17 | (memory 0) 18 | (memory 0) 19 | (memory $m 1) 20 | (func $type-result-i32-vs-f32 (result f32) 21 | (memory.size $m) 22 | ) 23 | ) 24 | "type mismatch" 25 | ) 26 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/memory_trap0.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 0) 3 | (memory 0) 4 | (memory $m 1) 5 | 6 | (func $addr_limit (result i32) 7 | (i32.mul (memory.size $m) (i32.const 0x10000)) 8 | ) 9 | 10 | (func (export "store") (param $i i32) (param $v i32) 11 | (i32.store $m (i32.add (call $addr_limit) (local.get $i)) (local.get $v)) 12 | ) 13 | 14 | (func (export "load") (param $i i32) (result i32) 15 | (i32.load $m (i32.add (call $addr_limit) (local.get $i))) 16 | ) 17 | 18 | (func (export "memory.grow") (param i32) (result i32) 19 | (memory.grow $m (local.get 0)) 20 | ) 21 | ) 22 | 23 | (assert_return (invoke "store" (i32.const -4) (i32.const 42))) 24 | (assert_return (invoke "load" (i32.const -4)) (i32.const 42)) 25 | (assert_trap (invoke "store" (i32.const -3) (i32.const 0x12345678)) "out of bounds memory access") 26 | (assert_trap (invoke "load" (i32.const -3)) "out of bounds memory access") 27 | (assert_trap (invoke "store" (i32.const -2) (i32.const 13)) "out of bounds memory access") 28 | (assert_trap (invoke "load" (i32.const -2)) "out of bounds memory access") 29 | (assert_trap (invoke "store" (i32.const -1) (i32.const 13)) "out of bounds memory access") 30 | (assert_trap (invoke "load" (i32.const -1)) "out of bounds memory access") 31 | (assert_trap (invoke "store" (i32.const 0) (i32.const 13)) "out of bounds memory access") 32 | (assert_trap (invoke "load" (i32.const 0)) "out of bounds memory access") 33 | (assert_trap (invoke "store" (i32.const 0x80000000) (i32.const 13)) "out of bounds memory access") 34 | (assert_trap (invoke "load" (i32.const 0x80000000)) "out of bounds memory access") 35 | (assert_return (invoke "memory.grow" (i32.const 0x10001)) (i32.const -1)) 36 | 37 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/start0.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 0) 3 | (memory $m (data "A")) 4 | (memory $n 1) 5 | 6 | (func $inc 7 | (i32.store8 $m 8 | (i32.const 0) 9 | (i32.add 10 | (i32.load8_u $m (i32.const 0)) 11 | (i32.const 1) 12 | ) 13 | ) 14 | ) 15 | (func $get (result i32) 16 | (return (i32.load8_u $m (i32.const 0))) 17 | ) 18 | (func $getn (result i32) 19 | (return (i32.load8_u $n (i32.const 0))) 20 | ) 21 | (func $main 22 | (call $inc) 23 | (call $inc) 24 | (call $inc) 25 | ) 26 | 27 | (start $main) 28 | (export "inc" (func $inc)) 29 | (export "get" (func $get)) 30 | (export "getn" (func $getn)) 31 | ) 32 | (assert_return (invoke "get") (i32.const 68)) 33 | (assert_return (invoke "getn") (i32.const 0)) 34 | 35 | (invoke "inc") 36 | (assert_return (invoke "get") (i32.const 69)) 37 | (assert_return (invoke "getn") (i32.const 0)) 38 | 39 | (invoke "inc") 40 | (assert_return (invoke "get") (i32.const 70)) 41 | (assert_return (invoke "getn") (i32.const 0)) 42 | 43 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/store0.wast: -------------------------------------------------------------------------------- 1 | ;; Multiple memories 2 | 3 | (module 4 | (memory $mem1 1) 5 | (memory $mem2 1) 6 | 7 | (func (export "load1") (param i32) (result i64) 8 | (i64.load $mem1 (local.get 0)) 9 | ) 10 | (func (export "load2") (param i32) (result i64) 11 | (i64.load $mem2 (local.get 0)) 12 | ) 13 | 14 | (func (export "store1") (param i32 i64) 15 | (i64.store $mem1 (local.get 0) (local.get 1)) 16 | ) 17 | (func (export "store2") (param i32 i64) 18 | (i64.store $mem2 (local.get 0) (local.get 1)) 19 | ) 20 | ) 21 | 22 | (invoke "store1" (i32.const 0) (i64.const 1)) 23 | (invoke "store2" (i32.const 0) (i64.const 2)) 24 | (assert_return (invoke "load1" (i32.const 0)) (i64.const 1)) 25 | (assert_return (invoke "load2" (i32.const 0)) (i64.const 2)) 26 | -------------------------------------------------------------------------------- /test/wasm-spec/core/multi-memory/store1.wast: -------------------------------------------------------------------------------- 1 | (module $M1 2 | (memory (export "mem") 1) 3 | 4 | (func (export "load") (param i32) (result i64) 5 | (i64.load (local.get 0)) 6 | ) 7 | (func (export "store") (param i32 i64) 8 | (i64.store (local.get 0) (local.get 1)) 9 | ) 10 | ) 11 | (register "M1") 12 | 13 | (module $M2 14 | (memory (export "mem") 1) 15 | 16 | (func (export "load") (param i32) (result i64) 17 | (i64.load (local.get 0)) 18 | ) 19 | (func (export "store") (param i32 i64) 20 | (i64.store (local.get 0) (local.get 1)) 21 | ) 22 | ) 23 | (register "M2") 24 | 25 | (invoke $M1 "store" (i32.const 0) (i64.const 1)) 26 | (invoke $M2 "store" (i32.const 0) (i64.const 2)) 27 | (assert_return (invoke $M1 "load" (i32.const 0)) (i64.const 1)) 28 | (assert_return (invoke $M2 "load" (i32.const 0)) (i64.const 2)) 29 | 30 | (module 31 | (memory $mem1 (import "M1" "mem") 1) 32 | (memory $mem2 (import "M2" "mem") 1) 33 | 34 | (func (export "load1") (param i32) (result i64) 35 | (i64.load $mem1 (local.get 0)) 36 | ) 37 | (func (export "load2") (param i32) (result i64) 38 | (i64.load $mem2 (local.get 0)) 39 | ) 40 | 41 | (func (export "store1") (param i32 i64) 42 | (i64.store $mem1 (local.get 0) (local.get 1)) 43 | ) 44 | (func (export "store2") (param i32 i64) 45 | (i64.store $mem2 (local.get 0) (local.get 1)) 46 | ) 47 | ) 48 | 49 | (invoke "store1" (i32.const 0) (i64.const 1)) 50 | (invoke "store2" (i32.const 0) (i64.const 2)) 51 | (assert_return (invoke "load1" (i32.const 0)) (i64.const 1)) 52 | (assert_return (invoke "load2" (i32.const 0)) (i64.const 2)) 53 | -------------------------------------------------------------------------------- /test/wasm-spec/core/ref_is_null.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $f1 (export "funcref") (param $x funcref) (result i32) 3 | (ref.is_null (local.get $x)) 4 | ) 5 | (func $f2 (export "externref") (param $x externref) (result i32) 6 | (ref.is_null (local.get $x)) 7 | ) 8 | 9 | (table $t1 2 funcref) 10 | (table $t2 2 externref) 11 | (elem (table $t1) (i32.const 1) func $dummy) 12 | (func $dummy) 13 | 14 | (func (export "init") (param $r externref) 15 | (table.set $t2 (i32.const 1) (local.get $r)) 16 | ) 17 | (func (export "deinit") 18 | (table.set $t1 (i32.const 1) (ref.null func)) 19 | (table.set $t2 (i32.const 1) (ref.null extern)) 20 | ) 21 | 22 | (func (export "funcref-elem") (param $x i32) (result i32) 23 | (call $f1 (table.get $t1 (local.get $x))) 24 | ) 25 | (func (export "externref-elem") (param $x i32) (result i32) 26 | (call $f2 (table.get $t2 (local.get $x))) 27 | ) 28 | ) 29 | 30 | (assert_return (invoke "funcref" (ref.null func)) (i32.const 1)) 31 | (assert_return (invoke "externref" (ref.null extern)) (i32.const 1)) 32 | 33 | (assert_return (invoke "externref" (ref.extern 1)) (i32.const 0)) 34 | 35 | (invoke "init" (ref.extern 0)) 36 | 37 | (assert_return (invoke "funcref-elem" (i32.const 0)) (i32.const 1)) 38 | (assert_return (invoke "externref-elem" (i32.const 0)) (i32.const 1)) 39 | 40 | (assert_return (invoke "funcref-elem" (i32.const 1)) (i32.const 0)) 41 | (assert_return (invoke "externref-elem" (i32.const 1)) (i32.const 0)) 42 | 43 | (invoke "deinit") 44 | 45 | (assert_return (invoke "funcref-elem" (i32.const 0)) (i32.const 1)) 46 | (assert_return (invoke "externref-elem" (i32.const 0)) (i32.const 1)) 47 | 48 | (assert_return (invoke "funcref-elem" (i32.const 1)) (i32.const 1)) 49 | (assert_return (invoke "externref-elem" (i32.const 1)) (i32.const 1)) 50 | 51 | (assert_invalid 52 | (module (func $ref-vs-num (param i32) (ref.is_null (local.get 0)))) 53 | "type mismatch" 54 | ) 55 | (assert_invalid 56 | (module (func $ref-vs-empty (ref.is_null))) 57 | "type mismatch" 58 | ) 59 | -------------------------------------------------------------------------------- /test/wasm-spec/core/ref_null.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "externref") (result externref) (ref.null extern)) 3 | (func (export "funcref") (result funcref) (ref.null func)) 4 | 5 | (global externref (ref.null extern)) 6 | (global funcref (ref.null func)) 7 | ) 8 | 9 | (assert_return (invoke "externref") (ref.null extern)) 10 | (assert_return (invoke "funcref") (ref.null func)) 11 | -------------------------------------------------------------------------------- /test/wasm-spec/core/simd/simd_linking.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (global (export "g-v128") v128 (v128.const i64x2 0 0)) 3 | (global (export "mg-v128") (mut v128) (v128.const i64x2 0 0)) 4 | ) 5 | (register "Mv128") 6 | 7 | (module 8 | ;; TODO: Reactivate once the fix for https://bugs.chromium.org/p/v8/issues/detail?id=13732 9 | ;; has made it to the downstream node.js that we use on CI. 10 | ;; (import "Mv128" "g-v128" (global v128)) 11 | (import "Mv128" "mg-v128" (global (mut v128))) 12 | ) 13 | -------------------------------------------------------------------------------- /test/wasm-spec/core/start.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module (func) (start 1)) 3 | "unknown function" 4 | ) 5 | 6 | (assert_invalid 7 | (module 8 | (func $main (result i32) (return (i32.const 0))) 9 | (start $main) 10 | ) 11 | "start function" 12 | ) 13 | (assert_invalid 14 | (module 15 | (func $main (param $a i32)) 16 | (start $main) 17 | ) 18 | "start function" 19 | ) 20 | 21 | (module 22 | (memory (data "A")) 23 | (func $inc 24 | (i32.store8 25 | (i32.const 0) 26 | (i32.add 27 | (i32.load8_u (i32.const 0)) 28 | (i32.const 1) 29 | ) 30 | ) 31 | ) 32 | (func $get (result i32) 33 | (return (i32.load8_u (i32.const 0))) 34 | ) 35 | (func $main 36 | (call $inc) 37 | (call $inc) 38 | (call $inc) 39 | ) 40 | 41 | (start $main) 42 | (export "inc" (func $inc)) 43 | (export "get" (func $get)) 44 | ) 45 | (assert_return (invoke "get") (i32.const 68)) 46 | (invoke "inc") 47 | (assert_return (invoke "get") (i32.const 69)) 48 | (invoke "inc") 49 | (assert_return (invoke "get") (i32.const 70)) 50 | 51 | (module 52 | (memory (data "A")) 53 | (func $inc 54 | (i32.store8 55 | (i32.const 0) 56 | (i32.add 57 | (i32.load8_u (i32.const 0)) 58 | (i32.const 1) 59 | ) 60 | ) 61 | ) 62 | (func $get (result i32) 63 | (return (i32.load8_u (i32.const 0))) 64 | ) 65 | (func $main 66 | (call $inc) 67 | (call $inc) 68 | (call $inc) 69 | ) 70 | (start 2) 71 | (export "inc" (func $inc)) 72 | (export "get" (func $get)) 73 | ) 74 | (assert_return (invoke "get") (i32.const 68)) 75 | (invoke "inc") 76 | (assert_return (invoke "get") (i32.const 69)) 77 | (invoke "inc") 78 | (assert_return (invoke "get") (i32.const 70)) 79 | 80 | (module 81 | (func $print_i32 (import "spectest" "print_i32") (param i32)) 82 | (func $main (call $print_i32 (i32.const 1))) 83 | (start 1) 84 | ) 85 | 86 | (module 87 | (func $print_i32 (import "spectest" "print_i32") (param i32)) 88 | (func $main (call $print_i32 (i32.const 2))) 89 | (start $main) 90 | ) 91 | 92 | (module 93 | (func $print (import "spectest" "print")) 94 | (start $print) 95 | ) 96 | 97 | (assert_trap 98 | (module (func $main (unreachable)) (start $main)) 99 | "unreachable" 100 | ) 101 | 102 | (assert_malformed 103 | (module quote "(module (func $a (unreachable)) (func $b (unreachable)) (start $a) (start $b))") 104 | "multiple start sections" 105 | ) 106 | -------------------------------------------------------------------------------- /test/wasm-spec/core/table-sub.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module 3 | (table $t1 10 funcref) 4 | (table $t2 10 externref) 5 | (func $f 6 | (table.copy $t1 $t2 (i32.const 0) (i32.const 1) (i32.const 2)) 7 | ) 8 | ) 9 | "type mismatch" 10 | ) 11 | 12 | (assert_invalid 13 | (module 14 | (table $t 10 funcref) 15 | (elem $el externref) 16 | (func $f 17 | (table.init $t $el (i32.const 0) (i32.const 1) (i32.const 2)) 18 | ) 19 | ) 20 | "type mismatch" 21 | ) 22 | -------------------------------------------------------------------------------- /test/wasm-spec/core/table.wast: -------------------------------------------------------------------------------- 1 | ;; Test table section structure 2 | 3 | (module (table 0 funcref)) 4 | (module (table 1 funcref)) 5 | (module (table 0 0 funcref)) 6 | (module (table 0 1 funcref)) 7 | (module (table 1 256 funcref)) 8 | (module (table 0 65536 funcref)) 9 | (module (table 0 0xffff_ffff funcref)) 10 | 11 | (module (table 0 funcref) (table 0 funcref)) 12 | (module (table (import "spectest" "table") 0 funcref) (table 0 funcref)) 13 | 14 | (assert_invalid (module (elem (i32.const 0))) "unknown table") 15 | (assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table") 16 | 17 | 18 | (assert_invalid 19 | (module (table 1 0 funcref)) 20 | "size minimum must not be greater than maximum" 21 | ) 22 | (assert_invalid 23 | (module (table 0xffff_ffff 0 funcref)) 24 | "size minimum must not be greater than maximum" 25 | ) 26 | 27 | (assert_malformed 28 | (module quote "(table 0x1_0000_0000 funcref)") 29 | "i32 constant out of range" 30 | ) 31 | (assert_malformed 32 | (module quote "(table 0x1_0000_0000 0x1_0000_0000 funcref)") 33 | "i32 constant out of range" 34 | ) 35 | (assert_malformed 36 | (module quote "(table 0 0x1_0000_0000 funcref)") 37 | "i32 constant out of range" 38 | ) 39 | 40 | 41 | ;; Duplicate table identifiers 42 | 43 | (assert_malformed (module quote 44 | "(table $foo 1 funcref)" 45 | "(table $foo 1 funcref)") 46 | "duplicate table") 47 | (assert_malformed (module quote 48 | "(import \"\" \"\" (table $foo 1 funcref))" 49 | "(table $foo 1 funcref)") 50 | "duplicate table") 51 | (assert_malformed (module quote 52 | "(import \"\" \"\" (table $foo 1 funcref))" 53 | "(import \"\" \"\" (table $foo 1 funcref))") 54 | "duplicate table") 55 | -------------------------------------------------------------------------------- /test/wasm-spec/core/table_get.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (table $t2 2 externref) 3 | (table $t3 3 funcref) 4 | (elem (table $t3) (i32.const 1) func $dummy) 5 | (func $dummy) 6 | 7 | (func (export "init") (param $r externref) 8 | (table.set $t2 (i32.const 1) (local.get $r)) 9 | (table.set $t3 (i32.const 2) (table.get $t3 (i32.const 1))) 10 | ) 11 | 12 | (func (export "get-externref") (param $i i32) (result externref) 13 | (table.get (local.get $i)) 14 | ) 15 | (func $f3 (export "get-funcref") (param $i i32) (result funcref) 16 | (table.get $t3 (local.get $i)) 17 | ) 18 | 19 | (func (export "is_null-funcref") (param $i i32) (result i32) 20 | (ref.is_null (call $f3 (local.get $i))) 21 | ) 22 | ) 23 | 24 | (invoke "init" (ref.extern 1)) 25 | 26 | (assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern)) 27 | (assert_return (invoke "get-externref" (i32.const 1)) (ref.extern 1)) 28 | 29 | (assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) 30 | (assert_return (invoke "is_null-funcref" (i32.const 1)) (i32.const 0)) 31 | (assert_return (invoke "is_null-funcref" (i32.const 2)) (i32.const 0)) 32 | 33 | (assert_trap (invoke "get-externref" (i32.const 2)) "out of bounds table access") 34 | (assert_trap (invoke "get-funcref" (i32.const 3)) "out of bounds table access") 35 | (assert_trap (invoke "get-externref" (i32.const -1)) "out of bounds table access") 36 | (assert_trap (invoke "get-funcref" (i32.const -1)) "out of bounds table access") 37 | 38 | 39 | ;; Type errors 40 | 41 | (assert_invalid 42 | (module 43 | (table $t 10 externref) 44 | (func $type-index-empty-vs-i32 (result externref) 45 | (table.get $t) 46 | ) 47 | ) 48 | "type mismatch" 49 | ) 50 | (assert_invalid 51 | (module 52 | (table $t 10 externref) 53 | (func $type-index-f32-vs-i32 (result externref) 54 | (table.get $t (f32.const 1)) 55 | ) 56 | ) 57 | "type mismatch" 58 | ) 59 | 60 | (assert_invalid 61 | (module 62 | (table $t 10 externref) 63 | (func $type-result-externref-vs-empty 64 | (table.get $t (i32.const 0)) 65 | ) 66 | ) 67 | "type mismatch" 68 | ) 69 | (assert_invalid 70 | (module 71 | (table $t 10 externref) 72 | (func $type-result-externref-vs-funcref (result funcref) 73 | (table.get $t (i32.const 1)) 74 | ) 75 | ) 76 | "type mismatch" 77 | ) 78 | 79 | (assert_invalid 80 | (module 81 | (table $t1 1 funcref) 82 | (table $t2 1 externref) 83 | (func $type-result-externref-vs-funcref-multi (result funcref) 84 | (table.get $t2 (i32.const 0)) 85 | ) 86 | ) 87 | "type mismatch" 88 | ) 89 | -------------------------------------------------------------------------------- /test/wasm-spec/core/token.wast: -------------------------------------------------------------------------------- 1 | ;; Test tokenization 2 | 3 | (assert_malformed 4 | (module quote "(func (drop (i32.const0)))") 5 | "unknown operator" 6 | ) 7 | (assert_malformed 8 | (module quote "(func br 0drop)") 9 | "unknown operator" 10 | ) 11 | -------------------------------------------------------------------------------- /test/wasm-spec/core/type.wast: -------------------------------------------------------------------------------- 1 | ;; Test type definitions 2 | 3 | (module 4 | (type (func)) 5 | (type $t (func)) 6 | 7 | (type (func (param i32))) 8 | (type (func (param $x i32))) 9 | (type (func (result i32))) 10 | (type (func (param i32) (result i32))) 11 | (type (func (param $x i32) (result i32))) 12 | 13 | (type (func (param f32 f64))) 14 | (type (func (result i64 f32))) 15 | (type (func (param i32 i64) (result f32 f64))) 16 | 17 | (type (func (param f32) (param f64))) 18 | (type (func (param $x f32) (param f64))) 19 | (type (func (param f32) (param $y f64))) 20 | (type (func (param $x f32) (param $y f64))) 21 | (type (func (result i64) (result f32))) 22 | (type (func (param i32) (param i64) (result f32) (result f64))) 23 | (type (func (param $x i32) (param $y i64) (result f32) (result f64))) 24 | 25 | (type (func (param f32 f64) (param $x i32) (param f64 i32 i32))) 26 | (type (func (result i64 i64 f32) (result f32 i32))) 27 | (type 28 | (func (param i32 i32) (param i64 i32) (result f32 f64) (result f64 i32)) 29 | ) 30 | 31 | (type (func (param) (param $x f32) (param) (param) (param f64 i32) (param))) 32 | (type 33 | (func (result) (result) (result i64 i64) (result) (result f32) (result)) 34 | ) 35 | (type 36 | (func 37 | (param i32 i32) (param i64 i32) (param) (param $x i32) (param) 38 | (result) (result f32 f64) (result f64 i32) (result) 39 | ) 40 | ) 41 | ) 42 | 43 | (assert_malformed 44 | (module quote "(type (func (result i32) (param i32)))") 45 | "unexpected token" 46 | ) 47 | (assert_malformed 48 | (module quote "(type (func (result $x i32)))") 49 | "unexpected token" 50 | ) 51 | -------------------------------------------------------------------------------- /test/wasm-spec/core/unreached-valid.wast: -------------------------------------------------------------------------------- 1 | (module 2 | 3 | ;; Check that both sides of the select are evaluated 4 | (func (export "select-trap-left") (param $cond i32) (result i32) 5 | (select (unreachable) (i32.const 0) (local.get $cond)) 6 | ) 7 | (func (export "select-trap-right") (param $cond i32) (result i32) 8 | (select (i32.const 0) (unreachable) (local.get $cond)) 9 | ) 10 | 11 | (func (export "select-unreached") 12 | (unreachable) (select) 13 | (unreachable) (i32.const 0) (select) 14 | (unreachable) (i32.const 0) (i32.const 0) (select) 15 | (unreachable) (i32.const 0) (i32.const 0) (i32.const 0) (select) 16 | (unreachable) (f32.const 0) (i32.const 0) (select) 17 | (unreachable) 18 | ) 19 | 20 | (func (export "select_unreached_result_1") (result i32) 21 | (unreachable) (i32.add (select)) 22 | ) 23 | 24 | (func (export "select_unreached_result_2") (result i64) 25 | (unreachable) (i64.add (select (i64.const 0) (i32.const 0))) 26 | ) 27 | 28 | (func (export "unreachable-num") 29 | (unreachable) 30 | (select) 31 | (i32.eqz) 32 | (drop) 33 | ) 34 | (func (export "unreachable-ref") 35 | (unreachable) 36 | (select) 37 | (ref.is_null) 38 | (drop) 39 | ) 40 | ) 41 | 42 | (assert_trap (invoke "select-trap-left" (i32.const 1)) "unreachable") 43 | (assert_trap (invoke "select-trap-left" (i32.const 0)) "unreachable") 44 | (assert_trap (invoke "select-trap-right" (i32.const 1)) "unreachable") 45 | (assert_trap (invoke "select-trap-right" (i32.const 0)) "unreachable") 46 | 47 | ;; Validation after unreachable 48 | 49 | (module 50 | (func (export "meet-bottom") 51 | (block (result f64) 52 | (block (result f32) 53 | (unreachable) 54 | (br_table 0 1 1 (i32.const 1)) 55 | ) 56 | (drop) 57 | (f64.const 0) 58 | ) 59 | (drop) 60 | ) 61 | ) 62 | 63 | (assert_trap (invoke "meet-bottom") "unreachable") 64 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/change.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | uint32_t coins[] = {5, 10, 20, 50, 100, 200}; 21 | 22 | #define COINT_NUMBER sizeof(coins) / sizeof(uint32_t) 23 | #define MONEY 155 24 | 25 | /* 26 | * Return the smallest number of coins 27 | * by with the given money can be paid. 28 | * 29 | * Money shall be changeable with the given coins. 30 | */ 31 | uint32_t change(uint64_t money) { 32 | if (money == 0) { 33 | return 0; 34 | } else { 35 | uint32_t least_coins = UINT32_MAX; 36 | for (int i = 0; i < COINT_NUMBER; i++) { 37 | if (coins[i] > money) { 38 | continue; 39 | } 40 | if (1 + change(money - coins[i]) < least_coins) { 41 | least_coins = 1 + change(money - coins[i]); 42 | } 43 | } 44 | return least_coins; 45 | } 46 | } 47 | 48 | uint32_t runtime() { 49 | return change(MONEY); 50 | } 51 | 52 | int main() { 53 | printf("%u\n", (unsigned int) runtime()); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/factorial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | uint64_t factorial(uint64_t n) { 21 | uint64_t counter = 0; 22 | for (uint64_t i = 0; i < n; i++, counter++) { 23 | factorial(n - 1); 24 | } 25 | 26 | return counter; 27 | } 28 | 29 | uint64_t runtime() { 30 | uint64_t retVal = 0; 31 | 32 | for (uint64_t i = 0; i < 6000000000; i++) { 33 | retVal += factorial(150000000); 34 | retVal -= factorial(149999999); 35 | retVal += factorial(149999998); 36 | } 37 | 38 | return retVal; 39 | } 40 | 41 | int main() { 42 | printf("%llu\n", (long long unsigned int) runtime()); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/fibonacci.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | uint64_t fibonacci(uint64_t n) { 21 | if (n == 0 || n == 1) { 22 | return n; 23 | } 24 | 25 | 26 | return fibonacci(n - 1) + fibonacci(n - 2); 27 | } 28 | 29 | uint64_t runtime() { 30 | return fibonacci(39); 31 | } 32 | 33 | int main() { 34 | printf("%llu\n", (long long unsigned int) runtime()); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/gregory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | double gregorySeries(uint64_t n) { 21 | double sum = 0; 22 | 23 | for (uint64_t i = 0; i < n; i++) { 24 | sum += (i % 2 == 0 ? 1 : -1) * (1.0 / (2 * i + 1)); 25 | } 26 | 27 | return sum * 4; 28 | } 29 | 30 | double runtime() { 31 | return gregorySeries(300000000); 32 | } 33 | 34 | int main() { 35 | printf("%.8lf\n", runtime()); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/include/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RANDOM_H 18 | #define RANDOM_H 19 | 20 | // constants for the random number generator 21 | #define m 65535 22 | #define a 33278 23 | #define c 1256 24 | #define seed 55682 25 | 26 | /** 27 | * Generate random number according to 28 | * the linear congruential generator (LCG). 29 | * 30 | * Xˇ(n+1) = (a * Xˇ(n) + c) mod m 31 | * 32 | * where: 33 | * - 0 < m 34 | * - 0 < a < m 35 | * - 0 <= c < m 36 | * - 0 <= Xˇ(0) <= m 37 | */ 38 | unsigned int random() { 39 | static unsigned int previous = seed; 40 | previous = (a * previous + c) % m; 41 | return previous; 42 | } 43 | 44 | #endif // RANDOM_H 45 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/mandelbrotDouble.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define FLOAT_SIZE 8 18 | #include "include/mandelbrot.h" 19 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/mandelbrotFloat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define FLOAT_SIZE 4 18 | #include "include/mandelbrot.h" 19 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/prime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #define EXIT_SUCCESS 0 22 | #define EXIT_FAILURE 1 23 | 24 | #define PRIME_NUMBER 7000 25 | 26 | 27 | // return the greatest x, where x^2 <= number 28 | uint64_t whole_sqrt(uint64_t number) { 29 | uint64_t root = 0; 30 | while ((root + 1) * (root + 1) <= number) { 31 | root += 1; 32 | } 33 | return root; 34 | } 35 | 36 | uint64_t getPrime(uint64_t sequence_number) { 37 | // there is no 0th prime number 38 | if (sequence_number == 0) { 39 | return 0; 40 | } 41 | 42 | uint64_t prime = 2; 43 | for (uint64_t i = 1; i < sequence_number; i++) { 44 | uint64_t current_number = prime; 45 | while (true) { 46 | // check for overflow 47 | if (current_number == UINT64_MAX) { 48 | return 0; 49 | } 50 | current_number += 1; 51 | bool is_prime = true; 52 | for (uint64_t j = 2; j <= whole_sqrt(current_number); j++) { 53 | if (current_number % j == 0) { 54 | is_prime = false; 55 | break; 56 | } 57 | } 58 | if (is_prime) { 59 | break; 60 | } 61 | } 62 | prime = current_number; 63 | } 64 | 65 | return prime; 66 | } 67 | 68 | uint64_t runtime() { 69 | return getPrime(PRIME_NUMBER); 70 | } 71 | 72 | int main() { 73 | printf("%llu\n", (long long unsigned int) runtime()); 74 | return EXIT_SUCCESS; 75 | } 76 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/simdMandelbrotDouble.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define FLOAT_SIZE 8 18 | #include "include/simdMandelbrot.h" 19 | -------------------------------------------------------------------------------- /test/wasmBenchmarker/ctests/simdMandelbrotFloat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-present Samsung Electronics Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define FLOAT_SIZE 4 18 | #include "include/simdMandelbrot.h" 19 | -------------------------------------------------------------------------------- /third_party/wabt/Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to WebAssembly 2 | 3 | Interested in participating? Please follow 4 | [the same contributing guidelines as the design repository][]. 5 | 6 | [the same contributing guidelines as the design repository]: https://github.com/WebAssembly/design/blob/master/Contributing.md 7 | 8 | Also, please be sure to read [the README.md](README.md) for this repository. 9 | -------------------------------------------------------------------------------- /third_party/wabt/include/string-view-lite/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/base-types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_BASE_TYPES_H_ 18 | #define WABT_BASE_TYPES_H_ 19 | 20 | #include 21 | #include 22 | 23 | namespace wabt { 24 | 25 | using Index = uint32_t; // An index into one of the many index spaces. 26 | using Address = uint64_t; // An address or size in linear memory. 27 | using Offset = size_t; // An offset into a host's file or memory buffer. 28 | 29 | constexpr Address kInvalidAddress = ~0; 30 | constexpr Index kInvalidIndex = ~0; 31 | constexpr Offset kInvalidOffset = ~0; 32 | 33 | } // namespace wabt 34 | 35 | #endif // WABT_BASE_TYPES_H_ 36 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/binary-reader-ir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_BINARY_READER_IR_H_ 18 | #define WABT_BINARY_READER_IR_H_ 19 | 20 | #include "wabt/common.h" 21 | #include "wabt/error.h" 22 | 23 | namespace wabt { 24 | 25 | struct Module; 26 | struct ReadBinaryOptions; 27 | 28 | Result ReadBinaryIr(const char* filename, 29 | const void* data, 30 | size_t size, 31 | const ReadBinaryOptions& options, 32 | Errors*, 33 | Module* out_module); 34 | 35 | } // namespace wabt 36 | 37 | #endif /* WABT_BINARY_READER_IR_H_ */ 38 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/binary-writer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_BINARY_WRITER_H_ 18 | #define WABT_BINARY_WRITER_H_ 19 | 20 | #include "wabt/common.h" 21 | #include "wabt/feature.h" 22 | #include "wabt/opcode.h" 23 | #include "wabt/stream.h" 24 | 25 | namespace wabt { 26 | 27 | struct Module; 28 | struct Script; 29 | 30 | struct WriteBinaryOptions { 31 | WriteBinaryOptions() = default; 32 | WriteBinaryOptions(const Features& features, 33 | bool canonicalize_lebs, 34 | bool relocatable, 35 | bool write_debug_names) 36 | : features(features), 37 | canonicalize_lebs(canonicalize_lebs), 38 | relocatable(relocatable), 39 | write_debug_names(write_debug_names) {} 40 | 41 | Features features; 42 | bool canonicalize_lebs = true; 43 | bool relocatable = false; 44 | bool write_debug_names = false; 45 | }; 46 | 47 | Result WriteBinaryModule(Stream*, const Module*, const WriteBinaryOptions&); 48 | 49 | void WriteType(Stream* stream, Type type, const char* desc = nullptr); 50 | 51 | void WriteStr(Stream* stream, 52 | nonstd::string_view s, 53 | const char* desc, 54 | PrintChars print_chars = PrintChars::No); 55 | 56 | void WriteOpcode(Stream* stream, Opcode opcode); 57 | 58 | void WriteLimits(Stream* stream, const Limits* limits); 59 | 60 | } // namespace wabt 61 | 62 | #endif /* WABT_BINARY_WRITER_H_ */ 63 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/binding-hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_BINDING_HASH_H_ 18 | #define WABT_BINDING_HASH_H_ 19 | 20 | #include 21 | #include 22 | #include "string-view-lite/string_view.h" 23 | #include 24 | #include 25 | 26 | #include "wabt/common.h" 27 | 28 | namespace wabt { 29 | 30 | struct Var; 31 | 32 | struct Binding { 33 | explicit Binding(Index index) : index(index) {} 34 | Binding(const Location& loc, Index index) : loc(loc), index(index) {} 35 | 36 | Location loc; 37 | Index index; 38 | }; 39 | 40 | // This class derives from a C++ container, which is usually not advisable 41 | // because they don't have virtual destructors. So don't delete a BindingHash 42 | // object through a pointer to std::unordered_multimap. 43 | class BindingHash : public std::unordered_multimap { 44 | public: 45 | using DuplicateCallback = 46 | std::function; 47 | 48 | void FindDuplicates(DuplicateCallback callback) const; 49 | 50 | Index FindIndex(const Var&) const; 51 | 52 | Index FindIndex(const std::string& name) const { 53 | auto iter = find(name); 54 | return iter != end() ? iter->second.index : kInvalidIndex; 55 | } 56 | 57 | Index FindIndex(nonstd::string_view name) const { 58 | return FindIndex(std::string(name)); 59 | } 60 | 61 | private: 62 | using ValueTypeVector = std::vector; 63 | 64 | void CreateDuplicatesVector(ValueTypeVector* out_duplicates) const; 65 | void SortDuplicatesVectorByLocation(ValueTypeVector* duplicates) const; 66 | void CallCallbacks(const ValueTypeVector& duplicates, 67 | DuplicateCallback callback) const; 68 | }; 69 | 70 | } // namespace wabt 71 | 72 | #endif /* WABT_BINDING_HASH_H_ */ 73 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_ERROR_H_ 18 | #define WABT_ERROR_H_ 19 | 20 | #include 21 | #include "string-view-lite/string_view.h" 22 | #include 23 | 24 | #include "wabt/common.h" 25 | 26 | namespace wabt { 27 | 28 | enum class ErrorLevel { 29 | Warning, 30 | Error, 31 | }; 32 | 33 | static inline const char* GetErrorLevelName(ErrorLevel error_level) { 34 | switch (error_level) { 35 | case ErrorLevel::Warning: 36 | return "warning"; 37 | case ErrorLevel::Error: 38 | return "error"; 39 | } 40 | WABT_UNREACHABLE; 41 | } 42 | 43 | class Error { 44 | public: 45 | Error() : error_level(ErrorLevel::Error) {} 46 | Error(ErrorLevel error_level, Location loc, nonstd::string_view message) 47 | : error_level(error_level), loc(loc), message(message) {} 48 | 49 | ErrorLevel error_level; 50 | Location loc; 51 | std::string message; 52 | }; 53 | 54 | using Errors = std::vector; 55 | 56 | } // namespace wabt 57 | 58 | #endif // WABT_ERROR_H_ 59 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/feature.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_FEATURE 18 | #error "You must define WABT_FEATURE before including this file." 19 | #endif 20 | 21 | /* 22 | * variable flag default help 23 | * ========================================================================= */ 24 | 25 | WABT_FEATURE(exceptions, "exceptions", false, "Experimental exception handling") 26 | WABT_FEATURE(mutable_globals, "mutable-globals", true, "Import/export mutable globals") 27 | WABT_FEATURE(sat_float_to_int, "saturating-float-to-int", true, "Saturating float-to-int operators") 28 | WABT_FEATURE(sign_extension, "sign-extension", true, "Sign-extension operators") 29 | WABT_FEATURE(simd, "simd", true, "SIMD support") 30 | WABT_FEATURE(threads, "threads", false, "Threading support") 31 | WABT_FEATURE(function_references, "function-references", false, "Typed function references") 32 | WABT_FEATURE(multi_value, "multi-value", true, "Multi-value") 33 | WABT_FEATURE(tail_call, "tail-call", false, "Tail-call support") 34 | WABT_FEATURE(bulk_memory, "bulk-memory", true, "Bulk-memory operations") 35 | WABT_FEATURE(reference_types, "reference-types", true, "Reference types (externref)") 36 | WABT_FEATURE(annotations, "annotations", false, "Custom annotation syntax") 37 | WABT_FEATURE(code_metadata, "code-metadata", false, "Code metadata") 38 | WABT_FEATURE(gc, "gc", false, "Garbage collection") 39 | WABT_FEATURE(memory64, "memory64", false, "64-bit memory") 40 | WABT_FEATURE(multi_memory, "multi-memory", false, "Multi-memory") 41 | WABT_FEATURE(extended_const, "extended-const", false, "Extended constant expressions") 42 | WABT_FEATURE(relaxed_simd, "relaxed-simd", false, "Relaxed SIMD") 43 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/feature.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_FEATURE_H_ 18 | #define WABT_FEATURE_H_ 19 | 20 | #include "wabt/common.h" 21 | 22 | namespace wabt { 23 | 24 | class OptionParser; 25 | 26 | class Features { 27 | public: 28 | void AddOptions(OptionParser*); 29 | 30 | void EnableAll() { 31 | #define WABT_FEATURE(variable, flag, default_, help) enable_##variable(); 32 | #include "wabt/feature.def" 33 | #undef WABT_FEATURE 34 | } 35 | 36 | #define WABT_FEATURE(variable, flag, default_, help) \ 37 | bool variable##_enabled() const { return variable##_enabled_; } \ 38 | void enable_##variable() { set_##variable##_enabled(true); } \ 39 | void disable_##variable() { set_##variable##_enabled(false); } \ 40 | void set_##variable##_enabled(bool value) { \ 41 | variable##_enabled_ = value; \ 42 | UpdateDependencies(); \ 43 | } 44 | #include "wabt/feature.def" 45 | #undef WABT_FEATURE 46 | 47 | private: 48 | void UpdateDependencies(); 49 | 50 | #define WABT_FEATURE(variable, flag, default_, help) \ 51 | bool variable##_enabled_ = default_; 52 | #include "wabt/feature.def" 53 | #undef WABT_FEATURE 54 | }; 55 | 56 | } // namespace wabt 57 | 58 | #endif // WABT_FEATURE_H_ 59 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/lexer-source-line-finder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_LEXER_SOURCE_LINE_FINDER_H_ 18 | #define WABT_LEXER_SOURCE_LINE_FINDER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "wabt/common.h" 25 | #include "wabt/lexer-source.h" 26 | #include "wabt/range.h" 27 | 28 | namespace wabt { 29 | 30 | class LexerSourceLineFinder { 31 | public: 32 | struct SourceLine { 33 | std::string line; 34 | int column_offset; 35 | }; 36 | 37 | explicit LexerSourceLineFinder(std::unique_ptr); 38 | 39 | Result GetSourceLine(const Location& loc, 40 | Offset max_line_length, 41 | SourceLine* out_source_line); 42 | Result GetLineOffsets(int line, OffsetRange* out_offsets); 43 | 44 | private: 45 | static OffsetRange ClampSourceLineOffsets(OffsetRange line_offset_range, 46 | ColumnRange column_range, 47 | Offset max_line_length); 48 | 49 | bool IsLineCached(int line) const; 50 | OffsetRange GetCachedLine(int line) const; 51 | 52 | std::unique_ptr source_; 53 | std::vector line_ranges_; 54 | Offset next_line_start_; 55 | bool last_cr_; // Last read character was a '\r' (carriage return). 56 | bool eof_; 57 | }; 58 | 59 | } // namespace wabt 60 | 61 | #endif // WABT_LEXER_SOURCE_LINE_FINDER_H_ 62 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/lexer-source.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_LEXER_SOURCE_H_ 18 | #define WABT_LEXER_SOURCE_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "wabt/common.h" 26 | #include "wabt/range.h" 27 | 28 | namespace wabt { 29 | 30 | class LexerSource { 31 | public: 32 | LexerSource(const void* data, Offset size); 33 | 34 | std::unique_ptr Clone(); 35 | Result Tell(Offset* out_offset); 36 | size_t Fill(void* dest, size_t size); 37 | Result ReadRange(OffsetRange, std::vector* out_data); 38 | Result Seek(Offset offset); 39 | 40 | WABT_DISALLOW_COPY_AND_ASSIGN(LexerSource); 41 | 42 | const void* data() { return data_; } 43 | Offset size() { return size_; } 44 | 45 | private: 46 | const void* data_; 47 | Offset size_; 48 | Offset read_offset_; 49 | }; 50 | 51 | } // namespace wabt 52 | 53 | #endif // WABT_LEXER_SOURCE_H_ 54 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/make-unique.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_MAKE_UNIQUE_H_ 18 | #define WABT_MAKE_UNIQUE_H_ 19 | 20 | #include 21 | 22 | namespace wabt { 23 | 24 | // This is named MakeUnique instead of make_unique because make_unique has the 25 | // potential to conflict with std::make_unique if it is defined. 26 | // 27 | // On gcc/clang, we currently compile with c++11, which doesn't define 28 | // std::make_unique, but on MSVC the newest C++ version is always used, which 29 | // includes std::make_unique. If an argument from the std namespace is used, it 30 | // will cause ADL to find std::make_unique, and an unqualified call to 31 | // make_unique will be ambiguous. We can work around this by fully qualifying 32 | // the call (i.e. wabt::make_unique), but it's simpler to just use a different 33 | // name. It's also more consistent with other names in the wabt namespace, 34 | // which use CamelCase. 35 | template 36 | std::unique_ptr MakeUnique(Args&&... args) { 37 | return std::unique_ptr(new T(std::forward(args)...)); 38 | } 39 | 40 | } // namespace wabt 41 | 42 | #endif // WABT_MAKE_UNIQUE_H_ 43 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/opcode-code-table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_OPCODE_CODE_TABLE_H_ 18 | #define WABT_OPCODE_CODE_TABLE_H_ 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #define WABT_OPCODE_CODE_TABLE_SIZE 131072 28 | 29 | /* 30 | * Number of bits required to store an opcode 31 | */ 32 | #define MAX_OPCODE_BITS 9 33 | 34 | /* This structure is defined in C because C++ doesn't (yet) allow you to use 35 | * designated array initializers, i.e. [10] = {foo}. 36 | */ 37 | extern uint32_t WabtOpcodeCodeTable[WABT_OPCODE_CODE_TABLE_SIZE]; 38 | 39 | #ifdef __cplusplus 40 | } /* extern "C" */ 41 | #endif 42 | 43 | #endif /* WABT_OPCODE_CODE_TABLE_H_ */ 44 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/range.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_RANGE_H_ 18 | #define WABT_RANGE_H_ 19 | 20 | namespace wabt { 21 | 22 | template 23 | struct Range { 24 | Range() : start(0), end(0) {} 25 | Range(T start, T end) : start(start), end(end) {} 26 | T start; 27 | T end; 28 | 29 | T size() const { return end - start; } 30 | }; 31 | 32 | using OffsetRange = Range; 33 | using ColumnRange = Range; 34 | 35 | } // namespace wabt 36 | 37 | #endif // WABT_RANGE_H_ 38 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/resolve-names.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_RESOLVE_NAMES_H_ 18 | #define WABT_RESOLVE_NAMES_H_ 19 | 20 | #include "wabt/common.h" 21 | #include "wabt/error.h" 22 | 23 | namespace wabt { 24 | 25 | struct Module; 26 | struct Script; 27 | 28 | Result ResolveNamesModule(Module*, Errors*); 29 | Result ResolveNamesScript(Script*, Errors*); 30 | 31 | } // namespace wabt 32 | 33 | #endif /* WABT_RESOLVE_NAMES_H_ */ 34 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_RESULT_H_ 18 | #define WABT_RESULT_H_ 19 | 20 | namespace wabt { 21 | 22 | struct Result { 23 | enum Enum { 24 | Ok, 25 | Error, 26 | }; 27 | 28 | Result() : Result(Ok) {} 29 | Result(Enum e) : enum_(e) {} 30 | operator Enum() const { return enum_; } 31 | Result& operator|=(Result rhs); 32 | 33 | private: 34 | Enum enum_; 35 | }; 36 | 37 | inline Result operator|(Result lhs, Result rhs) { 38 | return (lhs == Result::Error || rhs == Result::Error) ? Result::Error 39 | : Result::Ok; 40 | } 41 | 42 | inline Result& Result::operator|=(Result rhs) { 43 | enum_ = *this | rhs; 44 | return *this; 45 | } 46 | 47 | inline bool Succeeded(Result result) { 48 | return result == Result::Ok; 49 | } 50 | inline bool Failed(Result result) { 51 | return result == Result::Error; 52 | } 53 | 54 | #define CHECK_RESULT(expr) \ 55 | do { \ 56 | if (Failed(expr)) { \ 57 | return ::wabt::Result::Error; \ 58 | } \ 59 | } while (0) 60 | 61 | } // namespace wabt 62 | 63 | #endif // WABT_RESULT_H_ 64 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/tracing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_TRACING_H_ 18 | #define WABT_TRACING_H_ 19 | 20 | // Provides a simple tracing class that automatically generates enter/exit 21 | // messages using the scope of the instance. 22 | // 23 | // It also assumes that this file is only included in .cc files. 24 | // Immediately before the inclusion of this file, there is a define of 25 | // for WABT_TRACING, defining whether tracing should be compiled in for 26 | // that source file. 27 | 28 | #ifndef WABT_TRACING 29 | #define WABT_TRACING 0 30 | #endif 31 | 32 | #include "wabt/common.h" 33 | 34 | namespace wabt { 35 | 36 | #if WABT_TRACING 37 | 38 | // Scoped class that automatically prints enter("->") and exit("<-") 39 | // lines, indented by trace level. 40 | struct TraceScope { 41 | WABT_DISALLOW_COPY_AND_ASSIGN(TraceScope); 42 | TraceScope() = delete; 43 | TraceScope(const char* method); 44 | template 45 | TraceScope(const char* method, const char* format, Args&&... args) 46 | : method_(method) { 47 | PrintEnter(method); 48 | fprintf(stderr, format, std::forward(args)...); 49 | PrintNewline(); 50 | } 51 | ~TraceScope(); 52 | 53 | private: 54 | const char* method_; 55 | void PrintEnter(const char* method); 56 | void PrintNewline(); 57 | }; 58 | 59 | #define WABT_TRACE(method_name) TraceScope _func_(#method_name) 60 | 61 | #define WABT_TRACE_ARGS(method_name, format, ...) \ 62 | TraceScope _func_(#method_name, format, __VA_ARGS__) 63 | 64 | #else 65 | 66 | #define WABT_TRACE(method) 67 | #define WABT_TRACE_ARGS(method_name, format, ...) 68 | 69 | #endif 70 | 71 | } // end namespace wabt 72 | 73 | #endif // WABT_TRACING_H_ 74 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/utf8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_UTF8_H_ 18 | #define WABT_UTF8_H_ 19 | 20 | #include 21 | 22 | namespace wabt { 23 | 24 | bool IsValidUtf8(const char* s, size_t length); 25 | 26 | } // namespace wabt 27 | 28 | #endif // WABT_UTF8_H_ 29 | -------------------------------------------------------------------------------- /third_party/wabt/include/wabt/validator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WABT_VALIDATOR_H_ 18 | #define WABT_VALIDATOR_H_ 19 | 20 | #include "wabt/error.h" 21 | #include "wabt/feature.h" 22 | #include "wabt/shared-validator.h" 23 | 24 | namespace wabt { 25 | 26 | struct Module; 27 | struct Script; 28 | 29 | // Perform all checks on the script. It is valid if and only if this function 30 | // succeeds. 31 | Result ValidateScript(const Script*, Errors*, const ValidateOptions&); 32 | Result ValidateModule(const Module*, Errors*, const ValidateOptions&); 33 | 34 | } // namespace wabt 35 | 36 | #endif // WABT_VALIDATOR_H_ 37 | -------------------------------------------------------------------------------- /third_party/wabt/src/binary.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "wabt/binary.h" 18 | 19 | namespace wabt { 20 | 21 | BinarySectionOrder GetSectionOrder(BinarySection sec) { 22 | switch (sec) { 23 | #define V(Name, name, code) \ 24 | case BinarySection::Name: \ 25 | return BinarySectionOrder::Name; 26 | WABT_FOREACH_BINARY_SECTION(V) 27 | #undef V 28 | default: 29 | WABT_UNREACHABLE; 30 | } 31 | } 32 | 33 | const char* GetSectionName(BinarySection sec) { 34 | switch (sec) { 35 | #define V(Name, name, code) \ 36 | case BinarySection::Name: \ 37 | return #Name; 38 | WABT_FOREACH_BINARY_SECTION(V) 39 | #undef V 40 | default: 41 | WABT_UNREACHABLE; 42 | } 43 | } 44 | 45 | // clang-format off 46 | const char* NameSubsectionName[] = { 47 | "module", 48 | "function", 49 | "local", 50 | "label", 51 | "type", 52 | "table", 53 | "memory", 54 | "global", 55 | "elemseg", 56 | "dataseg", 57 | "field", 58 | "tag", 59 | }; 60 | // clang-format on 61 | 62 | const char* GetNameSectionSubsectionName(NameSectionSubsection subsec) { 63 | static_assert(WABT_ENUM_COUNT(NameSectionSubsection) == 64 | WABT_ARRAY_SIZE(NameSubsectionName), 65 | "Malformed ExprTypeName array"); 66 | return NameSubsectionName[size_t(subsec)]; 67 | } 68 | 69 | } // namespace wabt 70 | -------------------------------------------------------------------------------- /third_party/wabt/src/feature.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "wabt/feature.h" 18 | 19 | #include "wabt/option-parser.h" 20 | 21 | namespace wabt { 22 | 23 | void Features::AddOptions(OptionParser* parser) { 24 | #define WABT_FEATURE(variable, flag, default_, help) \ 25 | if (default_ == true) { \ 26 | parser->AddOption("disable-" flag, "Disable " help, \ 27 | [this]() { disable_##variable(); }); \ 28 | } else { \ 29 | parser->AddOption("enable-" flag, "Enable " help, \ 30 | [this]() { enable_##variable(); }); \ 31 | } 32 | 33 | #include "wabt/feature.def" 34 | #undef WABT_FEATURE 35 | parser->AddOption("enable-all", "Enable all features", 36 | [this]() { EnableAll(); }); 37 | } 38 | 39 | void Features::UpdateDependencies() { 40 | // Exception handling requires reference types. 41 | if (exceptions_enabled_) { 42 | reference_types_enabled_ = true; 43 | } 44 | 45 | // Function references require reference types. 46 | if (function_references_enabled_) { 47 | reference_types_enabled_ = true; 48 | } 49 | 50 | // Reference types requires bulk memory. 51 | if (!bulk_memory_enabled_) { 52 | reference_types_enabled_ = false; 53 | } 54 | } 55 | 56 | } // namespace wabt 57 | -------------------------------------------------------------------------------- /third_party/wabt/src/lexer-source.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "wabt/lexer-source.h" 18 | 19 | #include 20 | 21 | namespace wabt { 22 | 23 | LexerSource::LexerSource(const void* data, Offset size) 24 | : data_(data), size_(size), read_offset_(0) {} 25 | 26 | std::unique_ptr LexerSource::Clone() { 27 | LexerSource* result = new LexerSource(data_, size_); 28 | result->read_offset_ = read_offset_; 29 | return std::unique_ptr(result); 30 | } 31 | 32 | Result LexerSource::Tell(Offset* out_offset) { 33 | *out_offset = read_offset_; 34 | return Result::Ok; 35 | } 36 | 37 | size_t LexerSource::Fill(void* dest, Offset size) { 38 | Offset read_size = std::min(size, size_ - read_offset_); 39 | if (read_size > 0) { 40 | const void* src = static_cast(data_) + read_offset_; 41 | memcpy(dest, src, read_size); 42 | read_offset_ += read_size; 43 | } 44 | return read_size; 45 | } 46 | 47 | Result LexerSource::Seek(Offset offset) { 48 | if (offset < size_) { 49 | read_offset_ = offset; 50 | return Result::Ok; 51 | } 52 | return Result::Error; 53 | } 54 | 55 | Result LexerSource::ReadRange(OffsetRange range, std::vector* out_data) { 56 | OffsetRange clamped = range; 57 | clamped.start = std::min(clamped.start, size_); 58 | clamped.end = std::min(clamped.end, size_); 59 | if (clamped.size()) { 60 | out_data->resize(clamped.size()); 61 | const void* src = static_cast(data_) + clamped.start; 62 | memcpy(out_data->data(), src, clamped.size()); 63 | } 64 | return Result::Ok; 65 | } 66 | 67 | } // namespace wabt 68 | -------------------------------------------------------------------------------- /third_party/wabt/src/opcode-code-table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 WebAssembly Community Group participants 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "wabt/opcode-code-table.h" 18 | 19 | #include "wabt/config.h" 20 | 21 | #include 22 | 23 | typedef enum WabtOpcodeEnum { 24 | #define WABT_OPCODE(rtype, type1, type2, type3, mem_size, prefix, code, Name, \ 25 | text, decomp) \ 26 | Name, 27 | #include "wabt/opcode.def" 28 | #undef WABT_OPCODE 29 | Invalid, 30 | } WabtOpcodeEnum; 31 | 32 | WABT_STATIC_ASSERT(Invalid <= WABT_OPCODE_CODE_TABLE_SIZE); 33 | 34 | /* The array index calculated below must match the one in Opcode::FromCode. */ 35 | uint32_t WabtOpcodeCodeTable[WABT_OPCODE_CODE_TABLE_SIZE] = { 36 | #define WABT_OPCODE(rtype, type1, type2, type3, mem_size, prefix, code, Name, \ 37 | text, decomp) \ 38 | [(prefix << MAX_OPCODE_BITS) + code] = Name, 39 | #include "wabt/opcode.def" 40 | #undef WABT_OPCODE 41 | }; 42 | -------------------------------------------------------------------------------- /third_party/wabt/src/prebuilt/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /third_party/wabt/ubsan.blacklist: -------------------------------------------------------------------------------- 1 | # Work around libstdc++ bug: https://llvm.org/bugs/show_bug.cgi?id=18156 2 | # Also see: http://lists.llvm.org/pipermail/cfe-dev/2015-January/040945.html 3 | src:*/ios_base.h 4 | 5 | # Work around another libstdc++ bug: 6 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60734 7 | src:*/stl_tree.h 8 | 9 | # Work around for libstdc++ 4.8 bug: 10 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59829 11 | src:*/stl_vector.h 12 | src:*/stl_iterator.h 13 | -------------------------------------------------------------------------------- /tools/jit_exclude_list.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samsung/walrus/023b7bd2cc267a5b4e83aeccf263ab5e5dfa7dd3/tools/jit_exclude_list.txt --------------------------------------------------------------------------------