Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/esy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ jobs:
- name: Run tests
run: |
esy test

# Check formatting
- name: Check format
if: inputs.os == 'ubuntu-latest'
run: |
esy format
git diff --exit-code --name-only
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(dirs :standard)

(data_only_dirs node_modules)
(data_only_dirs node_modules)
15 changes: 11 additions & 4 deletions src/expression.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ end
module Switch = struct
external make : Module.t -> string list -> string -> t -> t -> t
= "caml_binaryen_switch"
(** Module, branch names, default branch name, condition, value. Value may be null. *)
(** Module, branch names, default branch name, condition, value. Value may be
null. *)

external get_num_names : t -> int = "caml_binaryen_switch_get_num_names"
external get_name_at : t -> int -> string = "caml_binaryen_switch_get_name_at"
Expand Down Expand Up @@ -544,7 +545,8 @@ module Call_indirect = struct

external make_return :
Module.t -> string -> t -> t list -> Type.t -> Type.t -> t
= "caml_binaryen_return_call_indirect__bytecode" "caml_binaryen_return_call_indirect"
= "caml_binaryen_return_call_indirect__bytecode"
"caml_binaryen_return_call_indirect"
(** Module, table, function value, params, params type, return type. *)

external get_target : t -> t = "caml_binaryen_call_indirect_get_target"
Expand Down Expand Up @@ -705,10 +707,13 @@ end
module Memory_init = struct
external make : Module.t -> string -> t -> t -> t -> string -> t
= "caml_binaryen_memory_init__bytecode" "caml_binaryen_memory_init"
(** Module, segment, destination, offset, size, memory_name *)

external get_segment : t -> string = "caml_binaryen_memory_init_get_segment"
(** Module, segment, destination, offset, size, memory_name *)

external set_segment : t -> string -> unit
= "caml_binaryen_memory_init_set_segment"

external get_dest : t -> t = "caml_binaryen_memory_init_get_dest"
external set_dest : t -> t -> unit = "caml_binaryen_memory_init_set_dest"
external get_offset : t -> t = "caml_binaryen_memory_init_get_offset"
Expand All @@ -719,8 +724,10 @@ end

module Data_drop = struct
external make : Module.t -> string -> t = "caml_binaryen_data_drop"
(** Module, segment. *)

external get_segment : t -> string = "caml_binaryen_data_drop_get_segment"
(** Module, segment. *)

external set_segment : t -> string -> unit
= "caml_binaryen_data_drop_set_segment"
end
Expand Down
12 changes: 8 additions & 4 deletions src/import.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
external add_function_import :
Module.t -> string -> string -> string -> Type.t -> Type.t -> unit
= "caml_binaryen_add_function_import__bytecode" "caml_binaryen_add_function_import"
(** Module, internal name, external module name, external base name, params type, results type. *)
= "caml_binaryen_add_function_import__bytecode"
"caml_binaryen_add_function_import"
(** Module, internal name, external module name, external base name, params
type, results type. *)

external add_table_import : Module.t -> string -> string -> string -> unit
= "caml_binaryen_add_table_import"
Expand All @@ -14,8 +16,10 @@ external add_memory_import :

external add_global_import :
Module.t -> string -> string -> string -> Type.t -> bool -> unit
= "caml_binaryen_add_global_import__bytecode" "caml_binaryen_add_global_import"
(** Module, internal name, external module name, external base name, type, mutable. *)
= "caml_binaryen_add_global_import__bytecode"
"caml_binaryen_add_global_import"
(** Module, internal name, external module name, external base name, type,
mutable. *)

external function_import_get_module : Function.t -> string
= "caml_binaryen_function_import_get_module"
Expand Down
3 changes: 2 additions & 1 deletion src/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ external set_memory :
type segment = { name : string; data : bytes; kind : segment_kind; size : int }
and segment_kind = Passive | Active of { offset : Expression.t }

(** Module, initial size, maximum size, export name, segments, shared, memory64, moduleName . *)
(** Module, initial size, maximum size, export name, segments, shared, memory64,
moduleName . *)
let set_memory wasm_mod initial maximum export_name (segments : segment list)
shared memory64 moduleName =
let split_segments segments =
Expand Down
46 changes: 31 additions & 15 deletions src/passes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ let avoid_reinterprets = "avoid-reinterprets"
(** removes arguments to calls in an lto-like manner *)
let dae = "dae"

(** removes arguments to calls in an lto-like manner, and optimizes where we removed *)
(** removes arguments to calls in an lto-like manner, and optimizes where we
removed *)
let dae_optimizing = "dae-optimizing"

(** refine and merge abstract (never-created) types *)
Expand Down Expand Up @@ -75,7 +76,8 @@ let extract_function_index = "extract-function-index"
(** flattens out code, removing nesting *)
let flatten = "flatten"

(** emulates function pointer casts, allowing incorrect indirect calls to (sometimes) work *)
(** emulates function pointer casts, allowing incorrect indirect calls to
(sometimes) work *)
let fpcast_emu = "fpcast-emu"

(** reports function metrics *)
Expand All @@ -84,7 +86,9 @@ let func_metrics = "func-metrics"
(** generate dynCall fuctions used by emscripten ABI *)
let generate_dyncalls = "generate-dyncalls"

(** generate dynCall functions used by emscripten ABI, but only for functions with i64 in their signature (which cannot be invoked via the wasm table without JavaScript BigInt support). *)
(** generate dynCall functions used by emscripten ABI, but only for functions
with i64 in their signature (which cannot be invoked via the wasm table
without JavaScript BigInt support). *)
let generate_i64_dyncalls = "generate-i64-dyncalls"

(** generate global effect info (helps later passes) *)
Expand All @@ -102,7 +106,8 @@ let gsi = "gsi"
(** globally optimize GC types *)
let gto = "gto"

(** Grand Unified Flow Analysis: optimize the entire program using information about what content can actually appear in each location *)
(** Grand Unified Flow Analysis: optimize the entire program using information
about what content can actually appear in each location *)
let gufa = "gufa"

(** GUFA plus local optimizations in functions we modified *)
Expand Down Expand Up @@ -132,7 +137,8 @@ let jspi = "jspi"
(** legalizes i64 types on the import/export boundary *)
let legalize_js_interface = "legalize-js-interface"

(** legalizes i64 types on the import/export boundary in a minimal manner, only on things only JS will call *)
(** legalizes i64 types on the import/export boundary in a minimal manner, only
on things only JS will call *)
let legalize_js_interface_minimally = "legalize-js-interface-minimally"

(** common subexpression elimination inside basic blocks *)
Expand Down Expand Up @@ -177,17 +183,21 @@ let merge_locals = "merge-locals"
(** reports metrics *)
let metrics = "metrics"

(** minifies import names (only those, and not export names), and emits a mapping to the minified ones *)
(** minifies import names (only those, and not export names), and emits a
mapping to the minified ones *)
let minify_imports = "minify-imports"

(** minifies both import and export names, and emits a mapping to the minified ones *)
(** minifies both import and export names, and emits a mapping to the minified
ones *)
let minify_imports_and_exports = "minify-imports-and-exports"

(** minifies both import and export names, and emits a mapping to the minified ones, and minifies the modules as well *)
(** minifies both import and export names, and emits a mapping to the minified
ones, and minifies the modules as well *)
let minify_imports_and_exports_and_modules =
"minify-imports-and-exports-and-modules"

(** apply the assumption that asyncify imports always unwind, and we never rewind *)
(** apply the assumption that asyncify imports always unwind, and we never
rewind *)
let mod_asyncify_always_and_only_unwind = "mod-asyncify-always-and-only-unwind"

(** apply the assumption that asyncify never unwinds *)
Expand All @@ -202,7 +212,8 @@ let monomorphize_always = "monomorphize-always"
(** combines multiple memories into a single memory *)
let multi_memory_lowering = "multi-memory-lowering"

(** combines multiple memories into a single memory, trapping if the read or write is larger than the length of the memory's data *)
(** combines multiple memories into a single memory, trapping if the read or
write is larger than the length of the memory's data *)
let multi_memory_lowering_with_bounds_checks =
"multi-memory-lowering-with-bounds-checks"

Expand All @@ -218,7 +229,8 @@ let once_reduction = "once-reduction"
(** optimizes added constants into load/store offsets *)
let optimize_added_constants = "optimize-added-constants"

(** optimizes added constants into load/store offsets, propagating them across locals too *)
(** optimizes added constants into load/store offsets, propagating them across
locals too *)
let optimize_added_constants_propagate = "optimize-added-constants-propagate"

(** eliminate and reuse casts *)
Expand All @@ -245,7 +257,8 @@ let optimize_for_js = "optimize-for-js"
(** computes compile-time evaluatable expressions *)
let precompute = "precompute"

(** computes compile-time evaluatable expressions and propagates them through locals *)
(** computes compile-time evaluatable expressions and propagates them through
locals *)
let precompute_propagate = "precompute-propagate"

(** print in s-expression format *)
Expand Down Expand Up @@ -330,19 +343,22 @@ let signature_pruning = "signature-pruning"
(** apply more specific subtypes to signature types where possible *)
let signature_refining = "signature-refining"

(** lower sign-ext operations to wasm mvp and disable the sign extension feature *)
(** lower sign-ext operations to wasm mvp and disable the sign extension feature
*)
let signext_lowering = "signext-lowering"

(** miscellaneous globals-related optimizations *)
let simplify_globals = "simplify-globals"

(** miscellaneous globals-related optimizations, and optimizes where we replaced global.gets with constants *)
(** miscellaneous globals-related optimizations, and optimizes where we replaced
global.gets with constants *)
let simplify_globals_optimizing = "simplify-globals-optimizing"

(** miscellaneous locals-related optimizations *)
let simplify_locals = "simplify-locals"

(** miscellaneous locals-related optimizations (no nesting at all; preserves flatness) *)
(** miscellaneous locals-related optimizations (no nesting at all; preserves
flatness) *)
let simplify_locals_nonesting = "simplify-locals-nonesting"

(** miscellaneous locals-related optimizations (no tees) *)
Expand Down
43 changes: 29 additions & 14 deletions src/passes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ val dae : t
(** removes arguments to calls in an lto-like manner *)

val dae_optimizing : t
(** removes arguments to calls in an lto-like manner, and optimizes where we removed *)
(** removes arguments to calls in an lto-like manner, and optimizes where we
removed *)

val abstract_type_refining : t
(** refine and merge abstract (never-created) types *)
Expand Down Expand Up @@ -76,7 +77,8 @@ val flatten : t
(** flattens out code, removing nesting *)

val fpcast_emu : t
(** emulates function pointer casts, allowing incorrect indirect calls to (sometimes) work *)
(** emulates function pointer casts, allowing incorrect indirect calls to
(sometimes) work *)

val func_metrics : t
(** reports function metrics *)
Expand All @@ -85,7 +87,9 @@ val generate_dyncalls : t
(** generate dynCall fuctions used by emscripten ABI *)

val generate_i64_dyncalls : t
(** generate dynCall functions used by emscripten ABI, but only for functions with i64 in their signature (which cannot be invoked via the wasm table without JavaScript BigInt support). *)
(** generate dynCall functions used by emscripten ABI, but only for functions
with i64 in their signature (which cannot be invoked via the wasm table
without JavaScript BigInt support). *)

val generate_global_effects : t
(** generate global effect info (helps later passes) *)
Expand All @@ -103,7 +107,8 @@ val gto : t
(** globally optimize GC types *)

val gufa : t
(** Grand Unified Flow Analysis: optimize the entire program using information about what content can actually appear in each location *)
(** Grand Unified Flow Analysis: optimize the entire program using information
about what content can actually appear in each location *)

val gufa_optimizing : t
(** GUFA plus local optimizations in functions we modified *)
Expand Down Expand Up @@ -133,7 +138,8 @@ val legalize_js_interface : t
(** legalizes i64 types on the import/export boundary *)

val legalize_js_interface_minimally : t
(** legalizes i64 types on the import/export boundary in a minimal manner, only on things only JS will call *)
(** legalizes i64 types on the import/export boundary in a minimal manner, only
on things only JS will call *)

val local_cse : t
(** common subexpression elimination inside basic blocks *)
Expand Down Expand Up @@ -178,16 +184,20 @@ val metrics : t
(** reports metrics *)

val minify_imports : t
(** minifies import names (only those, and not export names), and emits a mapping to the minified ones *)
(** minifies import names (only those, and not export names), and emits a
mapping to the minified ones *)

val minify_imports_and_exports : t
(** minifies both import and export names, and emits a mapping to the minified ones *)
(** minifies both import and export names, and emits a mapping to the minified
ones *)

val minify_imports_and_exports_and_modules : t
(** minifies both import and export names, and emits a mapping to the minified ones, and minifies the modules as well *)
(** minifies both import and export names, and emits a mapping to the minified
ones, and minifies the modules as well *)

val mod_asyncify_always_and_only_unwind : t
(** apply the assumption that asyncify imports always unwind, and we never rewind *)
(** apply the assumption that asyncify imports always unwind, and we never
rewind *)

val mod_asyncify_never_unwind : t
(** apply the assumption that asyncify never unwinds *)
Expand All @@ -202,7 +212,8 @@ val multi_memory_lowering : t
(** combines multiple memories into a single memory *)

val multi_memory_lowering_with_bounds_checks : t
(** combines multiple memories into a single memory, trapping if the read or write is larger than the length of the memory's data *)
(** combines multiple memories into a single memory, trapping if the read or
write is larger than the length of the memory's data *)

val nm : t
(** name list *)
Expand All @@ -217,7 +228,8 @@ val optimize_added_constants : t
(** optimizes added constants into load/store offsets *)

val optimize_added_constants_propagate : t
(** optimizes added constants into load/store offsets, propagating them across locals too *)
(** optimizes added constants into load/store offsets, propagating them across
locals too *)

val optimize_casts : t
(** eliminate and reuse casts *)
Expand All @@ -244,7 +256,8 @@ val precompute : t
(** computes compile-time evaluatable expressions *)

val precompute_propagate : t
(** computes compile-time evaluatable expressions and propagates them through locals *)
(** computes compile-time evaluatable expressions and propagates them through
locals *)

val print : t
(** print in s-expression format *)
Expand Down Expand Up @@ -334,13 +347,15 @@ val simplify_globals : t
(** miscellaneous globals-related optimizations *)

val simplify_globals_optimizing : t
(** miscellaneous globals-related optimizations, and optimizes where we replaced global.gets with constants *)
(** miscellaneous globals-related optimizations, and optimizes where we replaced
global.gets with constants *)

val simplify_locals : t
(** miscellaneous locals-related optimizations *)

val simplify_locals_nonesting : t
(** miscellaneous locals-related optimizations (no nesting at all; preserves flatness) *)
(** miscellaneous locals-related optimizations (no nesting at all; preserves
flatness) *)

val simplify_locals_notee : t
(** miscellaneous locals-related optimizations (no tees) *)
Expand Down