WASM2JS(1)
๐ WASM2JS(1) โ User Commands ๐
okay bestie, sit down, hydrate, because this is the wasm2js glow-up page and it is long. we're doing this in cute little chunks so your brain doesn't melt. โจ
๐ธ NAME ๐ธ
wasm2js โ literally just: transform .wasm/.wat files to asm.js. that's the whole vibe. ๐ฆ
๐ DESCRIPTION ๐
so the shape of the whole thing is this:
wasm2js INFILE
and that's it! feed it a .wasm or .wat file, it hands you back asm.js. iconic behaviour, no notes. ๐
๐ wasm2js options ๐
these are the top-level switches, the main-character flags, the ones that shape the whole output before we get into the spicy optimization stuff. ๐ซถ
--output,-oโ where do you want the good stuff to land? give it an output file. if you don't specify one, it just goes straight to stdout. you know, raw. unhinged. love that for you. ๐--allow-assertsโ lets you compile.wasttesting asserts. yes, the testing-flavoured ones. go off. ๐--pedanticโ emulates WebAssembly trapping behavior. being pedantic is a personality, and here it's a feature. ๐--emscriptenโ emulates the glue in emscripten-compatible form, and NOT in ES6 module form. so like, the old-school shape. pick your lane bestie. ๐ธ--deterministicโ replaces WebAssembly trapping behavior deterministically. okay so real talk, the default is that it simply does not care what would trap in wasm โ we're talking a load out of bounds, integer divide by zero, the whole chaotic mess. with this flag we try to be deterministic at least in what happens, which might or might not be to trap like wasm actually does โ but at least it shouldn't vary. so: chaotic-but-consistent. slay. โจ--symbols-fileโ emits a symbols file that maps function indexes to their original names. a little name tag for every function. so cute, so useful. ๐ท๏ธ
๐ Optimization passes ๐
this is the big one. the list. the way that there are like forty of these and every single one is doing something in the background like a little fairy godmother of your binary. ๐ง buckle up. โญ
--abstract-type-refiningโ refine and merge abstract (never-created) types. ๐--alignment-loweringโ lower unaligned loads and stores to smaller aligned ones. ๐--asyncifyโ async/await style transform, allowing pausing and resuming. pausing? resuming? main character energy fr. ๐ฅ--avoid-reinterpretsโ tries to avoid reinterpret operations via more loads. load more, reinterpret less. ๐--cfpโ propagate constant struct field values. ๐ฆ--cfp-reftestโ propagate constant struct field values, usingref.test. same energy, different tool. ๐--coalesce-localsโ reduce # of locals by coalescing. fewer locals, same lore. ๐ซถ--coalesce-locals-learningโ reduce # of locals by coalescing and learning. it's studying. it's growing. ๐--code-foldingโ fold code, merging duplicates. ๐--code-pushingโ push code forward, potentially making it not always execute. moving things downstream, sometimes so they justโฆ don't run. ๐ญ--const-hoistingโ hoist repeated constants to a local. ๐--constraint-analysisโ finds and uses mathematical constraints on locals. math girlies rise. ๐--daeโ removes arguments to calls in an lto-like manner. ๐ฆ--dae-optimizingโ removes arguments to calls in an lto-like manner, and optimizes where we removed. glow-up edition. โจ--dae2โ experimental reimplementation of DAE. (it's giving sequel. it's giving season two.) ๐--dceโ removes unreachable code. if you can't get there, it doesn't exist bestie. ๐ซ--dealignโ forces all loads and stores to have alignment1. no cap. ๐ธ--denanโ instrument the wasm to convert NaNs into0at runtime. bye bye NaN, hello zero. ๐--dfoโ optimizes using the DataFlow SSA IR. ๐--directizeโ turns indirect calls into direct ones. no more middleman. ๐--discard-global-effectsโ discards global effect info. ๐๏ธ--duplicate-function-eliminationโ removes duplicate functions. if you have two, keep one. ๐ซถ--duplicate-import-eliminationโ removes duplicate imports. same energy, import edition. ๐--dwarfdumpโ dump DWARF debug info sections from the read binary. deep lore extraction. ๐--emit-target-featuresโ emit the target features section in the output. ๐ท๏ธ--enclose-worldโ modify the wasm (destructively) for closed-world. yes bestie, destructively. it says so right there. ๐--extract-functionโ leaves just one function (useful for debugging). โ๏ธ--extract-function-indexโ leaves just one function selected by index. same but numbered. ๐ข--flattenโ flattens out code, removing nesting. no more layers, just vibes. ๐--fpcast-emuโ emulates function pointer casts, allowing incorrect indirect calls to (sometimes) work. sometimes. we said sometimes. โ ๏ธ--func-metricsโ reports function metrics. ๐--generate-dyncallsโ generatedynCallfunctions used by emscripten ABI. ๐--generate-global-effectsโ generate global effect info (helps later passes). helping the girlies downstream. ๐ซถ--generate-i64-dyncallsโ generatedynCallfunctions used by emscripten ABI, but only for functions withi64in their signature (which cannot be invoked via the wasm table without JavaScript BigInt support). ๐--global-refiningโ refine the types of globals. ๐ฎ--gsiโ globally optimize struct values. ๐--gsi-desc-castโ globally optimize struct values, also emittingref.cast_desc_eq. โจ--gtoโ globally optimize GC types. โป๏ธ--gufaโ Grand Unified Flow Analysis: optimize the entire program using information about what content can actually appear in each location. yes, that's the literal name. yes, it's iconic. ๐--gufa-cast-allโ GUFA plus add casts for all inferences. ๐--gufa-optimizingโ GUFA plus local optimizations in functions we modified. ๐ธ--heap-store-optimizationโ optimize heap (GC) stores. ๐ซถ--heap2localโ replace GC allocations with locals. ๐--i64-to-i32-loweringโ lower all uses ofi64s to usei32s instead. โ๏ธ--inline-mainโ inline__original_mainintomain. ๐--inliningโ inline functions (you probably wantinlining-optimizing). okay but literally it's telling you what you want. listen to it. ๐--inlining-optimizingโ inline functions and optimizes where we inlined. the deluxe version. ๐--instrument-branch-hintsโ instrument branch hints so we can see which guessed right. ๐ฏ--instrument-localsโ instrument the build with code to intercept all loads and stores. ๐--instrument-memoryโ instrument the build with code to intercept all loads and stores. (yes it's the same line as the one above, no we did not skip it, we are keeping everything, periodt.) ๐--intrinsic-loweringโ lower away binaryen intrinsics. ๐ง--legalize-and-prune-js-interfaceโ legalizes the import/export boundary and prunes when needed. ๐--legalize-js-interfaceโ legalizesi64types on the import/export boundary. โ๏ธ--licmโ loop invariant code motion. ๐--limit-segmentsโ attempt to merge segments to fit within web limits. ๐--llvm-memory-copy-fill-loweringโ Lowermemory.copyandmemory.fillto wasm mvp and disable the bulk-memory feature. ๐--llvm-nontrapping-fptoint-loweringโ lower nontrapping float-to-int operations to wasm mvp and disable the nontrapping fptoint feature. โจ--local-cseโ common subexpression elimination inside basic blocks. ๐--local-subtypingโ apply more specific subtypes to locals where possible. ๐ซถ--log-executionโ instrument the build with logging of where execution goes. ๐บ๏ธ--mark-js-calledโ mark js called functions (usingconfigureAll) as doing so. ๐--memory-packingโ packs memory into separate segments, skipping zeros. ๐งณ--memory64-loweringโ lower loads and stores to a 64-bit memory to instead use a 32-bit one. โฌ๏ธ--merge-blocksโ merges blocks to their parents. family reunion. ๐จ๐ฉ๐ง--merge-j2cl-itablesโ Merges itable structures into vtables to make types more compact. ๐--merge-localsโ merges locals when beneficial. ๐ธ--merge-similar-functionsโ merges similar functions when benefical. (that's their spelling, not mine, and we keep it exact bestie.) ๐--metricsโ reports metrics (with an optional title,--metrics[=TITLE]). ๐--minify-importsโ minifies import names (only those, and not export names), and emits a mapping to the minified ones. ๐๏ธ--minify-imports-and-exportsโ minifies both import and export names, and emits a mapping to the minified ones. ๐๏ธโจ--minify-imports-and-exports-and-modulesโ minifies both import and export names, and emits a mapping to the minified ones, and minifies the modules as well. (the full package, the deluxe, the everything.) ๐--minimize-rec-groupsโ Split types into minimal recursion groups. ๐ฎ--monomorphizeโ creates specialized versions of functions. ๐--monomorphize-alwaysโ creates specialized versions of functions (even if unhelpful). it doesn't care if it's unhelpful, it's doing it anyway. ๐ญ--multi-memory-loweringโ combines multiple memories into a single memory. ๐ง--multi-memory-lowering-with-bounds-checksโ combines multiple memories into a single memory, trapping if the read or write is larger than the length of the memory's data. โ ๏ธ--name-typesโ (re)name all heap types. ๐ท๏ธ--nmโ name list. ๐--no-full-inlineโ mark functions as no-inline (for full inlining only). ๐ซ--no-inlineโ mark functions as no-inline. ๐ซ--no-partial-inlineโ mark functions as no-inline (for partial inlining only). ๐ซ--once-reductionโ reduces calls to code that only runs once. 1๏ธโฃ--optimize-added-constantsโ optimizes added constants into load/store offsets. โ--optimize-added-constants-propagateโ optimizes added constants into load/store offsets, propagating them across locals too. โ๐ฆ--optimize-castsโ eliminate and reuse casts. ๐--optimize-for-jsโ early optimize of the instruction combinations for js. ๐--optimize-instructionsโ optimizes instruction combinations. โ๏ธ--optimize-j2clโ optimizes J2CL specific constructs. ๐--outliningโ outline instructions. โ๏ธ--pick-load-signsโ pick load signs based on their uses. ๐--poppifyโ Transform Binaryen IR into Poppy IR. ๐ธ--post-emscriptenโ miscellaneous optimizations for Emscripten-generated code. ๐ซถ--precomputeโ computes compile-time evaluatable expressions. ๐งฎ--precompute-propagateโ computes compile-time evaluatable expressions and propagates them through locals. ๐งฎโจ--printโ print in s-expression format. ๐จ๏ธ--print-boundaryโ print boundary in JSON format. ๐จ๏ธ๐--print-call-graphโ print call graph. ๐--print-featuresโ print options for enabled features. ๐--print-fullโ print in full s-expression format. ๐จ๏ธ๐--print-function-mapโ print a map of function indexes to names. ๐บ๏ธ--print-minifiedโ print in minified s-expression format. ๐จ๏ธ๐๏ธ--propagate-debug-locsโ propagate debug location from parents or previous siblings to child nodes. ๐ณ--propagate-globals-globallyโ propagate global values to other globals (useful for tests). ๐--remove-exportsโ removes exports using a wildcard. ๐--remove-importsโ removes imports and replaces them with nops. ๐ซฅ--remove-memoryโ removes memory init (legacy name). ๐ต (the name is legacy, not the flag. keep up bestie.)--remove-memory-initโ removes memory initialization. ๐งน--remove-non-js-opsโ removes operations incompatible with js. ๐ซ--remove-relaxed-simdโ replaces relaxed SIMD instructions with unreachable. ๐--remove-unused-brsโ removes breaks from locations that are not needed. โ๏ธ--remove-unused-module-elementsโ removes unused module elements. ๐งน--remove-unused-namesโ removes names from locations that are never branched to. ๐ท๏ธ๐ซ--remove-unused-nonfunction-module-elementsโ removes unused module elements that are not functions. ๐งฝ--remove-unused-typesโ remove unused private GC types. โป๏ธ--reorder-functionsโ sorts functions by access frequency. ๐--reorder-functions-by-nameโ sorts functions by name (useful for debugging). ๐ค
and bestieโฆ that is genuinely not the whole list. it keeps going. come back for part two, we're not even done being iconic yet. ๐๐ฆ
--reorder-globalsโ sorts globals by access frequency โจ hottest globals first, bestie--reorder-localsโ sorts locals by access frequency ๐--reorder-typesโ sorts private types by access frequency, no cap--rereloopโ re-optimize control flow using the relooper algorithm ๐ iconic--roundtripโ write the module to binary, then read it back. it's giving "just to be sure" ๐ฆ--rseโ remove redundantlocal.sets๐งน--safe-heapโ instrument loads and stores to check for invalid behavior. safety girl summer ๐--separate-data-segmentsโ write data segments to a file and strip them from the module--set-globalsโ sets specified globals to specified values--signature-pruningโ remove params from function signature types where possible โ๏ธ--signature-refiningโ apply more specific subtypes to signature types where possible--signext-loweringโ lower sign-ext operations to wasm mvp and disable the sign extension feature--simplify-globalsโ miscellaneous globals-related optimizations--simplify-globals-optimizingโ miscellaneous globals-related optimizations, and optimizes where we replacedglobal.gets with constants--simplify-localsโ miscellaneous locals-related optimizations--simplify-locals-nonestingโ miscellaneous locals-related optimizations (no nesting at all; preserves flatness) ๐ซถ flat is a vibe--simplify-locals-nostructureโ miscellaneous locals-related optimizations (no structure)--simplify-locals-noteeโ miscellaneous locals-related optimizations (no tees)--simplify-locals-notee-nostructureโ miscellaneous locals-related optimizations (no tees or structure) ๐ none of the above--souperifyโ emit Souper IR in text form--souperify-single-useโ emit Souper IR in text form (single-use nodes only)--spill-pointersโ spill pointers to the C stack (useful for Boehm-style GC)--ssaโ ssa-ify variables so that they have a single assignment ๐ one assignment, one queen--ssa-nomergeโ ssa-ify variables so that they have a single assignment, ignoring merges--stack-checkโ enforce limits on llvm's__stack_pointerglobal--string-gatheringโ gathers wasm strings to globals ๐งบ--string-liftingโ lift string imports to wasm strings โฌ๏ธ--string-loweringโ lowers wasm strings and operations to imports โฌ๏ธ--string-lowering-magic-importsโ same as string-lowering, but encodes well-formed strings as magic imports โจ--string-lowering-magic-imports-assertโ same as string-lowering-magic-imports, but raise a fatal error if there are invalid strings ๐ญ--stripโ deprecated; same as strip-debug--strip-debugโ strip debug info (including the names section)--strip-dwarfโ strip dwarf debug info--strip-ehโ strip EH instructions--strip-producersโ strip the wasm producers section--strip-target-featuresโ strip the wasm target features section--strip-toolchain-annotationsโ strip all toolchain-specific code annotations--stub-unsupported-jsโ stub out unsupported JS operations--symbolmapโ (alias for print-function-map)--table64-loweringโ alias for memory64-lowering--trace-callsโ instrument the build with code to intercept specific function calls ๐--translate-to-exnrefโ translate old Phase 3 EH instructions to new ones with exnref--translate-to-new-ehโ deprecated; same as translate-to-exnref--trap-mode-clampโ replace trapping operations with clamping semantics--trap-mode-jsโ replace trapping operations with js semantics--tuple-optimizationโ optimize trivial tuples away--type-finalizingโ mark all leaf types as final ๐--type-mergingโ merge types to their supertypes where possible--type-refiningโ apply more specific subtypes to type fields where possible--type-refining-gufaโ apply more specific subtypes to type fields where possible (using GUFA)--type-ssaโ create new types to help other optimizations--type-unfinalizingโ mark all types as non-final (open) ๐--unsubtypingโ removes unnecessary subtyping relationships--unteeโ removeslocal.tees, replacing them with sets and gets--vacuumโ removes obviously unneeded code ๐งฝ it's giving spring cleaning
๐ Optimization options ๐
-Oโ execute default optimization passes (equivalent to-Os)-O0โ execute no optimization passes ๐-O1โ execute-O1optimization passes (quick&useful opts, useful for iteration builds)-O2โ execute-O2optimization passes (most opts, generally gets most perf) ๐ฅ-O3โ execute-O3optimization passes (spends potentially a lot of time optimizing) โณ-O4โ execute-O4optimization passes (also flatten the IR, which can take a lot more time and memory, but is useful on more nested / complex / less-optimized input) ๐ main character energy but at what cost-Osโ execute default optimization passes, focusing on code size-Ozโ execute default optimization passes, super-focusing on code size ๐ smol is the goal--optimize-level,-olโ How much to focus on optimizing code--shrink-level,-sโ How much to focus on shrinking code size--debuginfo,-gโ Emit names section in wasm binary (or full debuginfo in wast)--always-inline-max-function-size,-aimfsโ Max size of functions that are always inlined (default2, which is safe for use with-Osbuilds)--flexible-inline-max-function-size,-fimfsโ Max size of functions that are inlined when lightweight (no loops or function calls) when optimizing aggressively for speed (-O3). Default:20--one-caller-inline-max-function-size,-ocimfsโ Max size of functions that are inlined when there is only one caller (default-1, which means all such functions are inlined)--inline-max-combined-binary-size,-imcbsโ Max size of combined functions after inlining. Default:409600--inline-functions-with-loops,-ifwlโ Allow inlining functions with loops ๐--partial-inlining-ifs,-piiโ Number of ifs allowed in partial inlining (zero means partial inlining is disabled) (default:0)--ignore-implicit-traps,-iitโ Optimize under the helpful assumption that no surprising traps occur (from load, div/mod, etc.)--traps-never-happen,-tnhโ Optimize under the helpful assumption that no trap is reached at runtime (from load, div/mod, etc.)--low-memory-unused,-lmuโ Optimize under the helpful assumption that the low 1K of memory is not used by the application--fast-math,-ffmโ Optimize floats without handling corner cases of NaNs and rounding--zero-filled-memory,-uimโ Assume that an imported memory will be zero-initialized--skip-pass,-spโ Skip a pass (do not run it) ๐ โโ๏ธ
ok quick vibe check bestie: read those "helpful assumption" ones carefully โ they're literally assumptions about your program, so if they're wrong, that's on you, fr fr.
๐ ๏ธ Tool options ๐ ๏ธ
--mvp-features,-mvpโ Disable all non-MVP features--all-features,-allโ Enable all features ๐ฅ everything everywhere all at once--detect-featuresโ (deprecated - this flag does nothing) ๐ it's giving ghost--quiet,-qโ Emit less verbose output and hide trivial warnings. ๐คซ--experimental-poppyโ Parse wast files as Poppy IR for testing purposes. ๐ธ--emit-module-namesโ Emit module names, even if not emitting the rest of the names section.--enable-sign-extโ Enable sign extension operations--disable-sign-extโ Disable sign extension operations--enable-threadsโ Enable atomic operations--disable-threadsโ Disable atomic operations--enable-mutable-globalsโ Enable mutable globals--disable-mutable-globalsโ Disable mutable globals--enable-nontrapping-float-to-intโ Enable nontrapping float-to-int operations--disable-nontrapping-float-to-intโ Disable nontrapping float-to-int operations--enable-simdโ Enable SIMD operations and types--disable-simdโ Disable SIMD operations and types--enable-bulk-memoryโ Enable bulk memory operations--disable-bulk-memoryโ Disable bulk memory operations--enable-bulk-memory-optโ Enablememory.copyandmemory.fill--disable-bulk-memory-optโ Disablememory.copyandmemory.fill--enable-call-indirect-overlongโ Enable LEB encoding of call-indirect (Ignored for compatibility as it has no effect on Binaryen)--disable-call-indirect-overlongโ Disable LEB encoding of call-indirect (Ignored for compatibility as it has no effect on Binaryen)--enable-exception-handlingโ Enable exception handling operations--disable-exception-handlingโ Disable exception handling operations--enable-tail-callโ Enable tail call operations--disable-tail-callโ Disable tail call operations--enable-reference-typesโ Enable reference types--disable-reference-typesโ Disable reference types--enable-multivalueโ Enable multivalue functions--disable-multivalueโ Disable multivalue functions--enable-gcโ Enable garbage collection--disable-gcโ Disable garbage collection--enable-memory64โ Enable memory64--disable-memory64โ Disable memory64--enable-relaxed-simdโ Enable relaxed SIMD--disable-relaxed-simdโ Disable relaxed SIMD--enable-extended-constโ Enable extended const expressions--disable-extended-constโ Disable extended const expressions--enable-stringsโ Enable strings--disable-stringsโ Disable strings--enable-multimemoryโ Enable multimemory--disable-multimemoryโ Disable multimemory--enable-stack-switchingโ Enable stack switching--disable-stack-switchingโ Disable stack switching--enable-shared-everythingโ Enable shared-everything threads--disable-shared-everythingโ Disable shared-everything threads--enable-fp16โ Enable float 16 operations--disable-fp16โ Disable float 16 operations--enable-custom-descriptorsโ Enable custom descriptors (RTTs) and exact references--disable-custom-descriptorsโ Disable custom descriptors (RTTs) and exact references--enable-multibyteโ Enable multibyte array loads and stores--disable-multibyteโ Disable multibyte array loads and stores
โจ every single one of those has an--enable-/--disable-twin, so if you turn a feature on you can always turn it right back off. balance, bestie ๐
--enable-relaxed-atomicsโ turns ON acquire/release atomic memory operations โจ--disable-relaxed-atomicsโ turns OFF acquire/release atomic memory operations ๐--enable-custom-page-sizesโ turns ON custom page sizes ๐--disable-custom-page-sizesโ turns OFF custom page sizes ๐--enable-wide-arithmeticโ turns ON wide arithmetic ๐ฅ--disable-wide-arithmeticโ turns OFF wide arithmetic ๐ฅ--enable-compact-importsโ turns ON the compact import section ๐--disable-compact-importsโ turns OFF the compact import section ๐--enable-typed-function-referencesโ deprecated compatibility flag โ ๏ธ (yes bestie, it's a legacy thing, no cap)--disable-typed-function-referencesโ deprecated compatibility flag โ ๏ธ (same energy, other direction)--no-validation,-nโ straight up disables validation, because it just assumes ur inputs are correct ๐ญ like okay queen, live dangerously--pass-arg,-paโ an argument that gets passed along to the optimization passes being run. Has to be in the formKEY@VALUE, fr fr. IfKEYis the name of a pass, then it applies to the closest instance of that pass before us. IfKEYisn't the name of a pass, then it's a global option that applies to all pass instances that read it ๐--closed-world,-cwโ assume code outside of the module doesn't inspect or interact with GC and function references, even if they get passed out. The outside may hold on to them and pass them back in, but it won't inspect their contents or call them ๐ซถ--preserve-type-orderโ preserve the order of types from the input (lowkey useful for debugging and testing) ๐ฆ--generate-stack-irโ generate StackIR during writing โจ--optimize-stack-irโ optimize StackIR during writing ๐--print-stack-irโ print StackIR during writing ๐ธ--no-stack-irโ do not use StackIR (even when it is the default) ๐
๐ General options ๐
--versionโ output version information and exit ๐--help,-hโ show this help message and exit ๐ฅฐ--debug,-dโ print debug information tostderr๐
and that's the whole thing bestie, ur officially a wasm2js scholar ๐โจ it's giving main character compiler energy tbh. this was wasm2js 131, dated August 2026, and if u ever forget a flag just come back and reread ur girl's notes ๐ no gatekeeping, periodt ๐
๐ฆ where this page comes from
- ubuntu stonking: binaryen 131-2 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms