├── test ├── revision ├── unit │ ├── __init__.py │ └── input │ │ ├── empty.wasm │ │ ├── random_data.txt │ │ ├── dwarf │ │ ├── zlib.wasm │ │ └── cubescript.wasm │ │ ├── bulkmem_data.wasm │ │ ├── gc_target_feature.wasm │ │ ├── simd_target_feature.wasm │ │ ├── atomics_target_feature.wasm │ │ ├── bulkmem_bad_datacount.wasm │ │ ├── bulkmem_target_feature.wasm │ │ ├── signext_target_feature.wasm │ │ ├── truncsat_target_feature.wasm │ │ ├── exception_handling_target_feature.wasm │ │ ├── tail_call_target_feature.wasm │ │ ├── mutable_globals_target_feature.wasm │ │ ├── reference_types_target_feature.wasm │ │ ├── asyncify-pure.txt │ │ ├── hello_world.wat │ │ ├── empty_lld.wat │ │ ├── stack_ir.wat │ │ └── asyncify-stackOverflow.wat ├── fannkuch.args ├── fasta.args ├── lit │ ├── wasm-split │ │ ├── none.txt │ │ ├── bar.txt │ │ ├── foo.txt │ │ ├── both.txt │ │ ├── export-name-already-exists.wast │ │ ├── instrument-memory-too-small.wast │ │ ├── verbose.wast │ │ ├── imported-memory.wast │ │ ├── initial-table.wast │ │ └── name-collision.wast │ ├── CMakeLists.txt │ ├── binary │ │ ├── dylink.test.wasm │ │ ├── bad-ref-as.test.wasm │ │ ├── bad-ref-as.test │ │ └── dylink.test │ ├── parse-error.wast │ ├── memory64-limits.wast │ ├── lit.site.cfg.py.in │ ├── parse-bad-tuple-extract-index.wast │ ├── validation │ │ └── shared-memory.wast │ ├── stdin-stdout.wast │ └── passes │ │ └── roundtrip-table.wast ├── lld │ ├── em_asm.wat.mem.mem │ ├── hello_world.wat.mem.mem │ ├── em_asm_pthread.wasm │ ├── shared_add_to_table.wasm │ ├── hello_world.c │ ├── init.c │ ├── em_asm.cpp │ ├── em_asm64.cpp │ ├── em_asm_shared.cpp │ ├── em_asm_O0.c │ ├── shared.cpp │ ├── em_asm_pthread.cpp │ ├── shared_longjmp.c │ ├── longjmp.c │ ├── main_module_table.wat │ ├── recursive.c │ ├── main_module_table_2.wat │ ├── main_module_table_3.wat │ ├── standalone-wasm3.wat │ ├── main_module_table_4.wat │ ├── standalone-wasm-with-start.wat │ ├── main_module_table_5.wat │ ├── em_asm_table.wat │ └── standalone-wasm2.wat ├── metadce │ ├── tag.wast.dced.stdout │ ├── all-outside.wast │ ├── spanning_cycle.wast.dced.stdout │ ├── threaded_cycle.wast.dced.stdout │ ├── all-outside.wast.dced │ ├── no-outside.wast.dced │ ├── threaded_unrooted.wast.dced │ ├── no-outside.wast.graph.txt │ ├── spanning_cycle_unrooted.wast.dced │ ├── threaded_unrooted_cycle.wast.dced │ ├── threaded.wast.dced.stdout │ ├── corners.wast.dced.stdout │ ├── all-outside.wast.dced.stdout │ ├── spanning_cycle_unrooted.wast.dced.stdout │ ├── rooted-export.wast.dced.stdout │ ├── no-outside.wast.dced.stdout │ ├── spanning_cycle_unrooted.wast │ ├── tag.wast.graph.txt │ ├── outside.wast.graph.txt │ ├── outside.wast.dced.stdout │ ├── tag.wast │ ├── rooted-export.wast.graph.txt │ ├── spanning_cycle_unrooted.wast.graph.txt │ ├── rooted-export.wast.dced │ ├── tag.wast.dced │ ├── corners.wast.graph.txt │ ├── no-outside.wast │ ├── spanning_cycle.wast.graph.txt │ ├── spanning_cycle.wast.dced │ ├── threaded_unrooted.wast.dced.stdout │ ├── threaded_unrooted_cycle.wast.dced.stdout │ ├── spanning_cycle.wast │ └── rooted-export.wast ├── binaryen.js │ ├── pass-arguments.js.txt │ ├── copy-expression.js.txt │ ├── tail_calls.js.txt │ ├── fast-math.js.txt │ ├── simd.js.txt │ ├── custom-section.js.txt │ ├── fast-math.js │ ├── inlining-options.js.txt │ ├── expressionrunner.js.txt │ ├── custom-section.js │ ├── simd.js │ ├── validation_errors.js.txt │ ├── sourcemap.js.txt │ ├── emit_asmjs.js │ ├── reloc.js.txt │ ├── tag.js.txt │ ├── pass-arguments.js │ ├── functions.js.txt │ ├── sideffects.js.txt │ ├── global.js.txt │ └── debug-info.js.txt ├── example │ ├── domtree.txt │ ├── hash.txt │ ├── small_set.txt │ ├── small_vector.txt │ ├── space.txt │ ├── local-graph.txt │ ├── c-api-relooper-unreachable-if.txt │ ├── cpp-unit.txt │ ├── cpp-threads.txt │ ├── c-api-hello-world.txt │ ├── stack-utils.txt │ └── match.txt ├── linker │ ├── baz.c │ ├── quux.c │ ├── foo.c │ ├── bar.c │ └── main.c ├── calls.emcc ├── hello_world.txt ├── mem.emcc ├── ctor-eval │ ├── imported3.wast.ctors │ ├── no_partial.wast.ctors │ ├── unsafe_call.wast.ctors │ ├── unsafe_store.wast.ctors │ ├── bad-indirect-call.wast.ctors │ ├── imported.wast.out │ ├── indirect-call3.wast.ctors │ ├── unsafe_store2.wast.ctors │ ├── unsafe_store3.wast.ctors │ ├── bad-indirect-call2.wast.ctors │ ├── basics.wast.ctors │ ├── imported-min.wast.out │ ├── imported.wast.ctors │ ├── imported2.wast.ctors │ ├── just_some.wast.ctors │ ├── stack-direction.wast.out │ ├── unsafe_store.wast.out │ ├── unsafe_store2.wast.out │ ├── unsafe_store3.wast.out │ ├── bad-indirect-call3.wast.ctors │ ├── basics-flatten.wast.ctors │ ├── imported-min.wast.ctors │ ├── stack-direction.wast.ctors │ ├── unsafe_store.wast │ ├── unsafe_store2.wast │ ├── unsafe_store3.wast │ ├── basics.wast.out │ ├── basics-flatten.wast.out │ ├── imported3.wast.out │ ├── no_partial.wast.out │ ├── indirect-call3.wast.out │ ├── just_some.wast.out │ ├── no_partial.wast │ ├── imported3.wast │ ├── unsafe_call.wast │ ├── bad-indirect-call.wast │ ├── imported2.wast.out │ ├── bad-indirect-call.wast.out │ ├── unsafe_call.wast.out │ ├── bad-indirect-call2.wast │ ├── bad-indirect-call3.wast │ ├── bad-indirect-call2.wast.out │ └── indirect-call3.wast ├── float_ops.emcc ├── hello_libcxx.txt ├── int_ops.emcc ├── passes │ ├── multi_unit_abbrev_noprint.bin.txt │ ├── dwarf_unit_with_no_abbrevs_noprint.bin.txt │ ├── safe-heap_start-function.passes │ ├── fib2_dwarf.passes │ ├── inlined_to_start_dwarf.passes │ ├── reverse_dwarf_abbrevs.passes │ ├── class_with_dwarf_noprint.passes │ ├── dwarf_unit_with_no_abbrevs_noprint.passes │ ├── fannkuch0_dwarf.passes │ ├── fannkuch3_dwarf.passes │ ├── fuzz_metrics_noprint.passes │ ├── fib2_emptylocspan_dwarf.passes │ ├── remove-memory.txt │ ├── dwarf_with_exceptions.passes │ ├── fannkuch3_manyopts_dwarf.passes │ ├── multi_unit_abbrev_noprint.passes │ ├── set-globals.passes │ ├── strip-target-features.wasm │ ├── O.wasm │ ├── ignore_missing_func_dwarf.passes │ ├── dwarf-local-order.passes │ ├── multi_line_table_dwarf.passes │ ├── too_much_for_liveness.passes │ ├── print.wasm │ ├── dwarfdump.wasm │ ├── fib_nonzero-low-pc_dwarf.passes │ ├── flatten.wasm │ ├── print_g.wasm │ ├── strip-target-features.bin.txt │ ├── fib2_dwarf.wasm │ ├── strip-debug.wasm │ ├── strip-dwarf.wasm │ ├── fannkuch0_dwarf.wasm │ ├── fannkuch3_dwarf.wasm │ ├── print_g_metrics.wasm │ ├── roundtrip_typenames_features.passes │ ├── safe-heap_enable-threads_enable-simd64.passes │ ├── strip-producers.wasm │ ├── converge_O3_metrics.wasm │ ├── dwarf-local-order.wasm │ ├── print_g_strip-dwarf.wasm │ ├── set-globals.txt │ ├── dwarf_with_exceptions.wasm │ ├── fuzz_metrics_noprint.wasm │ ├── reverse_dwarf_abbrevs.wasm │ ├── too_much_for_liveness.wasm │ ├── class_with_dwarf_noprint.wasm │ ├── fannkuch3_manyopts_dwarf.wasm │ ├── fib2_emptylocspan_dwarf.wasm │ ├── fib_nonzero-low-pc_dwarf.wasm │ ├── inlined_to_start_dwarf.wasm │ ├── multi_line_table_dwarf.wasm │ ├── print-function-map.wast │ ├── ignore_missing_func_dwarf.wasm │ ├── multi_unit_abbrev_noprint.wasm │ ├── remove-memory.wast │ ├── dwarfdump_roundtrip_dwarfdump.wasm │ ├── metrics_strip-debug_metrics.wasm │ ├── dce_vacuum_remove-unused-names.wasm │ ├── metrics_strip-producers_metrics.wasm │ ├── dwarf_unit_with_no_abbrevs_noprint.wasm │ ├── memory-packing_all-features_zero-filled-memory.txt │ ├── roundtrip_signed.passes │ ├── set-globals.wast │ ├── interesting-pass-mix.passes │ ├── roundtrip_signed.wasm │ ├── legalize-js-interface_pass-arg=legalize-js-interface-export-originals.wast │ ├── roundtrip.txt │ ├── print-function-map.txt │ ├── precompute_coalesce-locals_vacuum.txt │ ├── memory-packing_all-features_zero-filled-memory.wast │ ├── reorder-functions.txt │ ├── merge-blocks_remove-unused-brs.wast │ ├── vacuum_remove-unused-names_merge-blocks.txt │ ├── roundtrip.wast │ ├── reorder-functions.wast │ ├── roundtrip_typenames_features.txt │ ├── merge-blocks_remove-unused-brs.txt │ ├── safe-heap_start-function.wast │ ├── minify-imports-and-exports-and-modules.wast │ ├── vacuum_ignore-implicit-traps.txt │ ├── duplicate-import-elimination.wast │ ├── remove-unused-brs_precompute_vacuum_remove-unused-brs.txt │ ├── safe-heap_disable-simd.wast │ ├── souperify.wast │ ├── strip-debug.bin.txt │ ├── roundtrip_typenames_features.wast │ ├── simplify-locals.txt │ ├── duplicate-import-elimination.txt │ ├── strip-target-features_roundtrip_print-features_all-features.wast │ ├── fpcast-emu_pass-arg=max-func-params@5.wast │ ├── minify-imports-and-exports-and-modules.txt │ ├── emit-spec-wrapper=a.wat.wast.wat │ ├── souperify.txt │ ├── remove-unused-brs_generate-stack-ir_print-stack-ir.wast │ ├── precompute_coalesce-locals_vacuum.wast │ ├── remove-imports.txt │ ├── legalize-js-interface-minimally.wast │ ├── O1_print-stack-ir.wast │ ├── O2_print-stack-ir.wast │ ├── O3_print-stack-ir.wast │ ├── remove-unused-names_precompute.txt │ ├── pick-load-signs_all-features.wast │ ├── reorder-locals_print_roundtrip.wast │ ├── simplify-globals_all-features_fuzz-exec.wast │ ├── Os_print-stack-ir_all-features_disable-gc.wast │ ├── pick-load-signs_all-features.txt │ ├── roundtrip_signed.bin.txt │ ├── stack-check_enable-mutable-globals.wast │ ├── remove-unused-names_precompute.wast │ └── remove-unused-brs_precompute_vacuum_remove-unused-brs.wast ├── br_to_exit.wasm ├── control_flow.emcc ├── elided-br.wasm ├── grow_memory.emcc ├── spec │ ├── expected-output │ │ ├── func_ptrs.wast.log │ │ ├── names.wast.log │ │ ├── old_start.wast.log │ │ └── old_imports.wast.log │ ├── inline-module.wast │ ├── func-local-after-body.fail.wast │ ├── func-param-after-body.fail.wast │ ├── func-result-after-body.fail.wast │ ├── import-after-func.fail.wast │ ├── func-local-before-param.fail.wast │ ├── of_string-overflow-s32.fail.wast │ ├── of_string-overflow-u32.fail.wast │ ├── import-after-memory.fail.wast │ ├── import-after-table.fail.wast │ ├── of_string-overflow-hex-u32.fail.wast │ ├── import-after-global.fail.wast │ ├── of_string-overflow-hex-u64.fail.wast │ ├── of_string-overflow-s64.fail.wast │ ├── of_string-overflow-u64.fail.wast │ ├── func-local-before-result.fail.wast │ ├── func-result-before-param.fail.wast │ ├── f32.load32.fail.wast │ ├── f32.load64.fail.wast │ ├── f64.load32.fail.wast │ ├── f64.load64.fail.wast │ ├── i32.load32_s.fail.wast │ ├── i32.load32_u.fail.wast │ ├── i32.load64_s.fail.wast │ ├── i32.load64_u.fail.wast │ ├── i64.load64_s.fail.wast │ ├── i64.load64_u.fail.wast │ ├── f32.store32.fail.wast │ ├── f32.store64.fail.wast │ ├── f64.store32.fail.wast │ ├── f64.store64.fail.wast │ ├── i32.store32.fail.wast │ ├── i32.store64.fail.wast │ ├── i64.store64.fail.wast │ ├── address-offset-range.fail.wast │ ├── tuples.wast │ ├── atomics.wast │ ├── token.wast │ ├── break-drop.wast │ ├── call_indirect_refnull.wast │ ├── ref_eq.wast │ ├── ref_null.wast │ ├── Contributing.md │ ├── ref_is_null.wast │ └── call_indirect_sig_mismatch.wast ├── unreachable-pops.wasm ├── br_to_try.wasm ├── consume-stacky.wasm ├── break-within-catch.wasm ├── fn_prolog_epilog.debugInfo.wasm ├── let.wasm ├── memory-shared.wast ├── print │ ├── memory-shared.minified.txt │ ├── memory-shared.txt │ ├── memory-shared.wast │ ├── memory-import-shared.minified.txt │ ├── memory-import-shared.txt │ └── memory-import-shared.wast ├── dylib.wasm ├── stacky.wasm ├── validator │ ├── invalid_import.wast │ ├── invalid_return.wast │ ├── invalid_export.wast │ └── invalid_number.wast ├── empty_table.wast ├── fib-dbg.wasm ├── memory-shared.wast.from-wast ├── mutable-global.wasm ├── try-delegate.wasm ├── memory-shared.wast.fromBinary ├── metadatas.wasm ├── crash │ ├── outside.wasm │ ├── use_var_outside_func.wasm │ └── expression-past-end-of-input.wasm ├── duplicated_names.wasm ├── empty_table.wast.from-wast ├── break-to-return.wasm ├── empty_table.wast.fromBinary ├── memory-shared.wast.fromBinary.noDebugInfo ├── wasm2js │ ├── base64.wast │ ├── empty_export.wast │ ├── dot_import.wast │ ├── atomic_fence.wast │ ├── minified-memory.wast │ ├── start_func.wast │ ├── emscripten-grow-no.wast │ ├── sign_ext.wast │ ├── emscripten-grow-yes.wast │ ├── i64-ctz.wast │ ├── global_i64.wast │ ├── add_div.wast │ ├── br_table_to_loop.wast │ ├── deterministic.wast │ ├── unreachable-insts.wast │ ├── excess_fallthrough.wast │ ├── minus_minus.wast │ ├── nested-selects.wast │ ├── reinterpret_scratch.wast │ ├── if_unreachable.wast │ ├── func-ptr-offset.wast │ ├── base64.2asm.js │ ├── base64.2asm.js.opt │ ├── empty_table.2asm.js │ ├── i64-select.2asm.js │ ├── indirect-select.wast │ ├── i64-select.2asm.js.opt │ └── if_unreachable.2asm.js ├── duplicated_names_collision.wasm ├── complexBinaryNames.wasm ├── empty_imported_table.wast ├── empty_table.wast.fromBinary.noDebugInfo ├── fib-dbg.wasm.map ├── hello_world.c ├── bigswitch.txt ├── complexTextNames.wast ├── fn_prolog_epilog.debugInfo.wasm.map ├── empty_imported_table.wast.from-wast ├── hello_libcxx.cpp ├── empty_imported_table.wast.fromBinary ├── fasta.txt ├── imported_memory.wast ├── imported_memory_growth.wast ├── empty_imported_table.wast.fromBinary.noDebugInfo ├── extended-names.wast.fromBinary.noDebugInfo ├── elided-br.wasm.fromBinary ├── extended-names.wast ├── imported_memory.wast.from-wast ├── imported_memory_growth.wast.from-wast ├── br_to_exit.wasm.fromBinary ├── imported_memory.wast.fromBinary ├── imported_memory_growth.wast.fromBinary ├── segment-overlap.wast.from-wast ├── unreachable-instr-type.wast.fromBinary ├── extended-names.wast.from-wast ├── segment-overlap.wast.fromBinary ├── extended-names.wast.fromBinary ├── reduce │ ├── imports.wast.txt │ ├── simple.wast.txt │ ├── destructive.wast.txt │ ├── simple.wast │ ├── destructive.wast │ ├── atomics-and-bulk-memory.wast.txt │ ├── imports.wast │ └── memory_table.wast.txt ├── unreachable-instr-type.wast.fromBinary.noDebugInfo ├── printf.txt ├── imported_memory.wast.fromBinary.noDebugInfo ├── imported_memory_growth.wast.fromBinary.noDebugInfo ├── segment-overlap.wast ├── segment-overlap.wast.fromBinary.noDebugInfo ├── atomics-unshared.wast ├── unreachable-pops.wasm.fromBinary ├── table-import.wast ├── complexTextNames.wast.fromBinary.noDebugInfo ├── table-import.wast.from-wast ├── export-import.wast ├── memory-import.wast.from-wast ├── table-import.wast.fromBinary ├── complexTextNames.wast.from-wast ├── export-import.wast.from-wast ├── complexTextNames.wast.fromBinary ├── export-import.wast.fromBinary ├── memory-import.wast.fromBinary ├── memory-import64.wast.from-wast ├── complexBinaryNames.wasm.fromBinary ├── memory-import.wast ├── memory-import64.wast.fromBinary ├── reg_switch.wast.from-wast ├── fn_prolog_epilog.debugInfo.wast.fromBinary ├── memory-import64.wast ├── table-import.wast.fromBinary.noDebugInfo ├── metadatas.wasm.fromBinary ├── fn_prolog_epilog.debugInfo.wast.fromBinary.noDebugInfo ├── memory-import64.wast.wasm.fromBinary ├── reg_switch.wast.fromBinary ├── memory-import.wast.fromBinary.noDebugInfo ├── atomics-unshared.wast.from-wast ├── duplicate_types.wast.from-wast ├── atomics-unshared.wast.fromBinary ├── memory-import64.wast.fromBinary.noDebugInfo ├── reg_switch.wast ├── duplicate_types.wast.fromBinary ├── export-import.wast.fromBinary.noDebugInfo ├── multi-table.minified.txt ├── atomics-unshared.wast.fromBinary.noDebugInfo ├── calls.txt ├── reg_switch.wast.fromBinary.noDebugInfo ├── duplicated_names.wasm.fromBinary ├── mutable-global.wast.from-wast ├── tail-call.wast.from-wast ├── tail-call.wast.fromBinary ├── duplicate_types.wast.fromBinary.noDebugInfo ├── duplicated_names_collision.wasm.fromBinary ├── mutable-global.wast.fromBinary ├── hello_world.wat ├── mutable-global.wasm.fromBinary ├── newsyntax.wast ├── untaken-br_if.wast ├── mutable-global.wast ├── mutable-global.wast.fromBinary.noDebugInfo ├── tail-call.wast.fromBinary.noDebugInfo ├── hello_world.wast.from-wast ├── fn_prolog_epilog.debugInfo.wast ├── consume-stacky.wasm.fromBinary ├── hello_world.wast.fromBinary ├── hello_world.wast.fromBinary.noDebugInfo ├── fn_prolog_epilog.debugInfo.wast.from-wast ├── untaken-br_if.wast.fromBinary.noDebugInfo ├── untaken-br_if.wast.fromBinary ├── fn_prolog_epilog.debugInfo.wasm.fromBinary ├── untaken-br_if.wast.from-wast ├── fannkuch.txt ├── signext.wast ├── br_to_try.wasm.fromBinary ├── break-to-return.wasm.fromBinary ├── grow_memory.txt ├── break-within-catch.wasm.fromBinary ├── grow_memory.wast.from-wast ├── tags.wast ├── grow_memory.wast.fromBinary ├── duplicate_types.wast ├── grow_memory.cpp ├── grow_memory.wast.fromBinary.noDebugInfo ├── grow_memory.wast ├── stacky.wasm.fromBinary ├── newsyntax.wast.from-wast ├── tags.wast.from-wast ├── calls.cpp ├── newsyntax.wast.fromBinary ├── tags.wast.fromBinary ├── newsyntax.wast.fromBinary.noDebugInfo ├── signext.wast.from-wast ├── tags.wast.fromBinary.noDebugInfo ├── signext.wast.fromBinary ├── calls.post.js ├── unreachable-instr-type.wast.from-wast ├── nonspec-bulk-memory.wast ├── signext.wast.fromBinary.noDebugInfo ├── unreachable-instr-type.wast ├── nonspec-bulk-memory.wast.fromBinary.noDebugInfo ├── control_flow.post.js ├── externref.wast.from-wast ├── printf.c ├── nonspec-bulk-memory.wast.from-wast ├── externref.wast.fromBinary └── nonspec-bulk-memory.wast.fromBinary ├── wasi-stub ├── .gitignore ├── build.sh ├── run.sh └── README.md ├── third_party ├── .clang-tidy ├── v8 │ └── .gitignore ├── mozjs │ └── .gitignore ├── llvm-project │ └── include │ │ └── llvm │ │ ├── Support │ │ ├── Threading.h │ │ ├── CommandLine.h │ │ ├── ManagedStatic.h │ │ ├── Locale.h │ │ ├── LICENSE.TXT │ │ └── ReverseIteration.h │ │ ├── Config │ │ ├── abi-breaking.h │ │ ├── config.h │ │ └── llvm-config.h │ │ └── BinaryFormat │ │ └── ELFRelocs │ │ └── BPF.def ├── wabt │ ├── .gitignore │ └── wasm2c │ │ └── README.md ├── CMakeLists.txt └── .clang-format ├── config.h.in ├── media └── example.png ├── src ├── templates │ ├── normal.js │ └── wasm.js ├── cfg │ └── CMakeLists.txt ├── asmjs │ └── CMakeLists.txt ├── tools │ └── wasm-split │ │ └── CMakeLists.txt ├── js │ └── binaryen.js-extern-pre.js ├── emscripten-optimizer │ └── CMakeLists.txt ├── support │ └── CMakeLists.txt └── ir │ └── CMakeLists.txt ├── .gitattributes ├── scripts ├── test │ ├── mod.ule.js │ ├── env.js │ └── spectest.js ├── strip_local_names.py └── emcc-tests.sh ├── .flake8 ├── requirements-dev.txt ├── ubsan.blacklist └── .clang-format /test/revision: -------------------------------------------------------------------------------- 1 | 13645 2 | -------------------------------------------------------------------------------- /test/unit/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fannkuch.args: -------------------------------------------------------------------------------- 1 | ["5"] 2 | -------------------------------------------------------------------------------- /test/fasta.args: -------------------------------------------------------------------------------- 1 | ["10"] 2 | -------------------------------------------------------------------------------- /test/lit/wasm-split/none.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/lld/em_asm.wat.mem.mem: -------------------------------------------------------------------------------- 1 | iii -------------------------------------------------------------------------------- /test/metadce/tag.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /wasi-stub/.gitignore: -------------------------------------------------------------------------------- 1 | wasi-stub -------------------------------------------------------------------------------- /test/binaryen.js/pass-arguments.js.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/example/domtree.txt: -------------------------------------------------------------------------------- 1 | success. 2 | -------------------------------------------------------------------------------- /test/example/hash.txt: -------------------------------------------------------------------------------- 1 | success. 2 | -------------------------------------------------------------------------------- /test/example/small_set.txt: -------------------------------------------------------------------------------- 1 | ok. 2 | -------------------------------------------------------------------------------- /test/example/small_vector.txt: -------------------------------------------------------------------------------- 1 | ok. 2 | -------------------------------------------------------------------------------- /test/example/space.txt: -------------------------------------------------------------------------------- 1 | success. 2 | -------------------------------------------------------------------------------- /test/linker/baz.c: -------------------------------------------------------------------------------- 1 | void baz() {} 2 | -------------------------------------------------------------------------------- /test/linker/quux.c: -------------------------------------------------------------------------------- 1 | void quux() {} 2 | -------------------------------------------------------------------------------- /test/lit/wasm-split/bar.txt: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /test/lit/wasm-split/foo.txt: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /test/unit/input/empty.wasm: -------------------------------------------------------------------------------- 1 | asm -------------------------------------------------------------------------------- /third_party/.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: '' 2 | -------------------------------------------------------------------------------- /test/binaryen.js/copy-expression.js.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/calls.emcc: -------------------------------------------------------------------------------- 1 | ["-s", "ASSERTIONS=0"] 2 | -------------------------------------------------------------------------------- /test/example/local-graph.txt: -------------------------------------------------------------------------------- 1 | Success. 2 | -------------------------------------------------------------------------------- /test/hello_world.txt: -------------------------------------------------------------------------------- 1 | hello, world! 2 | 3 | -------------------------------------------------------------------------------- /test/mem.emcc: -------------------------------------------------------------------------------- 1 | ["-s", "ASSERTIONS=0"] 2 | -------------------------------------------------------------------------------- /test/metadce/all-outside.wast: -------------------------------------------------------------------------------- 1 | (module) 2 | -------------------------------------------------------------------------------- /test/ctor-eval/imported3.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/no_partial.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_call.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/example/c-api-relooper-unreachable-if.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/float_ops.emcc: -------------------------------------------------------------------------------- 1 | ["-s", "ASSERTIONS=0"] 2 | -------------------------------------------------------------------------------- /test/hello_libcxx.txt: -------------------------------------------------------------------------------- 1 | hello, world! 2 | 3 | -------------------------------------------------------------------------------- /test/int_ops.emcc: -------------------------------------------------------------------------------- 1 | ["-s", "ASSERTIONS=0"] 2 | -------------------------------------------------------------------------------- /test/linker/foo.c: -------------------------------------------------------------------------------- 1 | int foo() { return 43; } 2 | -------------------------------------------------------------------------------- /test/lit/wasm-split/both.txt: -------------------------------------------------------------------------------- 1 | foo 2 | bar 3 | -------------------------------------------------------------------------------- /test/lld/hello_world.wat.mem.mem: -------------------------------------------------------------------------------- 1 | Hello, world -------------------------------------------------------------------------------- /test/metadce/spanning_cycle.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/metadce/threaded_cycle.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/passes/multi_unit_abbrev_noprint.bin.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /third_party/v8/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /test/binaryen.js/tail_calls.js.txt: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | -------------------------------------------------------------------------------- /test/br_to_exit.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 |  -------------------------------------------------------------------------------- /test/control_flow.emcc: -------------------------------------------------------------------------------- 1 | ["-s", "ASSERTIONS=0"] 2 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/imported.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/ctor-eval/indirect-call3.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store2.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store3.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/metadce/all-outside.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/metadce/no-outside.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /third_party/mozjs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /test/binaryen.js/fast-math.js.txt: -------------------------------------------------------------------------------- 1 | // fastMath=false 2 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call2.wast.ctors: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /test/ctor-eval/basics.wast.ctors: -------------------------------------------------------------------------------- 1 | test1,test2,test3 2 | -------------------------------------------------------------------------------- /test/ctor-eval/imported-min.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/ctor-eval/imported.wast.ctors: -------------------------------------------------------------------------------- 1 | test1,test2,test3 2 | -------------------------------------------------------------------------------- /test/ctor-eval/imported2.wast.ctors: -------------------------------------------------------------------------------- 1 | test1,test2,test3 2 | -------------------------------------------------------------------------------- /test/ctor-eval/just_some.wast.ctors: -------------------------------------------------------------------------------- 1 | test1,test2,test3 2 | -------------------------------------------------------------------------------- /test/ctor-eval/stack-direction.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store2.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store3.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/elided-br.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 |  @@  -------------------------------------------------------------------------------- /test/grow_memory.emcc: -------------------------------------------------------------------------------- 1 | ["-s", "ALLOW_MEMORY_GROWTH=1"] 2 | -------------------------------------------------------------------------------- /test/metadce/threaded_unrooted.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/passes/dwarf_unit_with_no_abbrevs_noprint.bin.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/passes/safe-heap_start-function.passes: -------------------------------------------------------------------------------- 1 | safe-heap 2 | -------------------------------------------------------------------------------- /test/spec/expected-output/func_ptrs.wast.log: -------------------------------------------------------------------------------- 1 | 83 : i32 2 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Support/Threading.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call3.wast.ctors: -------------------------------------------------------------------------------- 1 | sig_mismatch 2 | -------------------------------------------------------------------------------- /test/ctor-eval/basics-flatten.wast.ctors: -------------------------------------------------------------------------------- 1 | test1,test2,test3 2 | -------------------------------------------------------------------------------- /test/ctor-eval/imported-min.wast.ctors: -------------------------------------------------------------------------------- 1 | test1,test2,test3 2 | -------------------------------------------------------------------------------- /test/linker/bar.c: -------------------------------------------------------------------------------- 1 | void quux(); 2 | void bar() { quux(); } 3 | -------------------------------------------------------------------------------- /test/metadce/no-outside.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | ] 3 | 4 | 5 | -------------------------------------------------------------------------------- /test/unreachable-pops.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 | j -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | #cmakedefine PROJECT_VERSION "${PROJECT_VERSION}" 2 | -------------------------------------------------------------------------------- /test/br_to_try.wasm: -------------------------------------------------------------------------------- 1 | asm``  2 |  3 | @  -------------------------------------------------------------------------------- /test/consume-stacky.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 |  AAA6 -------------------------------------------------------------------------------- /test/ctor-eval/stack-direction.wast.ctors: -------------------------------------------------------------------------------- 1 | __post_instantiate 2 | -------------------------------------------------------------------------------- /test/example/cpp-unit.txt: -------------------------------------------------------------------------------- 1 | i31ref(0) 2 | i31ref(0) 3 | Success 4 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle_unrooted.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/metadce/threaded_unrooted_cycle.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | ) 3 | -------------------------------------------------------------------------------- /test/passes/fib2_dwarf.passes: -------------------------------------------------------------------------------- 1 | dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/inlined_to_start_dwarf.passes: -------------------------------------------------------------------------------- 1 | g_roundtrip_dwarfdump 2 | -------------------------------------------------------------------------------- /test/passes/reverse_dwarf_abbrevs.passes: -------------------------------------------------------------------------------- 1 | roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/spec/expected-output/names.wast.log: -------------------------------------------------------------------------------- 1 | 42 : i32 2 | 123 : i32 3 | -------------------------------------------------------------------------------- /test/spec/expected-output/old_start.wast.log: -------------------------------------------------------------------------------- 1 | 1 : i32 2 | 2 : i32 3 | -------------------------------------------------------------------------------- /test/metadce/threaded.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: outside_js_function1 2 | -------------------------------------------------------------------------------- /test/passes/class_with_dwarf_noprint.passes: -------------------------------------------------------------------------------- 1 | roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/dwarf_unit_with_no_abbrevs_noprint.passes: -------------------------------------------------------------------------------- 1 | roundtrip_g 2 | -------------------------------------------------------------------------------- /test/passes/fannkuch0_dwarf.passes: -------------------------------------------------------------------------------- 1 | dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/fannkuch3_dwarf.passes: -------------------------------------------------------------------------------- 1 | dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/fuzz_metrics_noprint.passes: -------------------------------------------------------------------------------- 1 | translate-to-fuzz_metrics 2 | -------------------------------------------------------------------------------- /test/spec/inline-module.wast: -------------------------------------------------------------------------------- 1 | (func) (memory 0) (func (export "f")) 2 | -------------------------------------------------------------------------------- /test/break-within-catch.wasm: -------------------------------------------------------------------------------- 1 | asm``  2 |  @ -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 |  @@  -------------------------------------------------------------------------------- /test/let.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/let.wasm -------------------------------------------------------------------------------- /test/memory-shared.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | ) 4 | -------------------------------------------------------------------------------- /test/passes/fib2_emptylocspan_dwarf.passes: -------------------------------------------------------------------------------- 1 | dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/remove-memory.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1024 1024) 3 | ) 4 | -------------------------------------------------------------------------------- /test/print/memory-shared.minified.txt: -------------------------------------------------------------------------------- 1 | (module(memory $0 (shared 23 256)) 2 | ) -------------------------------------------------------------------------------- /third_party/wabt/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !wasm2c 4 | !wasm2c/* 5 | -------------------------------------------------------------------------------- /test/dylib.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/dylib.wasm -------------------------------------------------------------------------------- /test/passes/dwarf_with_exceptions.passes: -------------------------------------------------------------------------------- 1 | print_dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/fannkuch3_manyopts_dwarf.passes: -------------------------------------------------------------------------------- 1 | dwarfdump_O4_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/multi_unit_abbrev_noprint.passes: -------------------------------------------------------------------------------- 1 | g_roundtrip_roundtrip_roundtrip 2 | -------------------------------------------------------------------------------- /test/passes/set-globals.passes: -------------------------------------------------------------------------------- 1 | set-globals_pass-arg=set-globals@foo=1337,bar=42 2 | -------------------------------------------------------------------------------- /test/passes/strip-target-features.wasm: -------------------------------------------------------------------------------- 1 | asm linkingtarget_features+foo -------------------------------------------------------------------------------- /test/print/memory-shared.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | ) 4 | -------------------------------------------------------------------------------- /test/print/memory-shared.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | ) 4 | -------------------------------------------------------------------------------- /test/spec/func-local-after-body.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (nop) (local i32))) 2 | -------------------------------------------------------------------------------- /test/spec/func-param-after-body.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (nop) (param i32))) 2 | -------------------------------------------------------------------------------- /test/spec/func-result-after-body.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (nop) (result i32))) 2 | -------------------------------------------------------------------------------- /test/spec/import-after-func.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func) (import "" "" (memory 0))) 2 | -------------------------------------------------------------------------------- /test/stacky.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/stacky.wasm -------------------------------------------------------------------------------- /test/validator/invalid_import.wast: -------------------------------------------------------------------------------- 1 | (module (import $bad "test" "bad" (param i64))) -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Config/abi-breaking.h: -------------------------------------------------------------------------------- 1 | 2 | // waka 3 | 4 | -------------------------------------------------------------------------------- /media/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/media/example.png -------------------------------------------------------------------------------- /src/templates/normal.js: -------------------------------------------------------------------------------- 1 | 2 | var Module = {}; // *.asm.js expects this 3 | 4 | 5 | -------------------------------------------------------------------------------- /test/empty_table.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (table 0 0 funcref) 3 | (memory $0 0) 4 | ) 5 | -------------------------------------------------------------------------------- /test/fib-dbg.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/fib-dbg.wasm -------------------------------------------------------------------------------- /test/lit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | configure_file(lit.site.cfg.py.in lit.site.cfg.py @ONLY) 2 | -------------------------------------------------------------------------------- /test/memory-shared.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | ) 4 | -------------------------------------------------------------------------------- /test/mutable-global.wasm: -------------------------------------------------------------------------------- 1 | asm`env 2 | global-mut 3 |  #Aj$ -------------------------------------------------------------------------------- /test/passes/O.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/O.wasm -------------------------------------------------------------------------------- /test/passes/ignore_missing_func_dwarf.passes: -------------------------------------------------------------------------------- 1 | print_dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/spec/func-local-before-param.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (local i32) (param i32))) 2 | -------------------------------------------------------------------------------- /test/spec/of_string-overflow-s32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (i32.const -2147483649))) 2 | -------------------------------------------------------------------------------- /test/spec/of_string-overflow-u32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (i32.const 4294967296))) 2 | -------------------------------------------------------------------------------- /test/try-delegate.wasm: -------------------------------------------------------------------------------- 1 | asm`  2 | ! @@ @@A@  -------------------------------------------------------------------------------- /test/validator/invalid_return.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $foo (result i32) (i64.const 1))) -------------------------------------------------------------------------------- /test/memory-shared.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | ) 4 | 5 | -------------------------------------------------------------------------------- /test/metadatas.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/metadatas.wasm -------------------------------------------------------------------------------- /test/passes/dwarf-local-order.passes: -------------------------------------------------------------------------------- 1 | g_print_roundtrip_print_strip-dwarf_roundtrip_print 2 | -------------------------------------------------------------------------------- /test/passes/multi_line_table_dwarf.passes: -------------------------------------------------------------------------------- 1 | g_dwarfdump_roundtrip_dwarfdump_all-features 2 | -------------------------------------------------------------------------------- /test/passes/too_much_for_liveness.passes: -------------------------------------------------------------------------------- 1 | metrics_coalesce-locals_metrics_reorder-locals 2 | -------------------------------------------------------------------------------- /test/spec/import-after-memory.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 0) (import "" "" (global i32))) 2 | -------------------------------------------------------------------------------- /test/spec/import-after-table.fail.wast: -------------------------------------------------------------------------------- 1 | (module (table 0 funcref) (import "" "" (func))) 2 | -------------------------------------------------------------------------------- /test/spec/of_string-overflow-hex-u32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (i32.const 0x100000000))) 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.py text eol=lf 2 | *.sh text eol=lf 3 | test/binaryen.js/*.txt text eol=lf 4 | -------------------------------------------------------------------------------- /test/crash/outside.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/crash/outside.wasm -------------------------------------------------------------------------------- /test/duplicated_names.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 | A A A namefoofoofoo -------------------------------------------------------------------------------- /test/empty_table.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 0 0 funcref) 4 | ) 5 | -------------------------------------------------------------------------------- /test/metadce/corners.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: global$UNUSEDTOP$2 2 | unused: ignorable import 3 | -------------------------------------------------------------------------------- /test/passes/print.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/print.wasm -------------------------------------------------------------------------------- /test/spec/import-after-global.fail.wast: -------------------------------------------------------------------------------- 1 | (module (global i64) (import "" "" (table 0 funcref))) 2 | -------------------------------------------------------------------------------- /test/spec/of_string-overflow-hex-u64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (i64.const 0x10000000000000000))) 2 | -------------------------------------------------------------------------------- /test/spec/of_string-overflow-s64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (i64.const -9223372036854775809))) 2 | -------------------------------------------------------------------------------- /test/spec/of_string-overflow-u64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (i64.const 18446744073709551616))) 2 | -------------------------------------------------------------------------------- /test/break-to-return.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/break-to-return.wasm -------------------------------------------------------------------------------- /test/empty_table.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 0 0 funcref) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/memory-shared.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | ) 4 | 5 | -------------------------------------------------------------------------------- /test/passes/dwarfdump.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/dwarfdump.wasm -------------------------------------------------------------------------------- /test/passes/fib_nonzero-low-pc_dwarf.passes: -------------------------------------------------------------------------------- 1 | enable-mutable-globals_dwarfdump_roundtrip_dwarfdump_g 2 | -------------------------------------------------------------------------------- /test/passes/flatten.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/flatten.wasm -------------------------------------------------------------------------------- /test/passes/print_g.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/print_g.wasm -------------------------------------------------------------------------------- /test/passes/strip-target-features.bin.txt: -------------------------------------------------------------------------------- 1 | (module 2 | ;; custom section "linking", size 1 3 | ) 4 | -------------------------------------------------------------------------------- /test/spec/func-local-before-result.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (local i32) (result i32) (local.get 0))) 2 | -------------------------------------------------------------------------------- /test/spec/func-result-before-param.fail.wast: -------------------------------------------------------------------------------- 1 | (module (func (result i32) (param i32) (local.get 0))) 2 | -------------------------------------------------------------------------------- /test/unit/input/random_data.txt: -------------------------------------------------------------------------------- 1 | 6sgkjdfghk34589n-947-vn98f2yr-nb8f7t08b7gv*~&!%&^@}{PASD kjgsdf768 2 | -------------------------------------------------------------------------------- /test/wasm2js/base64.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $memory 1 1) 3 | (data (i32.const 2) "\00\fe\ff") 4 | ) -------------------------------------------------------------------------------- /test/wasm2js/empty_export.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "" (func $foo)) 3 | (func $foo) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /third_party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(BUILD_LLVM_DWARF) 2 | add_subdirectory(llvm-project) 3 | endif() 4 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Config/config.h: -------------------------------------------------------------------------------- 1 | 2 | // waka waka 3 | 4 | #include 5 | -------------------------------------------------------------------------------- /scripts/test/mod.ule.js: -------------------------------------------------------------------------------- 1 | 2 | export function ba_se() { 3 | console.log('"mod.ule"."ba.se"'); 4 | } 5 | -------------------------------------------------------------------------------- /test/duplicated_names_collision.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 | A A A namefoofoofoo.1 -------------------------------------------------------------------------------- /test/lld/em_asm_pthread.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/lld/em_asm_pthread.wasm -------------------------------------------------------------------------------- /test/passes/fib2_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fib2_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/strip-debug.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/strip-debug.wasm -------------------------------------------------------------------------------- /test/passes/strip-dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/strip-dwarf.wasm -------------------------------------------------------------------------------- /test/print/memory-import-shared.minified.txt: -------------------------------------------------------------------------------- 1 | (module(import "env" "memory" (memory $0 (shared 256 256)))) -------------------------------------------------------------------------------- /third_party/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | DisableFormat: true 4 | SortIncludes: false 5 | --- 6 | -------------------------------------------------------------------------------- /wasi-stub/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gcc -I../src wasi-stub.c -L../lib -lbinaryen -lpthread -o wasi-stub -------------------------------------------------------------------------------- /test/binaryen.js/simd.js.txt: -------------------------------------------------------------------------------- 1 | v128.const i8x16 0x1 0x0 0x0 0x0 0x2 0x0 0x0 0x0 0x3 0x0 0x0 0x0 0x4 0x0 0x0 0x0 2 | -------------------------------------------------------------------------------- /test/complexBinaryNames.wasm: -------------------------------------------------------------------------------- 1 | asm` $zoo (.bar) 2 | 3 |   name 4 | foo (.bar)1 -------------------------------------------------------------------------------- /test/print/memory-import-shared.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 (shared 256 256))) 3 | ) 4 | -------------------------------------------------------------------------------- /test/print/memory-import-shared.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 (shared 256 256))) 3 | ) 4 | -------------------------------------------------------------------------------- /test/spec/f32.load32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result f32) (f32.load32 (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/f32.load64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result f32) (f32.load64 (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/f64.load32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result f64) (f64.load32 (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/f64.load64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result f64) (f64.load64 (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/unit/input/dwarf/zlib.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/dwarf/zlib.wasm -------------------------------------------------------------------------------- /test/validator/invalid_export.wast: -------------------------------------------------------------------------------- 1 | (module (func $export64 (result i64) (i64.const 1)) (export "a" $export64)) -------------------------------------------------------------------------------- /test/empty_imported_table.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "table" (table 0 0 funcref)) 3 | (memory $0 0) 4 | ) 5 | -------------------------------------------------------------------------------- /test/empty_table.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 0 0 funcref) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/fib-dbg.wasm.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["fib.c"],"names":[],"mappings":"moBAEA,4BAKA,QAJA,OADA,OAAA,uCAKA"} 2 | -------------------------------------------------------------------------------- /test/hello_world.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("hello, world!\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/lit/binary/dylink.test.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/lit/binary/dylink.test.wasm -------------------------------------------------------------------------------- /test/lld/shared_add_to_table.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/lld/shared_add_to_table.wasm -------------------------------------------------------------------------------- /test/passes/fannkuch0_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fannkuch0_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/fannkuch3_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fannkuch3_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/print_g_metrics.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/print_g_metrics.wasm -------------------------------------------------------------------------------- /test/passes/roundtrip_typenames_features.passes: -------------------------------------------------------------------------------- 1 | enable-reference-types_enable-gc_emit-target-features_roundtrip 2 | -------------------------------------------------------------------------------- /test/passes/safe-heap_enable-threads_enable-simd64.passes: -------------------------------------------------------------------------------- 1 | safe-heap_enable-threads_enable-simd_enable-memory64 2 | -------------------------------------------------------------------------------- /test/passes/strip-producers.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/strip-producers.wasm -------------------------------------------------------------------------------- /test/spec/i32.load32_s.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result i32) (i32.load32_s (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/i32.load32_u.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result i32) (i32.load32_u (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/i32.load64_s.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result i32) (i32.load64_s (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/i32.load64_u.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result i32) (i32.load64_u (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/i64.load64_s.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result i64) (i64.load64_s (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/spec/i64.load64_u.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (result i64) (i64.load64_u (local.get 0)))) 2 | -------------------------------------------------------------------------------- /test/unit/input/bulkmem_data.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/bulkmem_data.wasm -------------------------------------------------------------------------------- /test/binaryen.js/custom-section.js.txt: -------------------------------------------------------------------------------- 1 | (module 2 | ;; custom section "hello", size 5, contents: "world" 3 | ) 4 | 5 | -------------------------------------------------------------------------------- /test/crash/use_var_outside_func.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/crash/use_var_outside_func.wasm -------------------------------------------------------------------------------- /test/linker/main.c: -------------------------------------------------------------------------------- 1 | int foo() { return 42; } 2 | 3 | void bar(); 4 | 5 | int main() { 6 | foo(); 7 | bar(); 8 | } 9 | -------------------------------------------------------------------------------- /test/lit/binary/bad-ref-as.test.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/lit/binary/bad-ref-as.test.wasm -------------------------------------------------------------------------------- /test/passes/converge_O3_metrics.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/converge_O3_metrics.wasm -------------------------------------------------------------------------------- /test/passes/dwarf-local-order.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/dwarf-local-order.wasm -------------------------------------------------------------------------------- /test/passes/print_g_strip-dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/print_g_strip-dwarf.wasm -------------------------------------------------------------------------------- /test/passes/set-globals.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (global $foo i32 (i32.const 1337)) 3 | (global $bar i64 (i64.const 42)) 4 | ) 5 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Support/CommandLine.h: -------------------------------------------------------------------------------- 1 | // XXX BINARYEN - we don't need this, but stuff imports it 2 | -------------------------------------------------------------------------------- /test/bigswitch.txt: -------------------------------------------------------------------------------- 1 | 34962: GL_ARRAY_BUFFER (0x8892) 2 | 26214: what? 3 | 35040: GL_STREAM_DRAW (0x88E0) 4 | 3060: what? 5 | 6 | -------------------------------------------------------------------------------- /test/complexTextNames.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $foo\20\28.bar\29) 3 | (func "$zoo (.bar)" (call $foo\20\28.bar\29)) 4 | ) 5 | -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wasm.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["src.cpp"],"names":[],"mappings":"sBAAC,EACA,EAAC,MACD,CAAC"} -------------------------------------------------------------------------------- /test/lld/hello_world.c: -------------------------------------------------------------------------------- 1 | int puts(const char* str); 2 | 3 | int main() { 4 | puts("Hello, world"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/passes/dwarf_with_exceptions.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/dwarf_with_exceptions.wasm -------------------------------------------------------------------------------- /test/passes/fuzz_metrics_noprint.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fuzz_metrics_noprint.wasm -------------------------------------------------------------------------------- /test/passes/reverse_dwarf_abbrevs.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/reverse_dwarf_abbrevs.wasm -------------------------------------------------------------------------------- /test/passes/too_much_for_liveness.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/too_much_for_liveness.wasm -------------------------------------------------------------------------------- /test/spec/f32.store32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param f32) (f32.store32 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/spec/f32.store64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param f64) (f32.store64 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/spec/f64.store32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param f32) (f64.store32 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/spec/f64.store64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param f64) (f64.store64 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/spec/i32.store32.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param i32) (i32.store32 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/spec/i32.store64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param i64) (i32.store64 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/spec/i64.store64.fail.wast: -------------------------------------------------------------------------------- 1 | (module (memory 1) (func (param i32) (param i64) (i64.store64 (local.get 0) (local.get 1)))) 2 | -------------------------------------------------------------------------------- /test/unit/input/dwarf/cubescript.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/dwarf/cubescript.wasm -------------------------------------------------------------------------------- /test/unit/input/gc_target_feature.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/gc_target_feature.wasm -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Support/ManagedStatic.h: -------------------------------------------------------------------------------- 1 | // XXX BINARYEN - we don't need this, but stuff imports it 2 | -------------------------------------------------------------------------------- /test/passes/class_with_dwarf_noprint.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/class_with_dwarf_noprint.wasm -------------------------------------------------------------------------------- /test/passes/fannkuch3_manyopts_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fannkuch3_manyopts_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/fib2_emptylocspan_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fib2_emptylocspan_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/fib_nonzero-low-pc_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/fib_nonzero-low-pc_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/inlined_to_start_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/inlined_to_start_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/multi_line_table_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/multi_line_table_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/print-function-map.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "foo" (func $Foo)) 3 | (func $bar) 4 | (func $baz) 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /test/unit/input/simd_target_feature.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/simd_target_feature.wasm -------------------------------------------------------------------------------- /test/empty_imported_table.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "table" (table $timport$0 0 0 funcref)) 3 | (memory $0 0) 4 | ) 5 | -------------------------------------------------------------------------------- /test/example/cpp-threads.txt: -------------------------------------------------------------------------------- 1 | create threads... 2 | threads running in parallel... 3 | waiting for threads to join... 4 | all done. 5 | -------------------------------------------------------------------------------- /test/hello_libcxx.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | std::cout << "hello, world!" << std::endl; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/metadce/all-outside.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: island 2 | unused: lonely 3 | unused: loop1 4 | unused: loop2 5 | unused: reverse 6 | -------------------------------------------------------------------------------- /test/passes/ignore_missing_func_dwarf.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/ignore_missing_func_dwarf.wasm -------------------------------------------------------------------------------- /test/passes/multi_unit_abbrev_noprint.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/multi_unit_abbrev_noprint.wasm -------------------------------------------------------------------------------- /test/passes/remove-memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1024 1024 3 | (segment 10 "123") 4 | (segment 20 "149") 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /test/unit/input/atomics_target_feature.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/atomics_target_feature.wasm -------------------------------------------------------------------------------- /test/unit/input/bulkmem_bad_datacount.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/bulkmem_bad_datacount.wasm -------------------------------------------------------------------------------- /test/unit/input/bulkmem_target_feature.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/bulkmem_target_feature.wasm -------------------------------------------------------------------------------- /test/unit/input/signext_target_feature.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/signext_target_feature.wasm -------------------------------------------------------------------------------- /test/crash/expression-past-end-of-input.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/crash/expression-past-end-of-input.wasm -------------------------------------------------------------------------------- /test/empty_imported_table.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "table" (table $timport$0 0 0 funcref)) 3 | (memory $0 0) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/fasta.txt: -------------------------------------------------------------------------------- 1 | GGCCGGGCGCGGTGGCTCAC 2 | cttBtatcatatgctaKggNcataaaSatg 3 | 4 | taaatcttgtgcttcgttagaagtctcgactacgtgtagcctagtgtttg 5 | 6 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle_unrooted.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: func$a_wasm_func$0 2 | unused: outside_js_function 3 | unused: wasm_export 4 | -------------------------------------------------------------------------------- /test/passes/dwarfdump_roundtrip_dwarfdump.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/dwarfdump_roundtrip_dwarfdump.wasm -------------------------------------------------------------------------------- /test/passes/metrics_strip-debug_metrics.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/metrics_strip-debug_metrics.wasm -------------------------------------------------------------------------------- /test/spec/address-offset-range.fail.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1) 3 | (func $bad (drop (i32.load offset=4294967296 (i32.const 0)))) 4 | ) 5 | -------------------------------------------------------------------------------- /test/unit/input/truncsat_target_feature.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/unit/input/truncsat_target_feature.wasm -------------------------------------------------------------------------------- /test/validator/invalid_number.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $invalid_number 3 | (i64.const 70847791997969805621592064) 4 | ) 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /test/wasm2js/dot_import.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "mod.ule" "ba.se" (func $base)) 3 | (func "exported" 4 | (call $base) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /test/imported_memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256 256)) 3 | (import "env" "table" (table 256 256 funcref)) 4 | ) 5 | -------------------------------------------------------------------------------- /test/imported_memory_growth.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256)) 3 | (import "env" "table" (table 256 funcref)) 4 | ) 5 | -------------------------------------------------------------------------------- /test/passes/dce_vacuum_remove-unused-names.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/dce_vacuum_remove-unused-names.wasm -------------------------------------------------------------------------------- /test/passes/metrics_strip-producers_metrics.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/metrics_strip-producers_metrics.wasm -------------------------------------------------------------------------------- /test/unit/input/exception_handling_target_feature.wasm: -------------------------------------------------------------------------------- 1 | asm``  2 | A name0%target_features+exception-handling -------------------------------------------------------------------------------- /test/passes/dwarf_unit_with_no_abbrevs_noprint.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/binaryen/main/test/passes/dwarf_unit_with_no_abbrevs_noprint.wasm -------------------------------------------------------------------------------- /test/wasm2js/atomic_fence.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | (func (export "atomic-fence") 4 | (atomic.fence) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /src/templates/wasm.js: -------------------------------------------------------------------------------- 1 | 2 | var Module = { 3 | asmjsCodeFile: 'a.asm.js' // tell polyfill (which replaces a.asm.js) where the asm.js code is 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /test/empty_imported_table.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "table" (table $timport$0 0 0 funcref)) 3 | (memory $0 0) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/passes/memory-packing_all-features_zero-filled-memory.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 1 1)) 3 | (data (i32.const 1024) "x") 4 | ) 5 | -------------------------------------------------------------------------------- /test/passes/roundtrip_signed.passes: -------------------------------------------------------------------------------- 1 | remove-unused-module-elements_roundtrip_vacuum_remove-unused-brs_merge-blocks_vacuum_duplicate-function-elimination 2 | -------------------------------------------------------------------------------- /test/wasm2js/minified-memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "a" (memory $0 1)) 3 | (func "foo" (result i32) 4 | (i32.load (i32.const 0)) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /test/wasm2js/start_func.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1) 3 | (start $foo) 4 | (func $foo 5 | (i32.store (i32.const 1) (i32.const 2)) 6 | ) 7 | ) 8 | -------------------------------------------------------------------------------- /src/cfg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB cfg_HEADERS *.h) 2 | set(cfg_SOURCES 3 | Relooper.cpp 4 | ${cfg_HEADERS} 5 | ) 6 | add_library(cfg OBJECT ${cfg_SOURCES}) 7 | -------------------------------------------------------------------------------- /test/binaryen.js/fast-math.js: -------------------------------------------------------------------------------- 1 | console.log("// fastMath=" + binaryen.getFastMath()); 2 | binaryen.setFastMath(true); 3 | assert(binaryen.getFastMath() == true); 4 | -------------------------------------------------------------------------------- /test/extended-names.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1 1) 3 | (data (i32.const 0) "a") 4 | (data "b") 5 | (table $0 1 funcref) 6 | ) 7 | 8 | -------------------------------------------------------------------------------- /test/elided-br.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (func $0 4 | (block $label$1 5 | (unreachable) 6 | ) 7 | ) 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /test/extended-names.wast: -------------------------------------------------------------------------------- 1 | (module $foo 2 | (table $t1 1 funcref) 3 | (memory $m1 1 1) 4 | (data $mydata (i32.const 0) "a") 5 | (data $passive_data "b") 6 | ) 7 | -------------------------------------------------------------------------------- /test/imported_memory.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256 256)) 3 | (import "env" "table" (table $timport$0 256 256 funcref)) 4 | ) 5 | -------------------------------------------------------------------------------- /test/imported_memory_growth.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256)) 3 | (import "env" "table" (table $timport$0 256 funcref)) 4 | ) 5 | -------------------------------------------------------------------------------- /test/metadce/rooted-export.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: export$wasm_func_a$4 2 | unused: export$wasm_tag_a$5 3 | unused: func$a_wasm_func$0 4 | unused: tag$a_wasm_tag$2 5 | -------------------------------------------------------------------------------- /test/unit/input/tail_call_target_feature.wasm: -------------------------------------------------------------------------------- 1 | asm` envbarmemoryfoo 2 |  name barfoo0target_features+ tail-call -------------------------------------------------------------------------------- /test/br_to_exit.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (func $0 4 | (block $label$0 5 | (br $label$0) 6 | ) 7 | ) 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /test/imported_memory.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256 256)) 3 | (import "env" "table" (table $timport$0 256 256 funcref)) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/imported_memory_growth.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256)) 3 | (import "env" "table" (table $timport$0 256 funcref)) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/segment-overlap.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 10) 3 | (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff") 4 | (data (i32.const 104) "\00\00\00\00") 5 | ) 6 | -------------------------------------------------------------------------------- /test/unreachable-instr-type.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 (shared 1 1)) 4 | (func $test 5 | (unreachable) 6 | ) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/extended-names.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module $foo 2 | (memory $m1 1 1) 3 | (data $mydata (i32.const 0) "a") 4 | (data $passive_data "b") 5 | (table $t1 1 funcref) 6 | ) 7 | -------------------------------------------------------------------------------- /test/segment-overlap.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 10) 3 | (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff") 4 | (data (i32.const 104) "\00\00\00\00") 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /test/unit/input/mutable_globals_target_feature.wasm: -------------------------------------------------------------------------------- 1 | asm`env 2 | global-mut 3 |  #Aj$ name0  gimport$0"target_features+mutable-globals -------------------------------------------------------------------------------- /test/binaryen.js/inlining-options.js.txt: -------------------------------------------------------------------------------- 1 | // alwaysInlineMaxSize=2 2 | // flexibleInlineMaxSize=20 3 | // oneCallerInlineMaxSize=-1 4 | // allowInliningFunctionsWithLoops=false 5 | -------------------------------------------------------------------------------- /test/extended-names.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module $foo 2 | (memory $m1 1 1) 3 | (data $mydata (i32.const 0) "a") 4 | (data $passive_data "b") 5 | (table $t1 1 funcref) 6 | ) 7 | 8 | -------------------------------------------------------------------------------- /test/metadce/no-outside.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: export$wasm_func$4 2 | unused: export$wasm_func_unused$5 3 | unused: func$a_wasm_func$0 4 | unused: func$an_unused_wasm_func$1 5 | -------------------------------------------------------------------------------- /test/passes/set-globals.wast: -------------------------------------------------------------------------------- 1 | (module 2 | ;; an imported i32 3 | (import "env" "in" (global $foo i32)) 4 | 5 | ;; a defined i64 6 | (global $bar i64 (i64.const 1234)) 7 | ) 8 | -------------------------------------------------------------------------------- /test/reduce/imports.wast.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (export "x" (func $0)) 4 | (func $0 (result i32) 5 | (i32.const 5678) 6 | ) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/reduce/simple.wast.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (export "x" (func $0)) 4 | (func $0 (result i32) 5 | (i32.const 5678) 6 | ) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/unreachable-instr-type.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 (shared 1 1)) 4 | (func $0 5 | (unreachable) 6 | ) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/binaryen.js/expressionrunner.js.txt: -------------------------------------------------------------------------------- 1 | // ExpressionRunner.Flags.Default = 0 2 | // ExpressionRunner.Flags.PreserveSideeffects = 1 3 | // ExpressionRunner.Flags.TraverseCalls = 2 4 | -------------------------------------------------------------------------------- /test/passes/interesting-pass-mix.passes: -------------------------------------------------------------------------------- 1 | flatten_rereloop_dce_remove-unused-brs_remove-unused-names_coalesce-locals_simplify-locals_reorder-locals_remove-unused-brs_merge-blocks_vacuum 2 | -------------------------------------------------------------------------------- /test/printf.txt: -------------------------------------------------------------------------------- 1 | int a = 12345 2 | unsigned b = 123456 3 | long c = 1234567 4 | unsigned long d = 12345678 5 | long long e = 1234567891011 6 | unsigned long long f = 123456789101112 7 | -------------------------------------------------------------------------------- /test/spec/expected-output/old_imports.wast.log: -------------------------------------------------------------------------------- 1 | 13 : i32 2 | 14 : i32 3 | 42 : f32 4 | 13 : i32 5 | 13 : i32 6 | 24 : i64 7 | 25 : i64 8 | 53 : f64 9 | 24 : i64 10 | 24 : i64 11 | -------------------------------------------------------------------------------- /test/spec/tuples.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module 3 | (func $foo 4 | (local $temp ((ref func) i32)) 5 | ) 6 | ) 7 | "var must be defaultable" 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /test/imported_memory.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $mimport$0 256 256)) 3 | (import "env" "table" (table $timport$0 256 256 funcref)) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/imported_memory_growth.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $mimport$0 256)) 3 | (import "env" "table" (table $timport$0 256 funcref)) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /test/passes/roundtrip_signed.wasm: -------------------------------------------------------------------------------- 1 | asm``A 2 | *as-br_table-indexas-local.set-value 3 | C"@#E@ #Ak$ @@A(  A @#E@ #Ak$ A( -------------------------------------------------------------------------------- /test/segment-overlap.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 10) 3 | (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff") ;; overlaps with the next 4 | (data (i32.const 104) "\00\00\00\00") 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /test/segment-overlap.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 10) 3 | (data (i32.const 100) "\ff\ff\ff\ff\ff\ff\ff\ff") 4 | (data (i32.const 104) "\00\00\00\00") 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /test/spec/atomics.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 23 256)) 3 | (func (export "atomic-fence") 4 | (atomic.fence) 5 | ) 6 | ) 7 | 8 | (assert_return (invoke "atomic-fence")) 9 | -------------------------------------------------------------------------------- /test/wasm2js/emscripten-grow-no.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "memory" (memory $0 256 256)) 4 | (data (i32.const 1600) "abc") 5 | (export "memory" (memory $0)) 6 | ) 7 | 8 | -------------------------------------------------------------------------------- /test/atomics-unshared.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1 1) 3 | (func $foo 4 | (drop (i32.atomic.rmw.cmpxchg 5 | (i32.const 0) 6 | (i32.const 0) 7 | (i32.const 0) 8 | )) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/lld/init.c: -------------------------------------------------------------------------------- 1 | volatile int x, y; 2 | 3 | __attribute__((constructor)) void init_x() { x = 14; } 4 | 5 | __attribute__((constructor)) void init_y() { y = 144; } 6 | 7 | int main() { return x + y; } 8 | -------------------------------------------------------------------------------- /test/passes/legalize-js-interface_pass-arg=legalize-js-interface-export-originals.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "func" (func $func)) 3 | (func $func (result i64) 4 | (unreachable) 5 | ) 6 | ) 7 | 8 | -------------------------------------------------------------------------------- /test/reduce/destructive.wast.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (export "x" (func $0)) 4 | (func $0 (param $0 i32) (result i32) 5 | (i32.const 100) 6 | ) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/unreachable-pops.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (func $0 (result i32) 4 | (block $label$1 (result i32) 5 | (unreachable) 6 | ) 7 | ) 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /test/binaryen.js/custom-section.js: -------------------------------------------------------------------------------- 1 | var module = new binaryen.Module(); 2 | 3 | module.addCustomSection("hello", [119, 111, 114, 108, 100]); 4 | 5 | assert(module.validate()); 6 | console.log(module.emitText()); 7 | -------------------------------------------------------------------------------- /src/asmjs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB asmjs_HEADERS *.h) 2 | set(asmjs_SOURCES 3 | asm_v_wasm.cpp 4 | asmangle.cpp 5 | shared-constants.cpp 6 | ${asmjs_HEADERS} 7 | ) 8 | add_library(asmjs OBJECT ${asmjs_SOURCES}) 9 | -------------------------------------------------------------------------------- /test/table-import.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "table" (table 1 1 funcref)) 4 | (elem (i32.const 0) $foo) 5 | (memory $0 0) 6 | (func $foo (type $0) 7 | (nop) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/complexTextNames.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (export "$zoo (.bar)" (func $1)) 4 | (func $0 5 | (nop) 6 | ) 7 | (func $1 8 | (call $0) 9 | ) 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /test/passes/roundtrip.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (export "foo" (func $0)) 4 | (func $0 5 | (unreachable) 6 | ) 7 | ) 8 | (module 9 | (memory $0 1 1) 10 | (table $0 0 funcref) 11 | ) 12 | -------------------------------------------------------------------------------- /test/table-import.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "table" (table $timport$0 1 1 funcref)) 4 | (memory $0 0) 5 | (elem (i32.const 0) $foo) 6 | (func $foo 7 | (nop) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/export-import.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (import "env" "test1" (func $test1)) 4 | (import "env" "test2" (global $test2 i32)) 5 | (export "test1" (func $test1)) 6 | (export "test2" (global $test2)) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/memory-import.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (import "env" "memory" (memory $0 1 1)) 4 | (func $foo (result i32) 5 | (i32.load offset=13 6 | (i32.const 37) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/table-import.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "table" (table $timport$0 1 1 funcref)) 4 | (memory $0 0) 5 | (elem (i32.const 0) $foo) 6 | (func $foo 7 | (nop) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/unit/input/reference_types_target_feature.wasm: -------------------------------------------------------------------------------- 1 | asm`ooenvtest1envtest2otest1test2 2 |   8nametest1 anyref_test00  gimport$1"target_features+reference-types -------------------------------------------------------------------------------- /test/complexTextNames.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (export "$zoo (.bar)" (func $1)) 4 | (func $foo\20\28.bar\29 5 | (nop) 6 | ) 7 | (func $1 8 | (call $foo\20\28.bar\29) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/export-import.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (import "env" "test2" (global $test2 i32)) 4 | (import "env" "test1" (func $test1)) 5 | (export "test1" (func $test1)) 6 | (export "test2" (global $test2)) 7 | ) 8 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle_unrooted.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "js_func" (func $a_js_func)) 3 | 4 | (export "wasm_func_a" (func $a_wasm_func)) 5 | 6 | (func $a_wasm_func 7 | (call $a_js_func) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/metadce/tag.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "tag_import", 4 | "import": ["env", "imported_tag"] 5 | }, 6 | { 7 | "name": "func_export", 8 | "root": true, 9 | "export": "test" 10 | } 11 | ] 12 | -------------------------------------------------------------------------------- /test/passes/print-function-map.txt: -------------------------------------------------------------------------------- 1 | 0:Foo 2 | 1:bar 3 | 2:baz 4 | (module 5 | (type $none_=>_none (func)) 6 | (import "env" "foo" (func $Foo)) 7 | (func $bar 8 | (nop) 9 | ) 10 | (func $baz 11 | (nop) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/wasm2js/sign_ext.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func "test8" (param $x i32) (result i32) 3 | (i32.extend8_s (local.get $x)) 4 | ) 5 | (func "test16" (param $x i32) (result i32) 6 | (i32.extend16_s (local.get $x)) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /test/complexTextNames.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (export "$zoo (.bar)" (func $1)) 4 | (func $foo\20\28.bar\29 5 | (nop) 6 | ) 7 | (func $1 8 | (call $foo\20\28.bar\29) 9 | ) 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /test/export-import.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (import "env" "test2" (global $test2 i32)) 4 | (import "env" "test1" (func $test1)) 5 | (export "test1" (func $test1)) 6 | (export "test2" (global $test2)) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/lit/binary/bad-ref-as.test: -------------------------------------------------------------------------------- 1 | ;; Test that we error properly on a file with a ref.as of a non-ref type. 2 | 3 | ;; RUN: not wasm-opt %s.wasm 2>&1 | filecheck %s 4 | 5 | ;; CHECK: parse exception: bad input type for ref.as: i32 6 | 7 | -------------------------------------------------------------------------------- /test/memory-import.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (import "env" "memory" (memory $0 1 1)) 4 | (func $foo (result i32) 5 | (i32.load offset=13 6 | (i32.const 37) 7 | ) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/memory-import64.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (import "env" "memory" (memory $0 i64 1 1)) 4 | (func $foo (result i32) 5 | (i32.load offset=13 6 | (i64.const 37) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/passes/precompute_coalesce-locals_vacuum.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (func $nested-br_if-value (param $0 i32) (result i32) 4 | (loop $label$0 5 | (br $label$0) 6 | ) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /test/complexBinaryNames.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (export "$zoo (.bar)" (func $1)) 4 | (func $foo\20\28.bar\29 5 | (nop) 6 | ) 7 | (func $1 8 | (call $foo\20\28.bar\29) 9 | ) 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /test/memory-import.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (import "env" "memory" (memory $0 1 1)) 4 | (func $foo (type $0) (result i32) 5 | (i32.load offset=13 6 | (i32.const 37) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/memory-import64.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (import "env" "memory" (memory $0 i64 1 1)) 4 | (func $foo (result i32) 5 | (i32.load offset=13 6 | (i64.const 37) 7 | ) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/reg_switch.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (memory $0 0) 4 | (func $0 5 | (if 6 | (i32.const 0) 7 | (block $A 8 | (br_table $A 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = 3 | E501, # line too long 4 | E241, # space after comma (ignored for list in gen-s-parser.py) 5 | W504 # line break after binary operator 6 | exclude = ./test/emscripten,./test/spec,./test/wasm-install,./test/lit 7 | -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (func $0 4 | (nop) 5 | (block $label$1 6 | (block $label$2 7 | (br $label$2) 8 | ) 9 | ) 10 | (return) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/lit/parse-error.wast: -------------------------------------------------------------------------------- 1 | ;; Test that parse errors have helpful messages 2 | 3 | ;; RUN: not wasm-opt %s 2>&1 | filecheck %s 4 | ;; CHECK: [parse exception: abc (at 8:4)] 5 | 6 | (module 7 | (func $foo 8 | (abc) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/lld/em_asm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | EM_ASM({ Module.print("Hello world"); }); 5 | int x = EM_ASM_INT({ return $0 + $1; }, 13, 27); 6 | EM_ASM_({ Module.print("Got " + $0); }, x); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/lld/em_asm64.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | EM_ASM({ Module.print("Hello world"); }); 5 | int x = EM_ASM_INT({ return $0 + $1; }, 13, 27); 6 | EM_ASM_({ Module.print("Got " + $0); }, x); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/memory-import64.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (import "env" "memory" (memory $0 i64 1 1)) 4 | (func $foo (type $0) (result i32) 5 | (i32.load offset=13 6 | (i64.const 37) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/table-import.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "table" (table $timport$0 1 1 funcref)) 4 | (memory $0 0) 5 | (elem (i32.const 0) $0) 6 | (func $0 7 | (nop) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/lld/em_asm_shared.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | EM_ASM({ Module.print("Hello world"); }); 5 | int x = EM_ASM_INT({ return $0 + $1; }, 13, 27); 6 | EM_ASM_({ Module.print("Got " + $0); }, x); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/metadatas.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (export "a" (func $0)) 4 | (func $0 5 | (nop) 6 | ) 7 | ;; custom section "emscripten_metadata", size 7 8 | ;; custom section "producers", size 187 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/spec/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/ctor-eval/unsafe_store.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (data (i32.const 10) "waka waka waka waka waka") 4 | (export "test1" $test1) 5 | (func $test1 6 | (i32.store8 (i32.const 9) (i32.const 109)) ;; before first segment 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store2.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (data (i32.const 10) "waka waka waka waka waka") 4 | (export "test1" $test1) 5 | (func $test1 6 | (i32.store8 (i32.const 34) (i32.const 109)) ;; after last segment 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /test/example/c-api-hello-world.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (func $adder (param $0 i32) (param $1 i32) (result i32) 4 | (i32.add 5 | (local.get $0) 6 | (local.get $1) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (func $0 4 | (nop) 5 | (block $label$1 6 | (block $label$2 7 | (br $label$2) 8 | ) 9 | ) 10 | (return) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/lit/memory64-limits.wast: -------------------------------------------------------------------------------- 1 | ;; RUN: wasm-opt %s -all --roundtrip -S -o - | filecheck %s 2 | 3 | (module 4 | (memory $0 i64 1 4294967296) 5 | ) 6 | 7 | ;; CHECK: (module 8 | ;; CHECK-NEXT: (memory $0 i64 1 4294967296) 9 | ;; CHECK-NEXT: ) 10 | -------------------------------------------------------------------------------- /test/lit/wasm-split/export-name-already-exists.wast: -------------------------------------------------------------------------------- 1 | ;; RUN: not wasm-split %s --instrument --profile-export=foo 2>&1 \ 2 | ;; RUN: | filecheck %s 3 | 4 | ;; CHECK: error: Export foo already exists. 5 | 6 | (module 7 | (export "foo" (memory 0 0)) 8 | ) 9 | -------------------------------------------------------------------------------- /test/memory-import64.wast.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (import "env" "memory" (memory $0 1 1 i64)) 4 | (func $0 (result i32) 5 | (i32.load offset=13 6 | (i64.const 37) 7 | ) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/metadce/outside.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "outside-entity", 4 | "reaches": ["inside-wasm-func"], 5 | "root": true 6 | }, 7 | { 8 | "name": "inside-wasm-func", 9 | "export": "wasm_func" 10 | } 11 | ] 12 | 13 | -------------------------------------------------------------------------------- /test/reg_switch.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (memory $0 0) 4 | (func $0 5 | (if 6 | (i32.const 0) 7 | (block $label$2 8 | (br_table $label$2 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/wasm2js/emscripten-grow-yes.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "memory" (memory $0 256 1024)) 4 | (data (i32.const 1600) "abc") 5 | (export "memory" (memory $0)) 6 | (func (export "get_size") (result i32) (memory.size)) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /src/tools/wasm-split/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB wasm_split_HEADERS *h) 2 | set(wasm_split_SOURCES 3 | wasm-split.cpp 4 | split-options.cpp 5 | instrumenter.cpp 6 | ${wasm_split_HEADERS} 7 | ) 8 | binaryen_add_executable(wasm-split "${wasm_split_SOURCES}") 9 | -------------------------------------------------------------------------------- /test/memory-import.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (import "env" "memory" (memory $mimport$0 1 1)) 4 | (func $0 (result i32) 5 | (i32.load offset=13 6 | (i32.const 37) 7 | ) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/metadce/outside.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: export$wasm_func_unused$10 2 | unused: func$an_unused_wasm_func$1 3 | unused: global$__THREW__unused$4 4 | unused: global$from_segment$5 5 | unused: global$from_segment_2$6 6 | unused: global$from_segment_never_used$7 7 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # These requirements are only needed for developers who want to run the test 2 | # suite or flake8, not for end users. 3 | 4 | # Install with `pip3 install -r requirements-dev.txt` 5 | 6 | flake8==3.7.8 7 | filecheck==0.0.17 8 | lit==0.11.0.post1 9 | -------------------------------------------------------------------------------- /test/atomics-unshared.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 1 1) 4 | (func $foo 5 | (drop 6 | (i32.atomic.rmw.cmpxchg 7 | (i32.const 0) 8 | (i32.const 0) 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/duplicate_types.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32))) 3 | (type $i32_=>_i32 (func (param i32) (result i32))) 4 | (func $f0 (param $0 i32) 5 | (nop) 6 | ) 7 | (func $f1 (param $0 i32) (result i32) 8 | (i32.const 0) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/lit/lit.site.cfg.py.in: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | config.binaryen_src_root = r'@CMAKE_SOURCE_DIR@' 4 | config.binaryen_build_root = r'@CMAKE_BINARY_DIR@' 5 | 6 | lit_config.load_config( 7 | config, os.path.join(config.binaryen_src_root, 'test', 'lit', 'lit.cfg.py')) 8 | -------------------------------------------------------------------------------- /test/lld/em_asm_O0.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | EM_ASM({ Module.print("Hello world"); }); 5 | int ret = EM_ASM_INT({ return $0 + $1; }, 20, 30); 6 | EM_ASM({ Module.print("Got " + $0); }, 42); 7 | return ret; 8 | } 9 | -------------------------------------------------------------------------------- /test/passes/memory-packing_all-features_zero-filled-memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | ;; we can optimize on an imported memory with zeroFilledMemory being set. 3 | (import "env" "memory" (memory $0 1 1)) 4 | (data (i32.const 1024) "x") 5 | (data (i32.const 1023) "\00") 6 | ) 7 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Config/llvm-config.h: -------------------------------------------------------------------------------- 1 | 2 | // This is all terrible 3 | 4 | #ifndef _WIN32 5 | #define LLVM_ON_UNIX 6 | #endif 7 | 8 | // Use simple std:: based atomics, no windows specifics 9 | #define LLVM_THREADING_USE_STD_CALL_ONCE 1 10 | -------------------------------------------------------------------------------- /test/atomics-unshared.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 1 1) 4 | (func $foo 5 | (drop 6 | (i32.atomic.rmw.cmpxchg 7 | (i32.const 0) 8 | (i32.const 0) 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /test/memory-import64.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (import "env" "memory" (memory $mimport$0 i64 1 1)) 4 | (func $0 (result i32) 5 | (i32.load offset=13 6 | (i64.const 37) 7 | ) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/metadce/tag.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "imported_tag" (tag $t0)) 3 | (tag $t1) 4 | (export "test" (func $test)) 5 | 6 | (func $test 7 | (try 8 | (do 9 | (throw $t0) 10 | ) 11 | (catch $t1) 12 | ) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/passes/reorder-functions.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (memory $0 256 256) 4 | (func $c 5 | (call $c) 6 | (call $c) 7 | (call $c) 8 | ) 9 | (func $b 10 | (call $b) 11 | (call $b) 12 | ) 13 | (func $a 14 | (call $a) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/reg_switch.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (memory $0 0) 4 | (func $0 (type $0) 5 | (if 6 | (i32.const 0) 7 | (block $A 8 | (br_table $A 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/wasm2js/i64-ctz.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "a" (func $popcnt64)) 3 | (export "b" (func $ctz64)) 4 | (func $popcnt64 (param $0 i64) (result i64) 5 | (i64.popcnt (local.get $0))) 6 | (func $ctz64 (param $0 i64) (result i64) 7 | (i64.ctz (local.get $0))) 8 | ) 9 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/BinaryFormat/ELFRelocs/BPF.def: -------------------------------------------------------------------------------- 1 | #ifndef ELF_RELOC 2 | #error "ELF_RELOC must be defined" 3 | #endif 4 | 5 | // No relocation 6 | ELF_RELOC(R_BPF_NONE, 0) 7 | ELF_RELOC(R_BPF_64_64, 1) 8 | ELF_RELOC(R_BPF_64_32, 10) 9 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_store3.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (data (i32.const 10) "waka waka waka waka waka") 4 | (export "test1" $test1) 5 | (func $test1 6 | (i32.store16 (i32.const 33) (i32.const 109)) ;; after last segment due to size of type 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /test/duplicate_types.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32))) 3 | (type $i32_=>_i32 (func (param i32) (result i32))) 4 | (func $f0 (param $0 i32) 5 | (nop) 6 | ) 7 | (func $f1 (param $0 i32) (result i32) 8 | (i32.const 0) 9 | ) 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /test/export-import.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "test2" (global $gimport$0 i32)) 4 | (import "env" "test1" (func $fimport$0)) 5 | (export "test1" (func $fimport$0)) 6 | (export "test2" (global $gimport$0)) 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /test/multi-table.minified.txt: -------------------------------------------------------------------------------- 1 | (module(type $none_=>_none (func))(import "a" "b" (table $t1 1 10 funcref))(elem (table $t1) (i32.const 0) func $f)(table $t2 3 3 funcref)(elem (table $t2) (i32.const 0) func $f)(elem (table $t2) (i32.const 1) func $f $g)(func $f(nop))(func $g(nop))) -------------------------------------------------------------------------------- /test/atomics-unshared.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 1 1) 4 | (func $0 5 | (drop 6 | (i32.atomic.rmw.cmpxchg 7 | (i32.const 0) 8 | (i32.const 0) 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /test/calls.txt: -------------------------------------------------------------------------------- 1 | simple 2 | 1 ==> 3 3 | 2 ==> 6 4 | 3 ==> 11 5 | 4 ==> 18 6 | 7 ==> 51 7 | fibo 8 | 1 ==> 1 9 | 2 ==> 2 10 | 3 ==> 3 11 | 4 ==> 5 12 | 7 ==> 21 13 | run_script 14 | hello from called script 15 | 9 16 | too many/few arguments 17 | 2 18 | 102 19 | -------------------------------------------------------------------------------- /test/lld/shared.cpp: -------------------------------------------------------------------------------- 1 | extern "C" int puts(const char* str); 2 | extern "C" int external_var; 3 | 4 | int print_message() { 5 | puts("Hello, world"); 6 | return external_var; 7 | } 8 | 9 | void* ptr_puts = (void*)&puts; 10 | void* ptr_local_func = (void*)&print_message; 11 | -------------------------------------------------------------------------------- /test/metadce/rooted-export.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "rooted-export-func", 4 | "root": true, 5 | "export": "wasm_func_b" 6 | }, 7 | { 8 | "name": "rooted-export-tag", 9 | "root": true, 10 | "export": "wasm_tag_b" 11 | } 12 | ] 13 | 14 | -------------------------------------------------------------------------------- /test/reg_switch.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (func $0 5 | (if 6 | (i32.const 0) 7 | (block $label$2 8 | (br_table $label$2 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | ) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/unit/input/asyncify-pure.txt: -------------------------------------------------------------------------------- 1 | 100 : i32 2 | 10 : i32 3 | 1 : i32 4 | 20 : i32 5 | 1000 : i32 6 | 2000 : i32 7 | 4000 : i32 8 | 200 : i32 9 | 300 : i32 10 | 400 : i32 11 | 1000 : i32 12 | 3000 : i32 13 | 4000 : i32 14 | 30 : i32 15 | 2 : i32 16 | 40 : i32 17 | 500 : i32 18 | -------------------------------------------------------------------------------- /test/binaryen.js/simd.js: -------------------------------------------------------------------------------- 1 | var module = new binaryen.Module(); 2 | 3 | var expr = module.v128.const([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]); 4 | var info = binaryen.getExpressionInfo(expr); 5 | console.log("v128.const i8x16 0x" + info.value.map(b => b.toString(16)).join(" 0x")); 6 | -------------------------------------------------------------------------------- /test/ctor-eval/basics.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "nas\00\00\00aka yzkx waka wakm\00\00\00\00\00\00C") 5 | (func $call-indirect 6 | (i32.store8 7 | (i32.const 40) 8 | (i32.const 67) 9 | ) 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/duplicated_names.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (func $foo (result i32) 4 | (i32.const 0) 5 | ) 6 | (func $foo.1 (result i32) 7 | (i32.const 1) 8 | ) 9 | (func $foo.2 (result i32) 10 | (i32.const 2) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle_unrooted.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "wasm_export", 4 | "export": "wasm_func_a" 5 | }, 6 | { 7 | "name": "outside_js_function", 8 | "reaches": ["wasm_export"], 9 | "import": ["env", "js_func"] 10 | } 11 | ] 12 | 13 | -------------------------------------------------------------------------------- /test/mutable-global.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "global-mut" (global $global-mut (mut i32))) 4 | (func $foo 5 | (global.set $global-mut 6 | (i32.add 7 | (global.get $global-mut) 8 | (i32.const 1) 9 | ) 10 | ) 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /test/tail-call.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (table $0 1 1 funcref) 4 | (elem (i32.const 0) $foo) 5 | (func $foo 6 | (return_call $bar) 7 | ) 8 | (func $bar 9 | (return_call_indirect $0 (type $void) 10 | (i32.const 0) 11 | ) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /src/js/binaryen.js-extern-pre.js: -------------------------------------------------------------------------------- 1 | // FIXME: The Emscripten shell requires this variable to be present, even though 2 | // we are building to ES6 (where it doesn't exist) and the .wasm blob is inlined 3 | // see: https://github.com/emscripten-core/emscripten/issues/11792 4 | var __dirname = ""; 5 | -------------------------------------------------------------------------------- /test/lld/em_asm_pthread.cpp: -------------------------------------------------------------------------------- 1 | // Build with 2 | // 3 | // emcc a.cpp -pthread -s WASM_BIGINT 4 | // 5 | 6 | #include 7 | 8 | EM_JS(void, world, (), { console.log("World."); }); 9 | 10 | int main() { 11 | EM_ASM({ console.log("Hello."); }); 12 | world(); 13 | } 14 | -------------------------------------------------------------------------------- /test/passes/merge-blocks_remove-unused-brs.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $func (param $x i32) 3 | (block $out 4 | (loop $loop 5 | (br_if $out 6 | (local.get $x) 7 | ) 8 | (nop) 9 | (br $loop) 10 | ) 11 | ) 12 | ) 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /test/passes/vacuum_remove-unused-names_merge-blocks.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (func $return-block (param $x i32) (result i32) 4 | (local.set $x 5 | (local.get $x) 6 | ) 7 | (return 8 | (local.get $x) 9 | ) 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/tail-call.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (table $0 1 1 funcref) 4 | (elem (i32.const 0) $foo) 5 | (func $foo 6 | (return_call $bar) 7 | ) 8 | (func $bar 9 | (return_call_indirect $0 (type $void) 10 | (i32.const 0) 11 | ) 12 | ) 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /test/binaryen.js/validation_errors.js.txt: -------------------------------------------------------------------------------- 1 | [wasm-validator error in function test] unexpected false: global.get name must be valid, on 2 | (global.get $missing) 3 | 0 4 | [wasm-validator error in function test] unexpected false: local.get index must be small enough, on 5 | (local.get $0) 6 | 0 7 | -------------------------------------------------------------------------------- /test/ctor-eval/basics-flatten.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "nas\00\00\00aka\00yzkx waka wakm\00\00\00\00\00\00C") 5 | (func $call-indirect 6 | (i32.store8 7 | (i32.const 40) 8 | (i32.const 67) 9 | ) 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/duplicate_types.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (type $i32_=>_i32 (func (param i32) (result i32))) 4 | (func $0 (param $0 i32) 5 | (nop) 6 | ) 7 | (func $1 (param $0 i32) (result i32) 8 | (i32.const 0) 9 | ) 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /test/duplicated_names_collision.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (func $foo (result i32) 4 | (i32.const 0) 5 | ) 6 | (func $foo.1 (result i32) 7 | (i32.const 1) 8 | ) 9 | (func $foo.1.1 (result i32) 10 | (i32.const 2) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/mutable-global.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "global-mut" (global $global-mut (mut i32))) 4 | (func $foo 5 | (global.set $global-mut 6 | (i32.add 7 | (global.get $global-mut) 8 | (i32.const 1) 9 | ) 10 | ) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/wasm2js/global_i64.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (global $f (mut i64) (i64.const 0x12345678ABCDEFAF)) 3 | (global $g (mut i64) (global.get $f)) 4 | (func $call (param i64)) 5 | (func "exp" 6 | (call $call (global.get $f)) 7 | (global.set $f (i64.const 0x1122334455667788)) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/ctor-eval/imported3.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (export "test1" (func $test1)) 6 | (func $test1 7 | (i32.store8 8 | (i32.const 13) 9 | (i32.const 115) 10 | ) 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /test/hello_world.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $add)) 5 | (func $add (param $x i32) (param $y i32) (result i32) 6 | (i32.add 7 | (local.get $x) 8 | (local.get $y) 9 | ) 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/mutable-global.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "global-mut" (global $gimport$0 (mut i32))) 4 | (func $0 5 | (global.set $gimport$0 6 | (i32.add 7 | (global.get $gimport$0) 8 | (i32.const 1) 9 | ) 10 | ) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/newsyntax.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "table" (table 9 9 funcref)) 3 | (func "call_indirect" 4 | (drop 5 | (call_indirect (param i32) (param f64) (result i32) (i32.const 10) (f64.const 20) (i32.const 30)) 6 | ) 7 | (call_indirect (i32.const 1)) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /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 | # Work around another libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60734 5 | src:*/stl_tree.h 6 | -------------------------------------------------------------------------------- /src/emscripten-optimizer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB emscripten-optimizer_HEADERS *.h) 2 | set(emscripten-optimizer_SOURCES 3 | optimizer-shared.cpp 4 | parser.cpp 5 | simple_ast.cpp 6 | ${emscripten-optimizer_HEADERS} 7 | ) 8 | add_library(emscripten-optimizer OBJECT ${emscripten-optimizer_SOURCES}) 9 | -------------------------------------------------------------------------------- /test/untaken-br_if.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $binaryify-untaken-br_if (result f32) 3 | (if (result f32) 4 | (i32.const 1) 5 | (unreachable) 6 | (block $label$1 (result f32) 7 | (br_if $label$1 8 | (f32.const 1) 9 | (unreachable) 10 | ) 11 | ) 12 | ) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/mutable-global.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (import "env" "global-mut" (global $global-mut (mut i32))) 4 | (func $foo (type $0) 5 | (global.set $global-mut 6 | (i32.add 7 | (global.get $global-mut) 8 | (i32.const 1) 9 | ) 10 | ) 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /test/mutable-global.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "global-mut" (global $gimport$0 (mut i32))) 4 | (func $0 5 | (global.set $gimport$0 6 | (i32.add 7 | (global.get $gimport$0) 8 | (i32.const 1) 9 | ) 10 | ) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/passes/roundtrip.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func "foo" 3 | ;; binaryen skips unreachable code while reading the binary format 4 | (unreachable) 5 | (nop) 6 | (nop) 7 | (nop) 8 | (nop) 9 | (nop) 10 | ) 11 | ) 12 | 13 | (module 14 | (memory 1 1) 15 | (table 0 funcref) 16 | ) 17 | -------------------------------------------------------------------------------- /test/reduce/simple.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "x" (func $x)) 3 | (func $x (result i32) 4 | (nop) 5 | (nop) 6 | (nop) 7 | (drop (i32.const 1234)) 8 | (i32.const 5678) ;; easily reducible 9 | ) 10 | (func $not-exported 11 | (nop) 12 | (unreachable) 13 | ) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/tail-call.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (table $0 1 1 funcref) 4 | (elem (i32.const 0) $0) 5 | (func $0 6 | (return_call $1) 7 | ) 8 | (func $1 9 | (return_call_indirect $0 (type $none_=>_none) 10 | (i32.const 0) 11 | ) 12 | ) 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /test/unit/input/hello_world.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $add)) 5 | (func $add (param $x i32) (param $y i32) (result i32) 6 | (i32.add 7 | (local.get $x) 8 | (local.get $y) 9 | ) 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/hello_world.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $add)) 5 | (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) 6 | (i32.add 7 | (local.get $x) 8 | (local.get $y) 9 | ) 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/metadce/rooted-export.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (type $none_=>_none (func)) 4 | (tag $b_wasm_tag (param i32)) 5 | (export "wasm_func_b" (func $b_wasm_func)) 6 | (export "wasm_tag_b" (tag $b_wasm_tag)) 7 | (func $b_wasm_func 8 | (unreachable) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/passes/reorder-functions.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (type $0 (func)) 4 | (func $a (type $0) 5 | (call $a) 6 | ) 7 | (func $b (type $0) 8 | (call $b) 9 | (call $b) 10 | ) 11 | (func $c (type $0) 12 | (call $c) 13 | (call $c) 14 | (call $c) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/unit/input/empty_lld.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $global$0 (mut i32) (i32.const 66192)) 3 | (global $global$1 i32 (i32.const 652)) 4 | (export "__data_end" (global $global$1)) 5 | (export "main" (func $main)) 6 | (func $main (param $0 i32) (param $1 i32) (result i32) 7 | (i32.const 0) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wast: -------------------------------------------------------------------------------- 1 | (module 2 | ;;@ src.cpp:1:1 3 | (func 4 | (nop) 5 | ;;@ src.cpp:2:1 6 | (block $l0 7 | ;;@ src.cpp:2:2 8 | (block $l1 9 | (br $l1) 10 | ) 11 | ) 12 | ;;@ src.cpp:3:1 13 | (return) 14 | ;;@ src.cpp:3:2 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/reduce/destructive.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "x" (func $x)) 3 | (func $x (param $x i32) (result i32) 4 | (if (i32.eq (local.get $x) (i32.const 98658746)) 5 | (unreachable) ;; this can be removed destructively, since we do not sent this param 6 | ) 7 | (i32.const 100) 8 | ) 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /test/consume-stacky.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 1 1) 4 | (func $0 (result i32) 5 | (local $0 i32) 6 | (local.set $0 7 | (i32.const 1) 8 | ) 9 | (i32.store 10 | (i32.const 2) 11 | (i32.const 3) 12 | ) 13 | (local.get $0) 14 | ) 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /test/ctor-eval/no_partial.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (export "test1" (func $test1)) 6 | (func $test1 7 | (i32.store8 8 | (i32.const 12) 9 | (i32.const 115) 10 | ) 11 | (unreachable) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/hello_world.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $add)) 5 | (func $add (; 0 ;) (param $0 i32) (param $1 i32) (result i32) 6 | (i32.add 7 | (local.get $0) 8 | (local.get $1) 9 | ) 10 | ) 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /test/metadce/tag.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "imported_tag" (tag $t0 (param))) 4 | (tag $t1 (param)) 5 | (export "test" (func $test)) 6 | (func $test 7 | (try $try 8 | (do 9 | (throw $t0) 10 | ) 11 | (catch $t1 12 | (nop) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/passes/roundtrip_typenames_features.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $ref?|$NamedStruct|_=>_none (func (param (ref null $NamedStruct)))) 3 | (type $NamedStruct (struct )) 4 | (export "export" (func $0)) 5 | (func $0 (param $0 (ref null $NamedStruct)) 6 | (nop) 7 | ) 8 | ;; features section: reference-types, gc 9 | ) 10 | -------------------------------------------------------------------------------- /test/wasm2js/add_div.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "foo" (func $foo (param i32) (result i32))) 3 | (func $foo (param $0 i32) (result i32) 4 | (i32.add 5 | (i32.div_u 6 | (local.get $0) 7 | (i32.const 100) 8 | ) 9 | (i32.div_s 10 | (local.get $0) 11 | (i32.const -100) 12 | ) 13 | ) 14 | ) 15 | ) -------------------------------------------------------------------------------- /test/hello_world.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $0)) 5 | (func $0 (; 0 ;) (param $0 i32) (param $1 i32) (result i32) 6 | (i32.add 7 | (local.get $0) 8 | (local.get $1) 9 | ) 10 | ) 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /test/passes/merge-blocks_remove-unused-brs.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (func $func (param $x i32) 4 | (loop $loop 5 | (block $out 6 | (block 7 | (br_if $out 8 | (local.get $x) 9 | ) 10 | (nop) 11 | (br $loop) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/wasm2js/br_table_to_loop.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func "exp1" 3 | (block $block 4 | (loop $loop 5 | (br_table $block $loop $block (i32.const 1)) 6 | ) 7 | ) 8 | ) 9 | (func "exp2" 10 | (block $block 11 | (loop $loop 12 | (br_table $loop $block $loop (i32.const 1)) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | ;;@ src.cpp:1:1 4 | (func $0 5 | (nop) 6 | ;;@ src.cpp:2:1 7 | (block $l0 8 | ;;@ src.cpp:2:2 9 | (block $l1 10 | (br $l1) 11 | ) 12 | ) 13 | ;;@ src.cpp:3:1 14 | (return) 15 | ;;@ src.cpp:3:2 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /test/lld/shared_longjmp.c: -------------------------------------------------------------------------------- 1 | typedef struct jmp_buf_buf { 2 | int thing; 3 | } jmp_buf; 4 | 5 | void longjmp(jmp_buf env, int val); 6 | int setjmp(jmp_buf env); 7 | 8 | int __THREW__; 9 | int __threwValue; 10 | 11 | void _start() { 12 | jmp_buf jmp; 13 | if (setjmp(jmp) == 0) { 14 | longjmp(jmp, 1); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/spec/break-drop.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "br") (block (br 0))) 3 | (func (export "br_if") (block (br_if 0 (i32.const 1)))) 4 | (func (export "br_table") (block (br_table 0 (i32.const 0)))) 5 | ) 6 | 7 | (assert_return (invoke "br")) 8 | (assert_return (invoke "br_if")) 9 | (assert_return (invoke "br_table")) 10 | -------------------------------------------------------------------------------- /test/lld/longjmp.c: -------------------------------------------------------------------------------- 1 | typedef struct jmp_buf_buf { 2 | int thing; 3 | } jmp_buf; 4 | 5 | void longjmp(jmp_buf env, int val); 6 | int setjmp(jmp_buf env); 7 | 8 | int __THREW__; 9 | int __threwValue; 10 | 11 | int main() { 12 | jmp_buf jmp; 13 | if (setjmp(jmp) == 0) { 14 | longjmp(jmp, 1); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/reduce/atomics-and-bulk-memory.wast.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 1 1) 4 | (export "foo" (func $0)) 5 | (func $0 (result i32) 6 | (i32.atomic.store8 7 | (i32.const 0) 8 | (i32.const 99) 9 | ) 10 | (i32.atomic.load8_u 11 | (i32.const 0) 12 | ) 13 | ) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/wasm2js/deterministic.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (global $global$0 (mut i32) (i32.const -44)) 3 | (import "env" "memory" (memory $0 1 1)) 4 | (func "foo" (result i32) 5 | (if 6 | (i32.div_u 7 | (global.get $global$0) 8 | (i32.load (i32.const 0)) 9 | ) 10 | (unreachable) 11 | ) 12 | (i32.const 1) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/binaryen.js/sourcemap.js.txt: -------------------------------------------------------------------------------- 1 | module.c 2 | 3 | 000: 00 a s m 01 00 00 00 01 05 01 ` 00 01 7f 03 4 | 010: 02 01 00 0a 06 01 04 00 A 01 0b 00 ! 10 s o 5 | 020: u r c e M a p p i n g U R L 0f m 6 | 030: o d u l e . w a s m . m a p 7 | 8 | {"version":3,"sources":["module.c"],"names":[],"mappings":"wBAAE"} 9 | -------------------------------------------------------------------------------- /test/lit/wasm-split/instrument-memory-too-small.wast: -------------------------------------------------------------------------------- 1 | ;; Test that the instrumentation increases the memory bounds if necessary 2 | 3 | ;; RUN: wasm-split %s --instrument -S -o - | filecheck %s 4 | 5 | ;; CHECK: (memory $0 1 1) 6 | ;; CHECK: (export "__write_profile" (func $__write_profile)) 7 | 8 | (module 9 | (memory $0 0 0) 10 | ) 11 | -------------------------------------------------------------------------------- /test/passes/safe-heap_start-function.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1 1) 3 | (func $foo 4 | ;; should not be modified because its the start function 5 | (i32.store (i32.load (i32.const 1234)) (i32.const 5678)) 6 | ) 7 | (func $bar 8 | (i32.store (i32.load (i32.const 1234)) (i32.const 5678)) 9 | ) 10 | (start $foo) 11 | ) 12 | -------------------------------------------------------------------------------- /test/unit/input/stack_ir.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "bar" (func $bar (param i32) (result i32))) 3 | (func "foo1" (result i32) 4 | (local $x i32) 5 | (local.set $x (call $bar (i32.const 0))) 6 | (drop 7 | (call $bar (i32.const 1)) 8 | ) 9 | (local.get $x) ;; local2stack can help here 10 | ) 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /test/untaken-br_if.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_f32 (func (result f32))) 3 | (func $0 (result f32) 4 | (if (result f32) 5 | (i32.const 1) 6 | (unreachable) 7 | (block $label$3 (result f32) 8 | (drop 9 | (f32.const 1) 10 | ) 11 | (unreachable) 12 | ) 13 | ) 14 | ) 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /test/wasm2js/unreachable-insts.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param f64 f64 f32))) 3 | (memory $0 1 1) 4 | (func $0 (; 0 ;) (type $0) (param $0 f64) (param $1 f64) (param $2 f32) 5 | (f64.store offset=22 align=1 6 | (block $label$1 (result i32) 7 | (unreachable) 8 | ) 9 | (f64.const 1) 10 | ) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /third_party/wabt/wasm2c/README.md: -------------------------------------------------------------------------------- 1 | These files are part of WABT, but are currently not present in releases, so the 2 | directory is included as a fallback in Binaryen in a way that the files will be 3 | overwritten in case WABT contains them in the future. 4 | 5 | Original README: https://github.com/WebAssembly/wabt/blob/master/wasm2c/README.md 6 | -------------------------------------------------------------------------------- /test/binaryen.js/emit_asmjs.js: -------------------------------------------------------------------------------- 1 | var module = new binaryen.Module(); 2 | 3 | module.addFunction("main", binaryen.i32, binaryen.i32, [], module.local.get(0, binaryen.i32)); 4 | 5 | module.addFunctionExport("main", "main"); 6 | 7 | assert(module.validate()); // should validate before calling emitAsmjs 8 | 9 | console.log(module.emitAsmjs()); 10 | -------------------------------------------------------------------------------- /test/metadce/corners.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "ignorable import", 4 | "import": ["non", "existent"] 5 | }, 6 | { 7 | "name": "imported_twice", 8 | "import": ["env", "imported_twice"] 9 | }, 10 | { 11 | "name": "stackAllocGood", 12 | "export": "stackAlloc", 13 | "root": true 14 | } 15 | ] 16 | 17 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | PointerAlignment: Left 5 | IndentCaseLabels: true 6 | ContinuationIndentWidth: 2 7 | ConstructorInitializerIndentWidth: 2 8 | SpaceAfterTemplateKeyword: false 9 | BinPackArguments: false 10 | BinPackParameters: false 11 | --- 12 | Language: JavaScript 13 | DisableFormat: true 14 | --- 15 | -------------------------------------------------------------------------------- /src/support/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB support_HEADERS *.h) 2 | set(support_SOURCES 3 | archive.cpp 4 | bits.cpp 5 | colors.cpp 6 | command-line.cpp 7 | debug.cpp 8 | file.cpp 9 | path.cpp 10 | safe_integer.cpp 11 | threads.cpp 12 | utilities.cpp 13 | ${support_HEADERS} 14 | ) 15 | add_library(support OBJECT ${support_SOURCES}) 16 | -------------------------------------------------------------------------------- /test/lld/main_module_table.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "__stack_pointer" (global $sp (mut i32))) 3 | (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) 4 | (global $global i32 (i32.const 42)) 5 | (export "__stdio_write" (func $__stdio_write)) 6 | (export "__data_end" (global $global)) 7 | (func $__stdio_write 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /test/untaken-br_if.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_f32 (func (result f32))) 3 | (func $binaryify-untaken-br_if (result f32) 4 | (if (result f32) 5 | (i32.const 1) 6 | (unreachable) 7 | (block $label$3 (result f32) 8 | (drop 9 | (f32.const 1) 10 | ) 11 | (unreachable) 12 | ) 13 | ) 14 | ) 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Support/Locale.h: -------------------------------------------------------------------------------- 1 | #ifndef LLVM_SUPPORT_LOCALE_H 2 | #define LLVM_SUPPORT_LOCALE_H 3 | 4 | namespace llvm { 5 | class StringRef; 6 | 7 | namespace sys { 8 | namespace locale { 9 | 10 | int columnWidth(StringRef s); 11 | bool isPrint(int c); 12 | 13 | } 14 | } 15 | } 16 | 17 | #endif // LLVM_SUPPORT_LOCALE_H 18 | -------------------------------------------------------------------------------- /scripts/test/env.js: -------------------------------------------------------------------------------- 1 | // This is the name by which the tests import the wasm table. 2 | export const table = []; 3 | 4 | var tempRet0 = 0; 5 | 6 | export function setTempRet0(x) { 7 | tempRet0 = x; 8 | } 9 | 10 | export function getTempRet0() { 11 | return tempRet0; 12 | } 13 | 14 | export const memoryBase = 0; 15 | export const tableBase = 0; 16 | -------------------------------------------------------------------------------- /test/fn_prolog_epilog.debugInfo.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | ;;@ src.cpp:1:1 4 | (func $0 5 | (nop) 6 | ;;@ src.cpp:2:1 7 | (block $label$1 8 | ;;@ src.cpp:2:2 9 | (block $label$2 10 | (br $label$2) 11 | ) 12 | ) 13 | ;;@ src.cpp:3:1 14 | (return) 15 | ;;@ src.cpp:3:2 16 | ) 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /test/spec/call_indirect_refnull.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (table $t 1 1 funcref) 3 | (elem (table $t) (i32.const 0) funcref (ref.null func)) 4 | 5 | (func $call-refnull (export "call-refnull") (result f32) 6 | (call_indirect (result f32) (i32.const 0)) 7 | ) 8 | ) 9 | (assert_trap 10 | (invoke "call-refnull") 11 | "uninitialized table element" 12 | ) -------------------------------------------------------------------------------- /test/spec/ref_eq.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $compare (export "compare") (param $x eqref) (param $y eqref) (result i32) 3 | (ref.eq 4 | (local.get $x) 5 | (local.get $y) 6 | ) 7 | ) 8 | ) 9 | 10 | ;; All nulls compare equal, regardless of their type. 11 | (assert_return (invoke "compare" (ref.null data) (ref.null eq)) (i32.const 1)) 12 | -------------------------------------------------------------------------------- /test/untaken-br_if.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_f32 (func (result f32))) 3 | (func $binaryify-untaken-br_if (result f32) 4 | (if (result f32) 5 | (i32.const 1) 6 | (unreachable) 7 | (block $label$1 (result f32) 8 | (br_if $label$1 9 | (f32.const 1) 10 | (unreachable) 11 | ) 12 | ) 13 | ) 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Support/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | LLVM System Interface Library 2 | ------------------------------------------------------------------------------- 3 | The LLVM System Interface Library is licensed under the Illinois Open Source 4 | License and has the following additional copyright: 5 | 6 | Copyright (C) 2004 eXtensible Systems, Inc. 7 | -------------------------------------------------------------------------------- /test/fannkuch.txt: -------------------------------------------------------------------------------- 1 | 12345 2 | 21345 3 | 23145 4 | 32145 5 | 31245 6 | 13245 7 | 23415 8 | 32415 9 | 34215 10 | 43215 11 | 42315 12 | 24315 13 | 34125 14 | 43125 15 | 41325 16 | 14325 17 | 13425 18 | 31425 19 | 41235 20 | 14235 21 | 12435 22 | 21435 23 | 24135 24 | 42135 25 | 23451 26 | 32451 27 | 34251 28 | 43251 29 | 42351 30 | 24351 31 | Pfannkuchen(5) = 7. 32 | -------------------------------------------------------------------------------- /test/signext.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (func $signext (type $0) 4 | (local $0 i32) 5 | (local $1 i64) 6 | (drop (i32.extend8_s (local.get $0))) 7 | (drop (i32.extend16_s (local.get $0))) 8 | (drop (i64.extend8_s (local.get $1))) 9 | (drop (i64.extend16_s (local.get $1))) 10 | (drop (i64.extend32_s (local.get $1))) 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /test/metadce/no-outside.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "js_func" (func $a_js_func)) 3 | (import "env" "js_func_unused" (func $an_unused_js_func)) 4 | (export "wasm_func" (func $a_wasm_func)) 5 | (export "wasm_func_unused" (func $an_unused_wasm_func)) 6 | (func $a_wasm_func 7 | (call $a_js_func) 8 | ) 9 | (func $an_unused_wasm_func 10 | ) 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /test/br_to_try.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (type $none_=>_none (func)) 4 | (tag $tag$0 (param i32)) 5 | (func $0 6 | (try $label$3 7 | (do 8 | (block $label$1 9 | (br $label$1) 10 | ) 11 | ) 12 | (catch $tag$0 13 | (drop 14 | (pop i32) 15 | ) 16 | ) 17 | ) 18 | ) 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /test/passes/minify-imports-and-exports-and-modules.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "memory" (memory $0 256 256)) 3 | (import "env" "table" (table $0 4 funcref)) 4 | (import "env" "longname1" (func $internal1)) 5 | (import "env" "longname2" (func $internal2)) 6 | (import "env" "longname3" (func $internal3)) 7 | (import "other" "longname4" (func $internal4)) 8 | ) 9 | -------------------------------------------------------------------------------- /test/passes/vacuum_ignore-implicit-traps.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (type $none_=>_none (func)) 4 | (memory $0 1) 5 | (func $load-would-normally-have-side-effects (result i32) 6 | (i64.ge_s 7 | (i64.const 2912825531628789796) 8 | (i64.const 0) 9 | ) 10 | ) 11 | (func $unary-binary-may-trap 12 | (nop) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle.wast.graph.txt: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "root", 4 | "root": true, 5 | "reaches": ["wasm_export"], 6 | }, 7 | { 8 | "name": "wasm_export", 9 | "export": "wasm_func_a" 10 | }, 11 | { 12 | "name": "outside_js_function", 13 | "reaches": ["wasm_export"], 14 | "import": ["env", "js_func"] 15 | } 16 | ] 17 | 18 | -------------------------------------------------------------------------------- /test/reduce/imports.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "func" (func $import)) 3 | (export "x" (func $x)) 4 | (func $x (result i32) 5 | (nop) 6 | (nop) 7 | (nop) 8 | (call $import) 9 | (drop (i32.const 1234)) 10 | (i32.const 5678) ;; easily reducible 11 | ) 12 | (func $not-exported 13 | (nop) 14 | (unreachable) 15 | ) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /test/ctor-eval/indirect-call3.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (import "env" "tableBase" (global $tableBase i32)) 4 | (import "env" "_abort" (func $_abort)) 5 | (memory $0 256 256) 6 | (data (i32.const 10) "waka waka xaka waka waka\00\00\00\00\00\00C") 7 | (func $call-indirect 8 | (i32.store8 9 | (i32.const 40) 10 | (i32.const 67) 11 | ) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/ctor-eval/just_some.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "wasa waka waka waka waka") 5 | (export "test2" (func $test2)) 6 | (export "test3" (func $test3)) 7 | (func $test2 8 | (unreachable) 9 | ) 10 | (func $test3 11 | (i32.store8 12 | (i32.const 13) 13 | (i32.const 113) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/spec/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/binaryen.js/reloc.js.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "memory_base" (global $memory_base i32)) 4 | (import "env" "table_base" (global $table_base i32)) 5 | (memory $0 1) 6 | (data (global.get $memory_base) "data data") 7 | (table $0 1 funcref) 8 | (elem $0 (global.get $table_base) $func $func) 9 | (func $func 10 | (nop) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/passes/duplicate-import-elimination.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "waka" (func $foo)) 3 | (import "env" "waka" (func $bar)) 4 | (import "env" "waka" (func $wrong (param i32))) 5 | (table 2 2 funcref) 6 | (elem (i32.const 0) $foo $bar) 7 | (start $bar) 8 | (func "baz" 9 | (call $foo) 10 | (call $bar) 11 | (call $wrong (i32.const 1)) 12 | ) 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /test/passes/remove-unused-brs_precompute_vacuum_remove-unused-brs.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_f64 (func (param i32) (result f64))) 3 | (global $global$3 (mut f64) (f64.const 0)) 4 | (func $1 (param $x i32) (result f64) 5 | (local $var$0 f64) 6 | (block $label$0 (result f64) 7 | (local.set $var$0 8 | (f64.const 0) 9 | ) 10 | (f64.const -3.4) 11 | ) 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/spec/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 | -------------------------------------------------------------------------------- /test/break-to-return.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $0)) 5 | (func $0 (param $0 i32) (param $1 i32) (result i32) 6 | (block $label$0 (result i32) 7 | (br $label$0 8 | (i32.add 9 | (local.get $0) 10 | (local.get $1) 11 | ) 12 | ) 13 | ) 14 | ) 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /test/grow_memory.txt: -------------------------------------------------------------------------------- 1 | alloc 1MB: 0 2 | alloc 1MB: 1 3 | alloc 1MB: 2 4 | alloc 1MB: 3 5 | alloc 1MB: 4 6 | alloc 1MB: 5 7 | alloc 1MB: 6 8 | alloc 1MB: 7 9 | alloc 1MB: 8 10 | alloc 1MB: 9 11 | alloc 1MB: 10 12 | alloc 1MB: 11 13 | alloc 1MB: 12 14 | alloc 1MB: 13 15 | alloc 1MB: 14 16 | alloc 1MB: 15 17 | alloc 1MB: 16 18 | alloc 1MB: 17 19 | alloc 1MB: 18 20 | alloc 1MB: 19 21 | ok. 22 | 23 | -------------------------------------------------------------------------------- /test/lit/parse-bad-tuple-extract-index.wast: -------------------------------------------------------------------------------- 1 | ;; Test that out-of-bounds tuple.extract indices produce parse errors. 2 | 3 | ;; RUN: not wasm-opt %s 2>&1 | filecheck %s 4 | 5 | ;; CHECK: [parse exception: Bad index on tuple.extract (at 9:17)] 6 | 7 | (module 8 | (func 9 | (tuple.extract 2 10 | (tuple.make 11 | (i32.const 0) 12 | (i64.const 1) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/break-within-catch.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (type $none_=>_none (func)) 4 | (tag $tag$0 (param i32)) 5 | (func $0 6 | (block $label$2 7 | (try $label$3 8 | (do 9 | (nop) 10 | ) 11 | (catch $tag$0 12 | (drop 13 | (pop i32) 14 | ) 15 | (br $label$2) 16 | ) 17 | ) 18 | ) 19 | ) 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle.wast.dced: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "js_func" (func $a_js_func)) 4 | (memory $0 1 1) 5 | (data "Hello, datacount section!") 6 | (export "wasm_func_a" (func $a_wasm_func)) 7 | (func $a_wasm_func 8 | (memory.init 0 9 | (i32.const 0) 10 | (i32.const 0) 11 | (i32.const 25) 12 | ) 13 | (call $a_js_func) 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /test/lld/recursive.c: -------------------------------------------------------------------------------- 1 | // This test emits a stack pointer, which tests global importing in object files 2 | // (which are mutable and not normally allowed). 3 | 4 | int printf(const char* fmt, ...); 5 | 6 | __attribute__((noinline)) int foo(int a, int b) { 7 | printf("%d:%d\n", a, b); 8 | return a + b; 9 | } 10 | 11 | int main() { 12 | printf("Result: %d\n", foo(1, 2)); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/metadce/threaded_unrooted.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: func$wasm_func_1$0 2 | unused: func$wasm_func_2$1 3 | unused: func$wasm_func_3$2 4 | unused: func$wasm_func_4$3 5 | unused: outside_js_function1 6 | unused: outside_js_function2 7 | unused: outside_js_function3 8 | unused: outside_js_function4 9 | unused: wasm_export1 10 | unused: wasm_export2 11 | unused: wasm_export3 12 | unused: wasm_export4 13 | -------------------------------------------------------------------------------- /test/example/stack-utils.txt: -------------------------------------------------------------------------------- 1 | ;; Test removeNops 2 | (block (result i32 i64) 3 | (nop) 4 | (i32.const 0) 5 | (nop) 6 | (i64.const 0) 7 | (nop) 8 | (nop) 9 | ) 10 | (block (result i32 i64) 11 | (i32.const 0) 12 | (i64.const 0) 13 | ) 14 | ;; Test stack signatures 15 | ;; Test stack signature composition 16 | ;; Test stack signature subtyping 17 | ;; Test stack signature lub 18 | ;; Test stack flow 19 | -------------------------------------------------------------------------------- /test/lld/main_module_table_2.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "__stack_pointer" (global $sp (mut i32))) 3 | (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) 4 | (import "env" "table" (table $timport$9 1 funcref)) 5 | (global $global i32 (i32.const 42)) 6 | (export "__stdio_write" (func $__stdio_write)) 7 | (export "__data_end" (global $global)) 8 | (func $__stdio_write 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/metadce/threaded_unrooted_cycle.wast.dced.stdout: -------------------------------------------------------------------------------- 1 | unused: func$wasm_func_1$0 2 | unused: func$wasm_func_2$1 3 | unused: func$wasm_func_3$2 4 | unused: func$wasm_func_4$3 5 | unused: outside_js_function1 6 | unused: outside_js_function2 7 | unused: outside_js_function3 8 | unused: outside_js_function4 9 | unused: wasm_export1 10 | unused: wasm_export2 11 | unused: wasm_export3 12 | unused: wasm_export4 13 | -------------------------------------------------------------------------------- /test/passes/safe-heap_disable-simd.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1 1) 3 | ) 4 | (module 5 | (memory 1 1) 6 | (import "env" "emscripten_get_sbrk_ptr" (func $foo (result i32))) 7 | ) 8 | (module 9 | (memory 1 1) 10 | (export "emscripten_get_sbrk_ptr" (func $foo)) 11 | (func $foo (result i32) 12 | (drop (i32.load (i32.const 0))) ;; should not be modified! 13 | (i32.const 1234) 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /scripts/strip_local_names.py: -------------------------------------------------------------------------------- 1 | 2 | """Removes local names. When you don't care about local names but do want 3 | to diff for structural changes, this can help. 4 | """ 5 | 6 | import sys 7 | 8 | for line in open(sys.argv[1]).readlines(): 9 | if '(local.tee ' in line or '(local.set ' in line or '(local.get ' in line: 10 | print(line[:line.find('$')]) 11 | else: 12 | print(line.rstrip()) 13 | -------------------------------------------------------------------------------- /test/grow_memory.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32) (result i32))) 3 | (type $1 (func (result i32))) 4 | (memory $0 1) 5 | (export "memory" (memory $0)) 6 | (export "grow" (func $0)) 7 | (export "current" (func $1)) 8 | (func $0 (param $var$0 i32) (result i32) 9 | (memory.grow 10 | (local.get $var$0) 11 | ) 12 | ) 13 | (func $1 (result i32) 14 | (memory.size) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/lit/validation/shared-memory.wast: -------------------------------------------------------------------------------- 1 | ;; Test that shared memory requires atomics 2 | 3 | ;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-ATOMICS 4 | ;; RUN: wasm-opt %s --enable-threads -o - -S | filecheck %s --check-prefix ATOMICS 5 | 6 | ;; NO-ATOMICS: memory is shared, but atomics are disabled 7 | ;; ATOMICS: (memory $0 (shared 10 20)) 8 | 9 | (module 10 | (memory (shared 10 20)) 11 | ) 12 | -------------------------------------------------------------------------------- /test/passes/souperify.wast: -------------------------------------------------------------------------------- 1 | (module 2 | ;; This tests if we can create dataflow graph correctly in the presence of 3 | ;; loops. 4 | (func $if-loop-test (local $0 i32) 5 | (if 6 | (i32.const 0) 7 | (loop $label$0 8 | (local.set $0 9 | (i32.sub 10 | (i32.const 0) 11 | (i32.const 0) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /test/spec/ref_is_null.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $f1 (export "externref") (param $x externref) (result i32) 3 | (ref.is_null (local.get $x)) 4 | ) 5 | (func $f2 (export "funcref") (param $x funcref) (result i32) 6 | (ref.is_null (local.get $x)) 7 | ) 8 | ) 9 | 10 | (assert_return (invoke "externref" (ref.null extern)) (i32.const 1)) 11 | (assert_return (invoke "funcref" (ref.null func)) (i32.const 1)) 12 | -------------------------------------------------------------------------------- /test/tags.wast: -------------------------------------------------------------------------------- 1 | ;; Test tags 2 | 3 | (module 4 | (tag (param i32)) 5 | (tag $e (param i32 f32)) 6 | (tag $empty) 7 | 8 | (tag $e-params0 (param i32 f32)) 9 | (tag $e-params1 (param i32) (param f32)) 10 | 11 | (tag $e-export (export "ex0") (param i32)) 12 | (tag $e-import (import "env" "im0") (param i32)) 13 | 14 | (import "env" "im1" (tag (param i32 f32))) 15 | (export "ex1" (tag $e)) 16 | ) 17 | -------------------------------------------------------------------------------- /test/grow_memory.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32) (result i32))) 3 | (type $1 (func (result i32))) 4 | (memory $0 1) 5 | (export "memory" (memory $0)) 6 | (export "grow" (func $0)) 7 | (export "current" (func $1)) 8 | (func $0 (param $var$0 i32) (result i32) 9 | (memory.grow 10 | (local.get $var$0) 11 | ) 12 | ) 13 | (func $1 (result i32) 14 | (memory.size) 15 | ) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /test/passes/strip-debug.bin.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (import "env" "__linear_memory" (memory $mimport$0 0)) 4 | (import "env" "__indirect_function_table" (table $timport$0 0 funcref)) 5 | (func $0 (result i32) 6 | (local $0 i32) 7 | (local.set $0 8 | (i32.const 1) 9 | ) 10 | (return 11 | (local.get $0) 12 | ) 13 | ) 14 | ;; custom section "zinking", size 28 15 | ) 16 | -------------------------------------------------------------------------------- /test/lit/wasm-split/verbose.wast: -------------------------------------------------------------------------------- 1 | ;; Test that --verbose mode correctly prints the kept and split funcs 2 | 3 | ;; RUN: wasm-split %s --keep-funcs=foo,bar --verbose \ 4 | ;; RUN: -o1 %t1.wasm -o2 %t2.wasm | filecheck %s 5 | 6 | ;; CHECK: Keeping functions: bar, foo{{$}} 7 | ;; CHECK: Splitting out functions: baz, quux{{$}} 8 | 9 | (module 10 | (func $foo) 11 | (func $bar) 12 | (func $baz) 13 | (func $quux) 14 | ) 15 | -------------------------------------------------------------------------------- /test/metadce/spanning_cycle.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1 1) 3 | (data "Hello, datacount section!") 4 | 5 | (import "env" "js_func" (func $a_js_func)) 6 | 7 | (export "wasm_func_a" (func $a_wasm_func)) 8 | 9 | (func $a_wasm_func 10 | ;; refer to the data segment to keep it around 11 | (memory.init 0 12 | (i32.const 0) 13 | (i32.const 0) 14 | (i32.const 25) 15 | ) 16 | (call $a_js_func) 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /test/passes/roundtrip_typenames_features.wast: -------------------------------------------------------------------------------- 1 | ;; This test enables two features, then roundtrips through binary. We should 2 | ;; preserve the features and type names while doing so. 3 | 4 | (module 5 | (type $ref?|$NamedStruct|_=>_none (func (param (ref null $NamedStruct)))) 6 | (type $NamedStruct (struct )) 7 | (export "export" (func $0)) 8 | (func $0 (param $0 (ref null $NamedStruct)) 9 | (nop) 10 | ) 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /test/wasm2js/excess_fallthrough.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "foo" (func $foo)) 3 | (func $bar) 4 | (func $foo (param $0 i32) 5 | (loop $label$4 6 | (block $label$5 7 | (call $bar) 8 | (block 9 | (block $label$7 10 | (br_table $label$7 $label$5 11 | (i32.const 123) 12 | ) 13 | ) 14 | (call $bar) 15 | ) 16 | (return) 17 | ) 18 | (unreachable) 19 | ) 20 | ) 21 | ) 22 | -------------------------------------------------------------------------------- /src/ir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB ir_HEADERS *.h) 2 | set(ir_SOURCES 3 | ExpressionAnalyzer.cpp 4 | ExpressionManipulator.cpp 5 | eh-utils.cpp 6 | intrinsics.cpp 7 | lubs.cpp 8 | names.cpp 9 | properties.cpp 10 | LocalGraph.cpp 11 | ReFinalize.cpp 12 | stack-utils.cpp 13 | table-utils.cpp 14 | type-updating.cpp 15 | module-splitting.cpp 16 | ${ir_HEADERS} 17 | ) 18 | add_library(ir OBJECT ${ir_SOURCES}) 19 | -------------------------------------------------------------------------------- /test/duplicate_types.wast: -------------------------------------------------------------------------------- 1 | (module ;; tests duplicate types are named properly 2 | (type (func)) 3 | (type (func)) 4 | (type (func)) 5 | (type (func (param i32))) 6 | (type $0 (func (param i32))) 7 | (type (func (param i32))) 8 | (type $b (func (param i32) (result f32))) 9 | (type (func (param i32) (result f32))) 10 | 11 | (func $f0 (param i32)) 12 | (func $f1 (param i32) (result i32) 13 | (i32.const 0) 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /test/lld/main_module_table_3.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "__stack_pointer" (global $sp (mut i32))) 3 | (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) 4 | (import "env" "table" (table $timport$9 1 funcref)) 5 | (elem (i32.const 0)) 6 | (global $global i32 (i32.const 42)) 7 | (export "__stdio_write" (func $__stdio_write)) 8 | (export "__data_end" (global $global)) 9 | (func $__stdio_write 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /test/lld/standalone-wasm3.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 2) 3 | (global $global$0 (mut i32) (i32.const 66112)) 4 | (global $global$1 i32 (i32.const 66112)) 5 | (global $global$2 i32 (i32.const 576)) 6 | (export "memory" (memory $0)) 7 | (export "__heap_base" (global $global$1)) 8 | (export "__data_end" (global $global$2)) 9 | (func $__original_main (param $0 i32) (param $1 i32) (result i32) 10 | (nop) 11 | ) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/metadce/rooted-export.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "wasm_func_a" (func $a_wasm_func)) 3 | (export "wasm_func_b" (func $b_wasm_func)) 4 | 5 | (func $a_wasm_func 6 | (unreachable) 7 | ) 8 | (func $b_wasm_func 9 | (unreachable) 10 | ) 11 | 12 | (export "wasm_tag_a" (tag $a_wasm_tag)) 13 | (export "wasm_tag_b" (tag $b_wasm_tag)) 14 | 15 | (tag $a_wasm_tag (param i32)) 16 | (tag $b_wasm_tag (param i32)) 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /test/grow_memory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | volatile int writeOnly; 6 | 7 | int main() { 8 | EM_ASM({ assert(HEAPU8.length == = 16 * 1024 * 1024); }); 9 | for (int i = 0; i < 20; i++) { 10 | printf("alloc 1MB: %d\n", i); 11 | writeOnly = (int)malloc(1024 * 1024); 12 | } 13 | EM_ASM({ assert(HEAPU8.length > 16 * 1024 * 1024); }); 14 | printf("ok.\n"); 15 | } 16 | -------------------------------------------------------------------------------- /test/lit/wasm-split/imported-memory.wast: -------------------------------------------------------------------------------- 1 | ;; RUN: wasm-split --instrument %s -all -S -o - | filecheck %s 2 | 3 | ;; Check that an imported memory is not exported as "profile-memory" 4 | 5 | (module 6 | (import "env" "mem" (memory $mem 1 1)) 7 | ) 8 | 9 | ;; CHECK: (import "env" "mem" (memory $mem 1 1)) 10 | ;; CHECK: (export "__write_profile" (func $__write_profile)) 11 | 12 | ;; CHECK-NOT: (export "profile-memory" (memory $mem)) 13 | -------------------------------------------------------------------------------- /test/example/match.txt: -------------------------------------------------------------------------------- 1 | Testing Internal::Any 2 | Testing Internal::Exact 3 | Testing Internal::{Bool,I32,I64,Int,F32,F64,Float}Lit 4 | Testing Internal::ConstantMatcher 5 | Testing Internal::UnaryMatcher 6 | Testing Internal::UnaryOpMatcher 7 | Testing Internal::AbstractUnaryOpMatcher 8 | Testing Internal::BinaryMatcher 9 | Testing Internal::BinaryOpMatcher 10 | Testing Internal::AbstractBinaryOpMatcher 11 | Testing Internal::SelectMatcher 12 | -------------------------------------------------------------------------------- /test/grow_memory.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (type $none_=>_i32 (func (result i32))) 4 | (memory $0 1) 5 | (export "memory" (memory $0)) 6 | (export "grow" (func $0)) 7 | (export "current" (func $1)) 8 | (func $0 (param $0 i32) (result i32) 9 | (memory.grow 10 | (local.get $0) 11 | ) 12 | ) 13 | (func $1 (result i32) 14 | (memory.size) 15 | ) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /wasi-stub/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | SYSTEM=$(uname) 5 | if [ "${SYSTEM}" = "Linux" ]; then 6 | export LD_LIBRARY_PATH="${SCRIPT_DIR}"/../lib 7 | elif [ "${SYSTEM}" = "Darwin" ]; then 8 | export DYLD_LIBRARY_PATH="${SCRIPT_DIR}"/../lib 9 | else 10 | echo "Unsupported system ${SYSTEM}" 11 | exit 1 12 | fi 13 | "${SCRIPT_DIR}"/wasi-stub $@ 14 | -------------------------------------------------------------------------------- /test/ctor-eval/no_partial.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (data (i32.const 10) "waka waka waka waka waka") 4 | (export "test1" $test1) 5 | (func $test1 6 | (i32.store8 (i32.const 12) (i32.const 115)) ;; a safe store, should alter memory 7 | (unreachable) 8 | (i32.store8 (i32.const 13) (i32.const 114)) ;; a safe store, should alter memory, but we trapped already, and so must roll back the first one too 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /test/grow_memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32) (result i32))) 3 | (type $1 (func (result i32))) 4 | (memory $0 1) 5 | (export "memory" (memory $0)) 6 | (export "grow" (func $0)) 7 | (export "current" (func $1)) 8 | (func $0 (; 0 ;) (type $0) (param $var$0 i32) (result i32) 9 | (memory.grow 10 | (local.get $var$0) 11 | ) 12 | ) 13 | (func $1 (; 1 ;) (type $1) (result i32) 14 | (memory.size) 15 | ) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /test/passes/simplify-locals.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (func $sink-from-inside (result i32) 4 | (local $0 i32) 5 | (local $1 i32) 6 | (local $2 i32) 7 | (nop) 8 | (i32.and 9 | (select 10 | (i32.const 0) 11 | (i32.const 1) 12 | (i32.const 1) 13 | ) 14 | (block $block (result i32) 15 | (nop) 16 | (nop) 17 | (nop) 18 | (i32.const 1) 19 | ) 20 | ) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /test/wasm2js/minus_minus.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (result i32))) 3 | (type $1 (func)) 4 | (export "func_44_invoker" (func $1)) 5 | (func $0 (; 0 ;) (type $0) (result i32) 6 | (i32.trunc_f64_s 7 | (f64.neg 8 | (f64.const -7094) ;; negation of a negative must not be emitted as "--" in js, that will not parse 9 | ) 10 | ) 11 | ) 12 | (func $1 (; 1 ;) (type $1) 13 | (drop 14 | (call $0) 15 | ) 16 | ) 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /test/passes/duplicate-import-elimination.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $i32_=>_none (func (param i32))) 4 | (import "env" "waka" (func $foo)) 5 | (import "env" "waka" (func $wrong (param i32))) 6 | (table $0 2 2 funcref) 7 | (elem (i32.const 0) $foo $foo) 8 | (export "baz" (func $0)) 9 | (start $foo) 10 | (func $0 11 | (call $foo) 12 | (call $foo) 13 | (call $wrong 14 | (i32.const 1) 15 | ) 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /test/passes/strip-target-features_roundtrip_print-features_all-features.wast: -------------------------------------------------------------------------------- 1 | ;; Test that features enabled on the IR Module survive a round trip 2 | ;; even if the target features section is stripped first 3 | 4 | (module 5 | (func $foo (result v128 externref ) 6 | (tuple.make 7 | (v128.const i32x4 0 0 0 0) 8 | (ref.null extern) 9 | ) 10 | ) 11 | (func $bar (result v128 externref) 12 | (return_call $foo) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/lit/stdin-stdout.wast: -------------------------------------------------------------------------------- 1 | ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. 2 | ;; RUN: wasm-opt < %s - -S -o - | filecheck %s 3 | ;; RUN: wasm-opt < %s - -g -o - | wasm-opt - -S -o - | filecheck %s 4 | 5 | ;; Test that file `-` is interpreted as stdin and stdout. 6 | 7 | (module 8 | ;; CHECK: (func $foo 9 | ;; CHECK-NEXT: (nop) 10 | ;; CHECK-NEXT: ) 11 | (func $foo 12 | (nop) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/lit/wasm-split/initial-table.wast: -------------------------------------------------------------------------------- 1 | ;; Test that the --initial-table flag works as expected 2 | 3 | ;; RUN: wasm-split %s --instrument --initial-table=1234 -S | filecheck %s 4 | 5 | ;; RUN: wasm-split %s -g -o1 %t.1.wasm -o2 %t.2.wasm --initial-table=1234 6 | ;; RUN: wasm-dis %t.1.wasm | filecheck %s 7 | ;; RUN: wasm-dis %t.2.wasm | filecheck %s 8 | 9 | ;; CHECK: (table $table 1234 funcref) 10 | 11 | (module 12 | (table $table 3 funcref) 13 | ) 14 | -------------------------------------------------------------------------------- /test/passes/fpcast-emu_pass-arg=max-func-params@5.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $vijfd (func (param i32) (param i64) (param f32) (param f64))) 3 | (table 10 10 funcref) 4 | (elem (i32.const 0) $a) 5 | (func $a (param $x i32) (param $y i64) (param $z f32) (param $w f64) 6 | (call_indirect (type $vijfd) 7 | (i32.const 1) 8 | (i64.const 2) 9 | (f32.const 3) 10 | (f64.const 4) 11 | (i32.const 1337) 12 | ) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/passes/minify-imports-and-exports-and-modules.txt: -------------------------------------------------------------------------------- 1 | memory => a 2 | table => b 3 | longname1 => c 4 | longname2 => d 5 | longname3 => e 6 | longname4 => f 7 | (module 8 | (type $none_=>_none (func)) 9 | (import "a" "a" (memory $0 256 256)) 10 | (import "a" "b" (table $0 4 funcref)) 11 | (import "a" "c" (func $internal1)) 12 | (import "a" "d" (func $internal2)) 13 | (import "a" "e" (func $internal3)) 14 | (import "a" "f" (func $internal4)) 15 | ) 16 | -------------------------------------------------------------------------------- /test/wasm2js/nested-selects.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $dummy) 3 | 4 | (func (export "sign") (param $0 i32) (result i32) 5 | (select 6 | (i32.const -1) 7 | (select 8 | (i32.const 1) 9 | (i32.const 0) 10 | (i32.gt_s 11 | (local.get $0) 12 | (i32.const 0) 13 | ) 14 | ) 15 | (i32.lt_s 16 | (local.get $0) 17 | (i32.const 0) 18 | ) 19 | ) 20 | ) 21 | ) 22 | -------------------------------------------------------------------------------- /test/ctor-eval/imported3.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (data (i32.const 10) "waka waka waka waka waka") 4 | ;; imports must not be used 5 | (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) 6 | (export "test1" $test1) 7 | (global $mine (mut i32) (global.get $tempDoublePtr)) ;; BAD, if used 8 | (func $test1 9 | (drop (global.get $mine)) 10 | (i32.store8 (i32.const 13) (i32.const 115)) ;; we never get here. 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /test/passes/emit-spec-wrapper=a.wat.wast.wat: -------------------------------------------------------------------------------- 1 | (invoke "hangLimitInitializer") (invoke "add" (i32.const 0) (i32.const 0) ) (invoke "hangLimitInitializer") (invoke "no_return" (i32.const 0) ) (invoke "hangLimitInitializer") (invoke "types" (i32.const 0) (i64.const 0) (f32.const 0) (f64.const 0) ) (invoke "hangLimitInitializer") (invoke "types2" (i32.const 0) (f32.const 0) (f64.const 0) ) (invoke "hangLimitInitializer") (invoke "types3" (i32.const 0) (f32.const 0) (f64.const 0) ) -------------------------------------------------------------------------------- /test/wasm2js/reinterpret_scratch.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1 1) 3 | (func "foo" (result i32) 4 | (local $0 f32) 5 | (i64.store align=4 6 | (i32.reinterpret_f32 ;; i32 0 7 | (local.get $0) ;; f32 0 8 | ) 9 | (i64.reinterpret_f64 ;; these two reinterprets must not interfere with 10 | (f64.const 0x12345678) ;; each other, even though both use scratch memory 11 | ) 12 | ) 13 | (i32.load 14 | (i32.const 0) 15 | ) 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /wasi-stub/README.md: -------------------------------------------------------------------------------- 1 | # WASI-STUB 2 | 3 | This tool takes a wasm file, replace all `wasi_snapshot_preview1` import to (stub) functions defines in the same module. This is useful when executing wasm in sandbox enviroment where wasi is not available. 4 | 5 | ## Build 6 | 7 | First build binaryen with `cmake . && make -j`. Then: 8 | ``` 9 | ./build.sh 10 | ``` 11 | 12 | ## Use 13 | 14 | ``` 15 | ./run.sh file.wasm 16 | ``` 17 | 18 | The tool will write file.wasm inplace. -------------------------------------------------------------------------------- /test/passes/souperify.txt: -------------------------------------------------------------------------------- 1 | 2 | ; function: if-loop-test 3 | 4 | ; start LHS (in if-loop-test) 5 | %0 = sub 0:i32, 0:i32 6 | %1 = ne 0:i32, 0:i32 7 | pc %1 1:i1 8 | infer %0 9 | 10 | (module 11 | (type $none_=>_none (func)) 12 | (func $if-loop-test 13 | (local $0 i32) 14 | (if 15 | (i32.const 0) 16 | (loop $label$0 17 | (local.set $0 18 | (i32.sub 19 | (i32.const 0) 20 | (i32.const 0) 21 | ) 22 | ) 23 | ) 24 | ) 25 | ) 26 | ) 27 | -------------------------------------------------------------------------------- /test/spec/call_indirect_sig_mismatch.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $funcref_=>_none (func (param funcref))) 3 | (table funcref (elem $callee)) 4 | (export "sig_mismatch" (func $sig_mismatch)) 5 | (func $callee (param $0 externref)) 6 | (func $sig_mismatch 7 | (call_indirect (type $funcref_=>_none) 8 | (ref.null func) 9 | (i32.const 0) 10 | ) 11 | ) 12 | ) 13 | 14 | (assert_trap (invoke "sig_mismatch") "callIndirect: function signatures don't match") 15 | -------------------------------------------------------------------------------- /test/stacky.wasm.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 3 | (memory $0 256 256) 4 | (export "add" (func $0)) 5 | (func $0 (param $0 i32) (param $1 i32) (result i32) 6 | (local $2 i32) 7 | (i32.add 8 | (block (result i32) 9 | (local.set $2 10 | (local.get $0) 11 | ) 12 | (local.set $0 13 | (i32.const 100) 14 | ) 15 | (local.get $2) 16 | ) 17 | (local.get $1) 18 | ) 19 | ) 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_call.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 256 256) 3 | (data (i32.const 10) "waka waka waka waka waka") 4 | (export "test1" $test1) 5 | (func $test1 6 | (call $unsafe-to-call) ;; unsafe to call 7 | (i32.store (i32.const 12) (i32.const 115)) ;; a safe store, should alter memory 8 | (i32.store16 (i32.const 20) (i32.const 31353)) 9 | (i32.store8 (i32.const 23) (i32.const 120)) 10 | ) 11 | (func $unsafe-to-call 12 | (unreachable) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/lld/main_module_table_4.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "__stack_pointer" (global $sp (mut i32))) 3 | (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) 4 | (import "env" "__table_base" (global $tb i32)) 5 | (import "env" "table" (table $timport$9 1 funcref)) 6 | (elem (global.get $tb)) 7 | (global $global i32 (i32.const 42)) 8 | (export "__stdio_write" (func $__stdio_write)) 9 | (export "__data_end" (global $global)) 10 | (func $__stdio_write 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /test/passes/remove-unused-brs_generate-stack-ir_print-stack-ir.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i64))) 3 | (func $0 (; 0 ;) (type $0) (param $var$0 i64) 4 | (block $label$1 5 | (br_if $label$1 6 | (block $label$2 (result i32) 7 | (loop $label$3 8 | (local.set $var$0 9 | (block $label$4 (result i64) 10 | (unreachable) 11 | ) 12 | ) 13 | ) 14 | (unreachable) 15 | ) 16 | ) 17 | (nop) 18 | ) 19 | ) 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /test/passes/precompute_coalesce-locals_vacuum.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $nested-br_if-value (param $var$0 i32) (result i32) 3 | (local $1 i32) 4 | (local $2 i32) 5 | (loop $label$0 (result i32) 6 | (drop 7 | (i32.const 2) 8 | ) 9 | (block (result i32) 10 | (local.set $2 11 | (i32.const 4) 12 | ) 13 | (br_if $label$0 ;; precomputing this into a br must change the type 14 | (i32.const 1) 15 | ) 16 | (local.get $2) 17 | ) 18 | ) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (memory 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (table 1 1 funcref) 6 | (elem (i32.const 0) $call-indirect) 7 | (export "test1" $test1) 8 | (func $test1 9 | (call_indirect (type $v) (i32.const 1)) ;; unsafe to call, out of range 10 | (i32.store8 (i32.const 20) (i32.const 120)) 11 | ) 12 | (func $call-indirect 13 | (i32.store8 (i32.const 40) (i32.const 67)) 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /test/newsyntax.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $i32_f64_=>_i32 (func (param i32 f64) (result i32))) 4 | (import "env" "table" (table $timport$0 9 9 funcref)) 5 | (export "call_indirect" (func $0)) 6 | (func $0 7 | (drop 8 | (call_indirect $timport$0 (type $i32_f64_=>_i32) 9 | (i32.const 10) 10 | (f64.const 20) 11 | (i32.const 30) 12 | ) 13 | ) 14 | (call_indirect $timport$0 (type $none_=>_none) 15 | (i32.const 1) 16 | ) 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /test/passes/remove-imports.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $FUNCSIG$v (func)) 3 | (import "env" "table" (table $table 1 1 funcref)) 4 | (import "env" "memBase" (global $gimport$0 i32)) 5 | (import "somewhere" "waka-sneaky" (func $waka-sneaky)) 6 | (memory $0 1024 1024) 7 | (elem (i32.const 0) $waka-sneaky) 8 | (func $nada 9 | (nop) 10 | (drop 11 | (i32.const 0) 12 | ) 13 | (drop 14 | (f64.const 0) 15 | ) 16 | (call_indirect (type $FUNCSIG$v) 17 | (i32.const 0) 18 | ) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /test/tags.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_f32_=>_none (func (param i32 f32))) 3 | (type $i32_=>_none (func (param i32))) 4 | (type $none_=>_none (func)) 5 | (import "env" "im0" (tag $e-import (param i32))) 6 | (import "env" "im1" (tag $eimport$1 (param i32 f32))) 7 | (tag $2 (param i32)) 8 | (tag $e (param i32 f32)) 9 | (tag $empty (param)) 10 | (tag $e-params0 (param i32 f32)) 11 | (tag $e-params1 (param i32 f32)) 12 | (tag $e-export (param i32)) 13 | (export "ex1" (tag $e)) 14 | ) 15 | -------------------------------------------------------------------------------- /third_party/llvm-project/include/llvm/Support/ReverseIteration.h: -------------------------------------------------------------------------------- 1 | #ifndef LLVM_SUPPORT_REVERSEITERATION_H 2 | #define LLVM_SUPPORT_REVERSEITERATION_H 3 | 4 | #include "llvm/Config/abi-breaking.h" 5 | #include "llvm/Support/PointerLikeTypeTraits.h" 6 | 7 | namespace llvm { 8 | 9 | template 10 | bool shouldReverseIterate() { 11 | #if LLVM_ENABLE_REVERSE_ITERATION 12 | return detail::IsPointerLike::value; 13 | #else 14 | return false; 15 | #endif 16 | } 17 | 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /test/calls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" { 4 | 5 | int inner(int x) { return x * x + 2; } 6 | 7 | int EMSCRIPTEN_KEEPALIVE simple(int x) { return inner(x); } 8 | 9 | int EMSCRIPTEN_KEEPALIVE fibo(int x) { 10 | if (x == 0 || x == 1) 11 | return 1; 12 | return fibo(x - 1) + fibo(x - 2); 13 | } 14 | 15 | int EMSCRIPTEN_KEEPALIVE run_script() { 16 | emscripten_run_script("Module.print('hello from called script')"); 17 | return emscripten_run_script_int("1+2+3+4-1"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/newsyntax.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $i32_f64_=>_i32 (func (param i32 f64) (result i32))) 4 | (import "env" "table" (table $timport$0 9 9 funcref)) 5 | (export "call_indirect" (func $0)) 6 | (func $0 7 | (drop 8 | (call_indirect $timport$0 (type $i32_f64_=>_i32) 9 | (i32.const 10) 10 | (f64.const 20) 11 | (i32.const 30) 12 | ) 13 | ) 14 | (call_indirect $timport$0 (type $none_=>_none) 15 | (i32.const 1) 16 | ) 17 | ) 18 | ) 19 | 20 | -------------------------------------------------------------------------------- /test/passes/legalize-js-interface-minimally.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "imported" (func $imported (result i64))) 3 | (import "env" "invoke_vj" (func $invoke_vj (param i64))) 4 | (export "func" (func $func)) 5 | (export "dynCall_foo" (func $dyn)) 6 | (func $func (result i64) 7 | (drop (call $imported)) 8 | (call $invoke_vj (i64.const 0)) 9 | (unreachable) 10 | ) 11 | (func $dyn (result i64) 12 | (drop (call $imported)) 13 | (unreachable) 14 | ) 15 | ) 16 | (module) 17 | 18 | -------------------------------------------------------------------------------- /test/tags.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_f32_=>_none (func (param i32 f32))) 3 | (type $i32_=>_none (func (param i32))) 4 | (type $none_=>_none (func)) 5 | (import "env" "im0" (tag $eimport$0 (param i32))) 6 | (import "env" "im1" (tag $eimport$1 (param i32 f32))) 7 | (tag $tag$0 (param i32)) 8 | (tag $tag$1 (param i32 f32)) 9 | (tag $tag$2 (param)) 10 | (tag $tag$3 (param i32 f32)) 11 | (tag $tag$4 (param i32 f32)) 12 | (tag $tag$5 (param i32)) 13 | (export "ex1" (tag $tag$1)) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/binaryen.js/tag.js.txt: -------------------------------------------------------------------------------- 1 | GetTag is equal: true 2 | getTagInfo={"name":"a-tag","module":"","base":"","params":2,"results":0} 3 | (module 4 | (type $i32_=>_none (func (param i32))) 5 | (type $i32_f32_=>_none (func (param i32 f32))) 6 | (import "module" "base" (tag $a-tag-imp (param i32 f32))) 7 | (tag $a-tag (param i32)) 8 | (export "a-tag-exp" (tag $a-tag)) 9 | ) 10 | 11 | (module 12 | (type $i32_f32_=>_none (func (param i32 f32))) 13 | (import "module" "base" (tag $a-tag-imp (param i32 f32))) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/lit/passes/roundtrip-table.wast: -------------------------------------------------------------------------------- 1 | ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. 2 | ;; RUN: wasm-opt %s -all --roundtrip -S -o - 3 | 4 | (module 5 | (type $functype (func)) 6 | (table $0 48 funcref) 7 | ;; a type that appears in the table and nowhere else. this test checks that 8 | ;; we do not crash during the roundtrip on seeing an unexpected type that 9 | ;; collectHeapTypes() did not scan. 10 | (elem (table $0) (i32.const 0) funcref (ref.null $functype)) 11 | ) 12 | -------------------------------------------------------------------------------- /test/newsyntax.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $i32_f64_=>_i32 (func (param i32 f64) (result i32))) 4 | (import "env" "table" (table $timport$0 9 9 funcref)) 5 | (export "call_indirect" (func $0)) 6 | (func $0 7 | (drop 8 | (call_indirect $timport$0 (type $i32_f64_=>_i32) 9 | (i32.const 10) 10 | (f64.const 20) 11 | (i32.const 30) 12 | ) 13 | ) 14 | (call_indirect $timport$0 (type $none_=>_none) 15 | (i32.const 1) 16 | ) 17 | ) 18 | ) 19 | 20 | -------------------------------------------------------------------------------- /test/passes/O1_print-stack-ir.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "stacky-help" (func $stacky-help)) 3 | (func $stacky-help (param $x i32) (result i32) 4 | (local $temp i32) 5 | (i32.add 6 | (call $stacky-help (i32.const 0)) 7 | (i32.eqz 8 | (block (result i32) ;; after we use the stack instead of the local, we can remove this block 9 | (local.set $temp (call $stacky-help (i32.const 1))) 10 | (drop (call $stacky-help (i32.const 2))) 11 | (local.get $temp) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/passes/O2_print-stack-ir.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "stacky-help" (func $stacky-help)) 3 | (func $stacky-help (param $x i32) (result i32) 4 | (local $temp i32) 5 | (i32.add 6 | (call $stacky-help (i32.const 0)) 7 | (i32.eqz 8 | (block (result i32) ;; after we use the stack instead of the local, we can remove this block 9 | (local.set $temp (call $stacky-help (i32.const 1))) 10 | (drop (call $stacky-help (i32.const 2))) 11 | (local.get $temp) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/passes/O3_print-stack-ir.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "stacky-help" (func $stacky-help)) 3 | (func $stacky-help (param $x i32) (result i32) 4 | (local $temp i32) 5 | (i32.add 6 | (call $stacky-help (i32.const 0)) 7 | (i32.eqz 8 | (block (result i32) ;; after we use the stack instead of the local, we can remove this block 9 | (local.set $temp (call $stacky-help (i32.const 1))) 10 | (drop (call $stacky-help (i32.const 2))) 11 | (local.get $temp) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/passes/remove-unused-names_precompute.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (memory $0 256 256) 4 | (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) 5 | (block $switch-default 6 | (nop) 7 | (block 8 | (i32.store 9 | (i32.const 12) 10 | (i32.const 26) 11 | ) 12 | (return) 13 | ) 14 | ) 15 | (block 16 | (local.set $$0 17 | (i32.const 4) 18 | ) 19 | (i32.store 20 | (local.get $$0) 21 | (i32.const 1) 22 | ) 23 | ) 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /test/signext.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (func $signext 4 | (local $0 i32) 5 | (local $1 i64) 6 | (drop 7 | (i32.extend8_s 8 | (local.get $0) 9 | ) 10 | ) 11 | (drop 12 | (i32.extend16_s 13 | (local.get $0) 14 | ) 15 | ) 16 | (drop 17 | (i64.extend8_s 18 | (local.get $1) 19 | ) 20 | ) 21 | (drop 22 | (i64.extend16_s 23 | (local.get $1) 24 | ) 25 | ) 26 | (drop 27 | (i64.extend32_s 28 | (local.get $1) 29 | ) 30 | ) 31 | ) 32 | ) 33 | -------------------------------------------------------------------------------- /test/tags.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_f32_=>_none (func (param i32 f32))) 3 | (type $i32_=>_none (func (param i32))) 4 | (type $none_=>_none (func)) 5 | (import "env" "im0" (tag $eimport$0 (param i32))) 6 | (import "env" "im1" (tag $eimport$1 (param i32 f32))) 7 | (tag $tag$0 (param i32)) 8 | (tag $tag$1 (param i32 f32)) 9 | (tag $tag$2 (param)) 10 | (tag $tag$3 (param i32 f32)) 11 | (tag $tag$4 (param i32 f32)) 12 | (tag $tag$5 (param i32)) 13 | (export "ex1" (tag $tag$1)) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /test/ctor-eval/imported2.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (global $mine (mut i32) (i32.const 1)) 4 | (memory $0 256 256) 5 | (data (i32.const 10) "wasa waka waka waka waka") 6 | (export "test2" (func $test2)) 7 | (export "test3" (func $test3)) 8 | (func $test2 9 | (global.set $mine 10 | (i32.const 2) 11 | ) 12 | (i32.store8 13 | (i32.const 13) 14 | (i32.const 115) 15 | ) 16 | ) 17 | (func $test3 18 | (i32.store8 19 | (i32.const 14) 20 | (i32.const 115) 21 | ) 22 | ) 23 | ) 24 | -------------------------------------------------------------------------------- /test/lld/standalone-wasm-with-start.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 2) 3 | (table $0 1 1 funcref) 4 | (elem (i32.const 0) $foo) 5 | (global $global$0 (mut i32) (i32.const 66112)) 6 | (global $global$1 i32 (i32.const 66112)) 7 | (global $global$2 i32 (i32.const 576)) 8 | (export "memory" (memory $0)) 9 | (export "_start" (func $_start)) 10 | (export "__heap_base" (global $global$1)) 11 | (export "__data_end" (global $global$2)) 12 | (func $_start (result i32) 13 | (nop) 14 | ) 15 | (func $foo (result i32)) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /test/passes/pick-load-signs_all-features.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 (shared 16 16)) 3 | (func $atomics-are-always-unsigned (result i32) 4 | (local $0 i32) 5 | (drop 6 | (block (result i32) 7 | (local.set $0 8 | (i32.atomic.load16_u ;; an atomic load cannot become signed 9 | (i32.const 27) 10 | ) 11 | ) 12 | (i32.shr_s 13 | (i32.shl 14 | (local.get $0) 15 | (i32.const 16) 16 | ) 17 | (i32.const 16) 18 | ) 19 | ) 20 | ) 21 | (i32.const -65) 22 | ) 23 | ) 24 | -------------------------------------------------------------------------------- /test/binaryen.js/pass-arguments.js: -------------------------------------------------------------------------------- 1 | assert(binaryen.getPassArgument("theKey") === null); 2 | 3 | binaryen.setPassArgument("theKey", "theValue"); 4 | assert(binaryen.getPassArgument("theKey") === "theValue"); 5 | 6 | binaryen.setPassArgument("theKey", null); 7 | assert(binaryen.getPassArgument("theKey") === null); 8 | 9 | binaryen.setPassArgument("theKey", "theValue2"); 10 | assert(binaryen.getPassArgument("theKey") === "theValue2"); 11 | 12 | binaryen.clearPassArguments(); 13 | assert(binaryen.getPassArgument("theKey") === null); 14 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (table $0 1 1 funcref) 6 | (elem (i32.const 0) $call-indirect) 7 | (export "test1" (func $test1)) 8 | (func $test1 9 | (call_indirect $0 (type $v) 10 | (i32.const 1) 11 | ) 12 | (i32.store8 13 | (i32.const 20) 14 | (i32.const 120) 15 | ) 16 | ) 17 | (func $call-indirect 18 | (i32.store8 19 | (i32.const 40) 20 | (i32.const 67) 21 | ) 22 | ) 23 | ) 24 | -------------------------------------------------------------------------------- /test/ctor-eval/unsafe_call.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (export "test1" (func $test1)) 6 | (func $test1 7 | (call $unsafe-to-call) 8 | (i32.store 9 | (i32.const 12) 10 | (i32.const 115) 11 | ) 12 | (i32.store16 13 | (i32.const 20) 14 | (i32.const 31353) 15 | ) 16 | (i32.store8 17 | (i32.const 23) 18 | (i32.const 120) 19 | ) 20 | ) 21 | (func $unsafe-to-call 22 | (unreachable) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /test/signext.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func)) 3 | (func $signext 4 | (local $0 i32) 5 | (local $1 i64) 6 | (drop 7 | (i32.extend8_s 8 | (local.get $0) 9 | ) 10 | ) 11 | (drop 12 | (i32.extend16_s 13 | (local.get $0) 14 | ) 15 | ) 16 | (drop 17 | (i64.extend8_s 18 | (local.get $1) 19 | ) 20 | ) 21 | (drop 22 | (i64.extend16_s 23 | (local.get $1) 24 | ) 25 | ) 26 | (drop 27 | (i64.extend32_s 28 | (local.get $1) 29 | ) 30 | ) 31 | ) 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /test/calls.post.js: -------------------------------------------------------------------------------- 1 | 2 | function test(name) { 3 | Module.print(name); 4 | function doTest(x) { 5 | Module.print(' ' + [x] + ' ==> ' + Module['_' + name](x)); 6 | } 7 | doTest(1); 8 | doTest(2); 9 | doTest(3); 10 | doTest(4); 11 | doTest(7); 12 | } 13 | 14 | test('simple'); 15 | test('fibo'); 16 | 17 | Module.print('run_script'); 18 | Module.print(Module['_run_script']()); 19 | 20 | Module.print('too many/few arguments'); 21 | Module.print(Module['_simple']()); 22 | Module.print(Module['_simple'](10, 20)); 23 | 24 | -------------------------------------------------------------------------------- /test/passes/reorder-locals_print_roundtrip.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (func $a 3 | (local $x i32) 4 | (local $y f64) 5 | ;; x appears twice 6 | (drop (local.get $x)) 7 | (drop (local.get $x)) 8 | (drop (local.get $y)) 9 | ) 10 | (func $b 11 | (local $x i32) 12 | (local $y f64) 13 | ;; y appears twice, so it will be reordered to be first, and that should be 14 | ;; preserved in the binary format 15 | (drop (local.get $x)) 16 | (drop (local.get $y)) 17 | (drop (local.get $y)) 18 | ) 19 | ) 20 | -------------------------------------------------------------------------------- /test/passes/simplify-globals_all-features_fuzz-exec.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (global $global$0 (mut funcref) (ref.null func)) 3 | (func $0 (param $0 f32) (param $1 i31ref) (param $2 i64) (param $3 f64) (param $4 funcref) 4 | (nop) 5 | ) 6 | (func "export" (result funcref) 7 | ;; this set's value will be applied to the get right after it. we should carry 8 | ;; over the specific typed function reference type properly while doing so. 9 | (global.set $global$0 10 | (ref.func $0) 11 | ) 12 | (global.get $global$0) 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /test/reduce/memory_table.wast.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (type $none_=>_none (func)) 4 | (memory $0 256 256) 5 | (export "f1" (func $0)) 6 | (export "f2" (func $1)) 7 | (export "f4" (func $2)) 8 | (func $0 9 | (nop) 10 | ) 11 | (func $1 (result i32) 12 | (i32.store 13 | (i32.const 0) 14 | (i32.const 65530) 15 | ) 16 | (i32.load 17 | (i32.const 0) 18 | ) 19 | ) 20 | (func $2 (result i32) 21 | (i32.add 22 | (call $1) 23 | (i32.const 1234) 24 | ) 25 | ) 26 | ) 27 | 28 | -------------------------------------------------------------------------------- /test/wasm2js/if_unreachable.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32 i32 i32 i32 i32 i32))) 3 | (import "env" "table" (table $timport$0 6 funcref)) 4 | (func $0 (; 0 ;) (type $0) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (param $5 i32) 5 | (if 6 | (i32.ne 7 | (i32.const 0) 8 | (i32.const 48) 9 | ) 10 | (block $label$2 11 | (br_if $label$2 12 | (i32.const 0) 13 | ) 14 | (unreachable) 15 | ) 16 | (unreachable) 17 | ) 18 | (unreachable) 19 | ) 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /test/passes/Os_print-stack-ir_all-features_disable-gc.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "stacky-help" (func $stacky-help)) 3 | (func $stacky-help (param $x i32) (result i32) 4 | (local $temp i32) 5 | (i32.add 6 | (call $stacky-help (i32.const 0)) 7 | (i32.eqz 8 | (block (result i32) ;; after we use the stack instead of the local, we can remove this block 9 | (local.set $temp (call $stacky-help (i32.const 1))) 10 | (drop (call $stacky-help (i32.const 2))) 11 | (local.get $temp) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/passes/pick-load-signs_all-features.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 (shared 16 16)) 4 | (func $atomics-are-always-unsigned (result i32) 5 | (local $0 i32) 6 | (drop 7 | (block $block (result i32) 8 | (local.set $0 9 | (i32.atomic.load16_u 10 | (i32.const 27) 11 | ) 12 | ) 13 | (i32.shr_s 14 | (i32.shl 15 | (local.get $0) 16 | (i32.const 16) 17 | ) 18 | (i32.const 16) 19 | ) 20 | ) 21 | ) 22 | (i32.const -65) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /test/unreachable-instr-type.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 (shared 1 1)) 4 | (func $test 5 | (i32.load 6 | (unreachable) 7 | ) 8 | (f32.store 9 | (unreachable) 10 | (f32.const 0) 11 | ) 12 | (i32.atomic.rmw.add 13 | (unreachable) 14 | (i64.const 0) 15 | ) 16 | (i32.atomic.rmw.cmpxchg 17 | (unreachable) 18 | (i64.const 0) 19 | (i64.const 1) 20 | ) 21 | (memory.atomic.wait64 22 | (unreachable) 23 | (i64.const 0) 24 | (i64.const 0) 25 | ) 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /test/binaryen.js/functions.js.txt: -------------------------------------------------------------------------------- 1 | GetFunction is equal: true 2 | getFunctionInfo={"module":"","base":"","params":0,"results":2,"vars":[]} 3 | getExpressionInfo(body)={"id":14,"value":3} 4 | (i32.const 3) 5 | 6 | (module 7 | ) 8 | 9 | (module 10 | (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) 11 | (func $b-function (param $a i32) (param $b i32) (result i32) 12 | (local $res i32) 13 | (local $unused f64) 14 | (local.tee $res 15 | (i32.add 16 | (local.get $a) 17 | (local.get $b) 18 | ) 19 | ) 20 | ) 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /test/binaryen.js/sideffects.js.txt: -------------------------------------------------------------------------------- 1 | SideEffects.None=0 2 | SideEffects.Branches=1 3 | SideEffects.Calls=2 4 | SideEffects.ReadsLocal=4 5 | SideEffects.WritesLocal=8 6 | SideEffects.ReadsGlobal=16 7 | SideEffects.WritesGlobal=32 8 | SideEffects.ReadsMemory=64 9 | SideEffects.WritesMemory=128 10 | SideEffects.ReadsTable=256 11 | SideEffects.WritesTable=512 12 | SideEffects.ImplicitTrap=1024 13 | SideEffects.IsAtomic=2048 14 | SideEffects.Throws=4096 15 | SideEffects.DanglingPop=8192 16 | SideEffects.TrapsNeverHappen=16384 17 | SideEffects.Any=32767 18 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call2.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (memory 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (import "env" "_abort" (func $_abort)) 6 | (table 2 2 funcref) 7 | (elem (i32.const 0) $_abort $call-indirect) 8 | (export "test1" $test1) 9 | (func $test1 10 | (call_indirect (type $v) (i32.const 0)) ;; unsafe to call, imported 11 | (i32.store8 (i32.const 20) (i32.const 120)) 12 | ) 13 | (func $call-indirect 14 | (i32.store8 (i32.const 40) (i32.const 67)) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/nonspec-bulk-memory.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1024 1024 3 | (segment 0 "hello, world") 4 | ) 5 | (func $memory.init 6 | (memory.init 0 7 | (i32.const 512) 8 | (i32.const 0) 9 | (i32.const 12) 10 | ) 11 | ) 12 | (func $data.drop 13 | (data.drop 0) 14 | ) 15 | (func $memory.copy 16 | (memory.copy 17 | (i32.const 512) 18 | (i32.const 0) 19 | (i32.const 12) 20 | ) 21 | ) 22 | (func $memory.fill 23 | (memory.fill 24 | (i32.const 0) 25 | (i32.const 42) 26 | (i32.const 1024) 27 | ) 28 | ) 29 | ) 30 | -------------------------------------------------------------------------------- /test/passes/roundtrip_signed.bin.txt: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (global $global$0 (mut i32) (i32.const 10)) 4 | (memory $0 16 17) 5 | (export "as-br_table-index" (func $0)) 6 | (export "as-local.set-value" (func $0)) 7 | (func $0 8 | (if 9 | (i32.eqz 10 | (global.get $global$0) 11 | ) 12 | (return) 13 | ) 14 | (global.set $global$0 15 | (i32.sub 16 | (global.get $global$0) 17 | (i32.const 1) 18 | ) 19 | ) 20 | (drop 21 | (i32.load 22 | (i32.const 0) 23 | ) 24 | ) 25 | ) 26 | ) 27 | -------------------------------------------------------------------------------- /test/signext.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (func $0 4 | (local $0 i32) 5 | (local $1 i64) 6 | (drop 7 | (i32.extend8_s 8 | (local.get $0) 9 | ) 10 | ) 11 | (drop 12 | (i32.extend16_s 13 | (local.get $0) 14 | ) 15 | ) 16 | (drop 17 | (i64.extend8_s 18 | (local.get $1) 19 | ) 20 | ) 21 | (drop 22 | (i64.extend16_s 23 | (local.get $1) 24 | ) 25 | ) 26 | (drop 27 | (i64.extend32_s 28 | (local.get $1) 29 | ) 30 | ) 31 | ) 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call3.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $funcref_=>_none (func (param funcref))) 3 | (memory 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (table funcref (elem $callee)) 6 | (export "sig_mismatch" (func $sig_mismatch)) 7 | (func $callee (param $0 externref) 8 | (i32.store8 (i32.const 40) (i32.const 67)) 9 | ) 10 | (func $sig_mismatch 11 | (call_indirect (type $funcref_=>_none) ;; unsafe to call, signature mismatch 12 | (ref.null func) 13 | (i32.const 0) 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /test/lld/main_module_table_5.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "__stack_pointer" (global $sp (mut i32))) 3 | (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) 4 | (import "env" "__table_base" (global $tb i32)) 5 | (import "env" "table" (table $timport$9 1 funcref)) 6 | (elem (global.get $tb) $other $stuff) 7 | (global $global i32 (i32.const 42)) 8 | (export "__stdio_write" (func $__stdio_write)) 9 | (export "__data_end" (global $global)) 10 | (func $__stdio_write 11 | ) 12 | (func $other 13 | ) 14 | (func $stuff 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /scripts/test/spectest.js: -------------------------------------------------------------------------------- 1 | export function print() { 2 | console.log(); 3 | } 4 | export function print_i32(arg) { 5 | console.log(arg, ': i32'); 6 | } 7 | export function print_f32(arg) { 8 | console.log(arg, ': f32'); 9 | } 10 | export function print_f64(arg) { 11 | console.log(arg, ': f64'); 12 | } 13 | export function print_i32_f32(arg0, arg1) { 14 | console.log(arg0, ': i32'); 15 | console.log(arg1, ': f32'); 16 | } 17 | export function print_f64_f64(arg0, arg1) { 18 | console.log(arg0, ': f64'); 19 | console.log(arg1, ': f64'); 20 | } 21 | -------------------------------------------------------------------------------- /test/unreachable-instr-type.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory (shared 1 1)) 3 | (func $test 4 | (f32.load (unreachable)) 5 | 6 | (f32.store 7 | (unreachable) 8 | (f32.const 0) 9 | ) 10 | 11 | (i64.atomic.rmw.add 12 | (unreachable) 13 | (i64.const 0) 14 | ) 15 | 16 | (i64.atomic.rmw.cmpxchg 17 | (unreachable) 18 | (i64.const 0) 19 | (i64.const 1) 20 | ) 21 | 22 | (memory.atomic.wait64 23 | (unreachable) 24 | (i64.const 0) 25 | (i64.const 0) 26 | ) 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /test/passes/stack-check_enable-mutable-globals.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (import "env" "__stack_pointer" (global $sp (mut i32))) 3 | (func "use_stack" (result i32) 4 | (global.set $sp (i32.const 42)) 5 | (global.get $sp) 6 | ) 7 | ) 8 | ;; if the global names are taken we should not crash 9 | (module 10 | (import "env" "__stack_pointer" (global $sp (mut i32))) 11 | (global $__stack_base (mut i32) (i32.const 0)) 12 | (global $__stack_limit (mut i32) (i32.const 0)) 13 | (export "use_stack" (func $0)) 14 | (func $0 (result i32) 15 | (unreachable) 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /test/unit/input/asyncify-stackOverflow.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1 2) 3 | (import "env" "sleep" (func $sleep)) 4 | (export "memory" (memory 0)) 5 | (func "many_locals" (param $x i32) (result i32) 6 | (local $y i32) 7 | (local $z i32) 8 | (local.set $y 9 | (i32.add (local.get $x) (i32.const 10)) 10 | ) 11 | (local.set $z 12 | (i32.add (local.get $y) (i32.const 20)) 13 | ) 14 | (call $sleep) 15 | (select 16 | (local.get $y) 17 | (local.get $z) 18 | (local.get $x) 19 | ) 20 | ) 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /test/binaryen.js/global.js.txt: -------------------------------------------------------------------------------- 1 | GetGlobal is equal: true 2 | getGlobalInfo={"module":"","base":"","mutable":false} 3 | getExpressionInfo(init)={"id":14,"value":1} 4 | (i32.const 1) 5 | 6 | (module 7 | (import "module" "base" (global $a-global-imp i32)) 8 | (import "module" "base" (global $a-mut-global-imp (mut i32))) 9 | (global $a-global i32 (i32.const 1)) 10 | (export "a-global-exp" (global $a-global)) 11 | ) 12 | 13 | (module 14 | (import "module" "base" (global $a-global-imp i32)) 15 | (import "module" "base" (global $a-mut-global-imp (mut i32))) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /test/lld/em_asm_table.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $0 (func (param i32 i32))) 3 | (type $1 (func (param i32 i32 i32) (result i32))) 4 | (import "env" "memory" (memory $2 8192)) 5 | (import "env" "emscripten_log" (func $fimport$0 (param i32 i32))) 6 | (import "env" "emscripten_asm_const_int" (func $fimport$1 (param i32 i32 i32) (result i32))) 7 | (table $0 159609 funcref) 8 | (elem (i32.const 1) $fimport$0 $fimport$1) 9 | (global $global$0 (mut i32) (i32.const 1024)) 10 | (global $global$1 i32 (i32.const 1048)) 11 | (export "__data_end" (global $global$1)) 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /test/nonspec-bulk-memory.wast.fromBinary.noDebugInfo: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 1024 1024) 4 | (data (i32.const 0) "hello, world") 5 | (func $0 6 | (memory.init 0 7 | (i32.const 512) 8 | (i32.const 0) 9 | (i32.const 12) 10 | ) 11 | ) 12 | (func $1 13 | (data.drop 0) 14 | ) 15 | (func $2 16 | (memory.copy 17 | (i32.const 512) 18 | (i32.const 0) 19 | (i32.const 12) 20 | ) 21 | ) 22 | (func $3 23 | (memory.fill 24 | (i32.const 0) 25 | (i32.const 42) 26 | (i32.const 1024) 27 | ) 28 | ) 29 | ) 30 | 31 | -------------------------------------------------------------------------------- /scripts/emcc-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o pipefail 5 | 6 | mkdir -p emcc-build 7 | echo "emcc-tests: build:wasm" 8 | emcmake cmake -B emcc-build -DCMAKE_BUILD_TYPE=Release -G Ninja 9 | ninja -C emcc-build binaryen_wasm 10 | echo "emcc-tests: test:wasm" 11 | ./check.py --binaryen-bin=emcc-build/bin binaryenjs_wasm 12 | echo "emcc-tests: done:wasm" 13 | 14 | echo "emcc-tests: build:js" 15 | ninja -C emcc-build binaryen_js 16 | echo "emcc-tests: test:js" 17 | ./check.py --binaryen-bin=emcc-build/bin binaryenjs 18 | echo "emcc-tests: done:js" 19 | -------------------------------------------------------------------------------- /test/control_flow.post.js: -------------------------------------------------------------------------------- 1 | 2 | function test(name) { 3 | Module.print(name); 4 | function doTest(x) { 5 | Module.print(' ' + [x] + ' ==> ' + Module['_check_' + name](x)); 6 | } 7 | doTest(1); 8 | doTest(2); 9 | doTest(3); 10 | doTest(4); 11 | doTest(11); 12 | doTest(90); 13 | } 14 | 15 | test('if'); 16 | test('loop'); 17 | test('loop_break'); 18 | test('loop_continue'); 19 | test('do_loop'); 20 | test('do_once'); 21 | test('while_forever'); 22 | test('switch'); 23 | test('switch_nodefault'); 24 | test('switch_rdefault'); 25 | test('switch_fallthrough'); 26 | 27 | -------------------------------------------------------------------------------- /test/passes/remove-unused-names_precompute.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 256 256) 3 | (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) 4 | (block $switch-default 5 | (block $switch-case 6 | (br_table $switch-case $switch-default 7 | (i32.const 0) 8 | ) 9 | ) 10 | (block 11 | (i32.store 12 | (i32.const 12) 13 | (i32.const 26) 14 | ) 15 | (return) 16 | ) 17 | ) 18 | (block 19 | (local.set $$0 20 | (i32.const 4) 21 | ) 22 | (i32.store 23 | (local.get $$0) 24 | (i32.const 1) 25 | ) 26 | ) 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /test/ctor-eval/bad-indirect-call2.wast.out: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (import "env" "_abort" (func $_abort)) 4 | (memory $0 256 256) 5 | (data (i32.const 10) "waka waka waka waka waka") 6 | (table $0 2 2 funcref) 7 | (elem (i32.const 0) $_abort $call-indirect) 8 | (export "test1" (func $test1)) 9 | (func $test1 10 | (call_indirect $0 (type $v) 11 | (i32.const 0) 12 | ) 13 | (i32.store8 14 | (i32.const 20) 15 | (i32.const 120) 16 | ) 17 | ) 18 | (func $call-indirect 19 | (i32.store8 20 | (i32.const 40) 21 | (i32.const 67) 22 | ) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /test/externref.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $externref_=>_externref (func (param externref) (result externref))) 3 | (import "env" "test2" (global $test2 externref)) 4 | (import "env" "test1" (func $test1 (param externref) (result externref))) 5 | (memory $0 1 1) 6 | (export "test1" (func $test1)) 7 | (export "test2" (global $test2)) 8 | (func $externref_test (; 1 ;) (param $0 externref) (result externref) 9 | (local $1 externref) 10 | (local.set $1 11 | (call $test1 12 | (local.get $0) 13 | ) 14 | ) 15 | (return 16 | (local.get $1) 17 | ) 18 | ) 19 | ) 20 | -------------------------------------------------------------------------------- /test/printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a = 12345; 5 | unsigned b = 123456; 6 | long c = 1234567; 7 | unsigned long d = 12345678; 8 | long long e = 1234567891011; 9 | unsigned long long f = 123456789101112; 10 | 11 | printf("int a = %d\n" 12 | "unsigned b = %u\n" 13 | "long c = %ld\n" 14 | "unsigned long d = %lu\n" 15 | "long long e = %lld\n" 16 | "unsigned long long f = %llu\n", 17 | a, 18 | b, 19 | c, 20 | d, 21 | e, 22 | f); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/wasm2js/func-ptr-offset.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $T (func (result i32))) 3 | (table 4 funcref) 4 | (elem (i32.const 1) $t1 $t2 $t3) 5 | 6 | (func $t1 (type $T) (i32.const 1)) 7 | (func $t2 (type $T) (i32.const 2)) 8 | (func $t3 (type $T) (i32.const 3)) 9 | 10 | (func (export "call") (param i32) (result i32) 11 | (call_indirect (type $T) (local.get $0)) 12 | ) 13 | ) 14 | 15 | (assert_return (invoke "call" (i32.const 1)) (i32.const 1)) 16 | (assert_return (invoke "call" (i32.const 2)) (i32.const 2)) 17 | (assert_return (invoke "call" (i32.const 3)) (i32.const 3)) 18 | -------------------------------------------------------------------------------- /test/lit/wasm-split/name-collision.wast: -------------------------------------------------------------------------------- 1 | ;; Regression test for a bug in which colliding internal names between 2 | ;; non-function exports would result in the wrong import names being used in the 3 | ;; secondary module. 4 | 5 | ;; RUN: wasm-split %s -o1 %t.1.wasm -o2 %t.2.wasm 6 | ;; RUN: wasm-dis %t.2.wasm | filecheck %s 7 | 8 | ;; CHECK-NOT: (import "primary" "memory" (table 9 | ;; CHECK: (import "primary" "table" (table 10 | 11 | (module 12 | (table $collide 1 funcref) 13 | (memory $collide 1 1) 14 | (export "table" (table $collide)) 15 | (export "memory" (memory $collide)) 16 | ) 17 | -------------------------------------------------------------------------------- /test/lld/standalone-wasm2.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 2) 3 | (global $global$0 (mut i32) (i32.const 66112)) 4 | (global $global$1 i32 (i32.const 66112)) 5 | (global $global$2 i32 (i32.const 576)) 6 | (export "memory" (memory $0)) 7 | (export "main" (func $main)) 8 | (export "__heap_base" (global $global$1)) 9 | (export "__data_end" (global $global$2)) 10 | (func $__original_main (param $0 i32) (param $1 i32) (result i32) 11 | (nop) 12 | ) 13 | (func $main (param $0 i32) (param $1 i32) (result i32) 14 | (call $__original_main (local.get $0) (local.get $1)) 15 | ) 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /test/nonspec-bulk-memory.wast.from-wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 1024 1024) 4 | (data (i32.const 0) "hello, world") 5 | (func $memory.init 6 | (memory.init 0 7 | (i32.const 512) 8 | (i32.const 0) 9 | (i32.const 12) 10 | ) 11 | ) 12 | (func $data.drop 13 | (data.drop 0) 14 | ) 15 | (func $memory.copy 16 | (memory.copy 17 | (i32.const 512) 18 | (i32.const 0) 19 | (i32.const 12) 20 | ) 21 | ) 22 | (func $memory.fill 23 | (memory.fill 24 | (i32.const 0) 25 | (i32.const 42) 26 | (i32.const 1024) 27 | ) 28 | ) 29 | ) 30 | -------------------------------------------------------------------------------- /test/binaryen.js/debug-info.js.txt: -------------------------------------------------------------------------------- 1 | === default === 2 | debugInfo=false 3 | (module 4 | (type $none_=>_none (func)) 5 | (memory $0 0) 6 | (export "test" (func $0)) 7 | (func $0 8 | (nop) 9 | ) 10 | ) 11 | 12 | === with debug info === 13 | debugInfo=true 14 | (module 15 | (type $v (func)) 16 | (memory $0 0) 17 | (export "test" (func $test)) 18 | (func $test 19 | (nop) 20 | ) 21 | ) 22 | 23 | === without debug info === 24 | debugInfo=false 25 | (module 26 | (type $none_=>_none (func)) 27 | (memory $0 0) 28 | (export "test" (func $0)) 29 | (func $0 30 | (nop) 31 | ) 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /test/ctor-eval/indirect-call3.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $v (func)) 3 | (memory 256 256) 4 | (data (i32.const 10) "waka waka waka waka waka") 5 | (import "env" "tableBase" (global $tableBase i32)) 6 | (import "env" "_abort" (func $_abort)) 7 | (table 2 2 funcref) 8 | (elem (global.get $tableBase) $_abort $call-indirect) 9 | (export "test1" $test1) 10 | (func $test1 11 | (call_indirect (type $v) (i32.const 1)) ;; safe to call 12 | (i32.store8 (i32.const 20) (i32.const 120)) 13 | ) 14 | (func $call-indirect 15 | (i32.store8 (i32.const 40) (i32.const 67)) 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /test/passes/remove-unused-brs_precompute_vacuum_remove-unused-brs.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (global $global$3 (mut f64) (f64.const 0)) 3 | (func $1 (param $x i32) (result f64) 4 | (local $var$0 f64) 5 | (block $label$0 6 | (local.set $var$0 7 | (f64.const 0) 8 | ) 9 | (if 10 | (i32.gt_s 11 | (i32.const 9) 12 | (i32.const 0) 13 | ) 14 | (return 15 | (f64.const -3.4) 16 | ) 17 | ) 18 | (if 19 | (local.get $x) 20 | (return 21 | (f64.const 5.6) 22 | ) 23 | ) 24 | (return 25 | (f64.const 1.2) 26 | ) 27 | ) 28 | ) 29 | ) 30 | -------------------------------------------------------------------------------- /test/wasm2js/base64.2asm.js: -------------------------------------------------------------------------------- 1 | 2 | function asmFunc(env) { 3 | var Math_imul = Math.imul; 4 | var Math_fround = Math.fround; 5 | var Math_abs = Math.abs; 6 | var Math_clz32 = Math.clz32; 7 | var Math_min = Math.min; 8 | var Math_max = Math.max; 9 | var Math_floor = Math.floor; 10 | var Math_ceil = Math.ceil; 11 | var Math_trunc = Math.trunc; 12 | var Math_sqrt = Math.sqrt; 13 | var abort = env.abort; 14 | var nan = NaN; 15 | var infinity = Infinity; 16 | return { 17 | 18 | }; 19 | } 20 | 21 | var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } 22 | }); 23 | -------------------------------------------------------------------------------- /test/externref.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $externref_=>_externref (func (param externref) (result externref))) 3 | (import "env" "test2" (global $gimport$1 externref)) 4 | (import "env" "test1" (func $test1 (param externref) (result externref))) 5 | (memory $0 1 1) 6 | (export "test1" (func $test1)) 7 | (export "test2" (global $gimport$1)) 8 | (func $externref_test (; 1 ;) (param $0 externref) (result externref) 9 | (local $1 externref) 10 | (local.set $1 11 | (call $test1 12 | (local.get $0) 13 | ) 14 | ) 15 | (return 16 | (local.get $1) 17 | ) 18 | ) 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /test/lit/binary/dylink.test: -------------------------------------------------------------------------------- 1 | # Verify that extra bytes in the dylink section are preserved. 2 | # 3 | # `dylink.test.wasm` was generated using emscripten to build a side 4 | # module with two TLS exports (which adds extra information to the 5 | # dylink section) using: 6 | # `emcc -s USE_PTHREAD -s SIDE_MODULE side.c` 7 | # 8 | # side.c: 9 | # _Thread_local int foo = 10; 10 | # _Thread_local int bar = 11; 11 | # 12 | # and then removing all sections except the dylink.0 section using: 13 | # `llvm-objcopy --only-section=dylink.0` 14 | RUN: wasm-opt -O1 %s.wasm -o %t.o 15 | RUN: cmp %s.wasm %t.o 16 | -------------------------------------------------------------------------------- /test/nonspec-bulk-memory.wast.fromBinary: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 1024 1024) 4 | (data (i32.const 0) "hello, world") 5 | (func $memory.init 6 | (memory.init 0 7 | (i32.const 512) 8 | (i32.const 0) 9 | (i32.const 12) 10 | ) 11 | ) 12 | (func $data.drop 13 | (data.drop 0) 14 | ) 15 | (func $memory.copy 16 | (memory.copy 17 | (i32.const 512) 18 | (i32.const 0) 19 | (i32.const 12) 20 | ) 21 | ) 22 | (func $memory.fill 23 | (memory.fill 24 | (i32.const 0) 25 | (i32.const 42) 26 | (i32.const 1024) 27 | ) 28 | ) 29 | ) 30 | 31 | -------------------------------------------------------------------------------- /test/wasm2js/base64.2asm.js.opt: -------------------------------------------------------------------------------- 1 | 2 | function asmFunc(env) { 3 | var Math_imul = Math.imul; 4 | var Math_fround = Math.fround; 5 | var Math_abs = Math.abs; 6 | var Math_clz32 = Math.clz32; 7 | var Math_min = Math.min; 8 | var Math_max = Math.max; 9 | var Math_floor = Math.floor; 10 | var Math_ceil = Math.ceil; 11 | var Math_trunc = Math.trunc; 12 | var Math_sqrt = Math.sqrt; 13 | var abort = env.abort; 14 | var nan = NaN; 15 | var infinity = Infinity; 16 | return { 17 | 18 | }; 19 | } 20 | 21 | var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } 22 | }); 23 | -------------------------------------------------------------------------------- /test/wasm2js/empty_table.2asm.js: -------------------------------------------------------------------------------- 1 | 2 | function asmFunc(env) { 3 | var Math_imul = Math.imul; 4 | var Math_fround = Math.fround; 5 | var Math_abs = Math.abs; 6 | var Math_clz32 = Math.clz32; 7 | var Math_min = Math.min; 8 | var Math_max = Math.max; 9 | var Math_floor = Math.floor; 10 | var Math_ceil = Math.ceil; 11 | var Math_trunc = Math.trunc; 12 | var Math_sqrt = Math.sqrt; 13 | var abort = env.abort; 14 | var nan = NaN; 15 | var infinity = Infinity; 16 | return { 17 | 18 | }; 19 | } 20 | 21 | var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } 22 | }); 23 | -------------------------------------------------------------------------------- /test/wasm2js/i64-select.2asm.js: -------------------------------------------------------------------------------- 1 | 2 | function asmFunc(env) { 3 | var Math_imul = Math.imul; 4 | var Math_fround = Math.fround; 5 | var Math_abs = Math.abs; 6 | var Math_clz32 = Math.clz32; 7 | var Math_min = Math.min; 8 | var Math_max = Math.max; 9 | var Math_floor = Math.floor; 10 | var Math_ceil = Math.ceil; 11 | var Math_trunc = Math.trunc; 12 | var Math_sqrt = Math.sqrt; 13 | var abort = env.abort; 14 | var nan = NaN; 15 | var infinity = Infinity; 16 | return { 17 | 18 | }; 19 | } 20 | 21 | var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } 22 | }); 23 | -------------------------------------------------------------------------------- /test/wasm2js/indirect-select.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (import "env" "table" (table $timport 6 funcref)) 4 | (func "foo-true" (param $x i32) (result i32) 5 | (call_indirect (type $none_=>_i32) 6 | (select 7 | (i32.const 1) 8 | (i32.const 0) 9 | (local.get $x) 10 | ) 11 | ) 12 | ) 13 | (func "foo-false" (param $x i32) (result i32) 14 | (call_indirect (type $none_=>_i32) 15 | (select 16 | (i32.const 0) 17 | (i32.const 1) 18 | (local.get $x) 19 | ) 20 | ) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /test/wasm2js/i64-select.2asm.js.opt: -------------------------------------------------------------------------------- 1 | 2 | function asmFunc(env) { 3 | var Math_imul = Math.imul; 4 | var Math_fround = Math.fround; 5 | var Math_abs = Math.abs; 6 | var Math_clz32 = Math.clz32; 7 | var Math_min = Math.min; 8 | var Math_max = Math.max; 9 | var Math_floor = Math.floor; 10 | var Math_ceil = Math.ceil; 11 | var Math_trunc = Math.trunc; 12 | var Math_sqrt = Math.sqrt; 13 | var abort = env.abort; 14 | var nan = NaN; 15 | var infinity = Infinity; 16 | return { 17 | 18 | }; 19 | } 20 | 21 | var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } 22 | }); 23 | -------------------------------------------------------------------------------- /test/wasm2js/if_unreachable.2asm.js: -------------------------------------------------------------------------------- 1 | 2 | function asmFunc(env) { 3 | var Math_imul = Math.imul; 4 | var Math_fround = Math.fround; 5 | var Math_abs = Math.abs; 6 | var Math_clz32 = Math.clz32; 7 | var Math_min = Math.min; 8 | var Math_max = Math.max; 9 | var Math_floor = Math.floor; 10 | var Math_ceil = Math.ceil; 11 | var Math_trunc = Math.trunc; 12 | var Math_sqrt = Math.sqrt; 13 | var abort = env.abort; 14 | var nan = NaN; 15 | var infinity = Infinity; 16 | return { 17 | 18 | }; 19 | } 20 | 21 | var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } 22 | }); 23 | --------------------------------------------------------------------------------