Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP
Browse files Browse the repository at this point in the history
hhugo committed Jan 13, 2025
1 parent be753c1 commit 4d07ad1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions compiler/lib-wasm/binaryen.ml
Original file line number Diff line number Diff line change
@@ -20,11 +20,13 @@ open Stdlib

let debug = Debug.find "binaryen"

let command cmdline =
let command ~output_file cmdline =
let cmdline = String.concat ~sep:" " cmdline in
if debug () then Format.eprintf "+ %s@." cmdline;
let res = Sys.command cmdline in
if res <> 0 then failwith ("the following command terminated unsuccessfully: " ^ cmdline)
if res <> 0 then failwith ("the following command terminated unsuccessfully: " ^ cmdline);
if not (Sys.file_exists output_file)
then failwith (Printf.sprintf "the following command didn't generate the expected file (%s): %s" output_file cmdline)

let common_options () =
let l =
@@ -46,7 +48,7 @@ let opt_flag flag v =
| Some v -> [ flag; Filename.quote v ]

let link ~runtime_files ~input_files ~opt_output_sourcemap ~output_file =
command
command ~output_file
("wasm-merge"
:: (common_options ()
@ List.flatten
@@ -98,7 +100,7 @@ let dead_code_elimination
@@ fun usage_file ->
let primitives = Linker.list_all () in
Fs.write_file ~name:deps_file ~contents:(generate_dependencies ~dependencies primitives);
command
command ~output_file
("wasm-metadce"
:: (common_options ()
@ [ "--graph-file"; Filename.quote deps_file; Filename.quote input_file ]
@@ -121,7 +123,7 @@ let optimize ~profile ~opt_input_sourcemap ~input_file ~opt_output_sourcemap ~ou
| None -> 1
| Some p -> fst (List.find ~f:(fun (_, p') -> Poly.equal p p') Driver.profiles)
in
command
command ~output_file
("wasm-opt"
:: (common_options ()
@ optimization_options.(level - 1)

0 comments on commit 4d07ad1

Please sign in to comment.