Skip to content

Commit da30036

Browse files
vouillonhhugo
authored andcommitted
Output a Wasm binary module rather than a text file when possible
This is faster to write a binary file, and then for binaryen to parse a binary file. We still output a Wasm text file when source maps are enabled (we don't yet supported writing a source map file together with a Wasm binary module) or when `--debug wat` is set.
1 parent 9239d10 commit da30036

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

compiler/bin-wasm_of_ocaml/compile.ml

+3-12
Original file line numberDiff line numberDiff line change
@@ -246,23 +246,14 @@ let generate_prelude ~out_file =
246246
~deadcode_sentinal
247247
program
248248
in
249-
Generate.output ch ~context;
249+
Generate.wasm_output ch ~context;
250250
uinfo.provides
251251

252252
let build_prelude z =
253253
Fs.with_intermediate_file (Filename.temp_file "prelude" ".wasm")
254254
@@ fun prelude_file ->
255-
Fs.with_intermediate_file (Filename.temp_file "prelude_file" ".wasm")
256-
@@ fun tmp_prelude_file ->
257255
let predefined_exceptions = generate_prelude ~out_file:prelude_file in
258-
Binaryen.optimize
259-
~profile:Profile.O1
260-
~input_file:prelude_file
261-
~output_file:tmp_prelude_file
262-
~opt_input_sourcemap:None
263-
~opt_output_sourcemap:None
264-
();
265-
Zip.add_file z ~name:"prelude.wasm" ~file:tmp_prelude_file;
256+
Zip.add_file z ~name:"prelude.wasm" ~file:prelude_file;
266257
predefined_exceptions
267258

268259
let build_js_runtime ~primitives ?runtime_arguments () =
@@ -408,7 +399,7 @@ let run
408399
program
409400
in
410401
if standalone then Generate.add_start_function ~context toplevel_name;
411-
Generate.output ch ~context;
402+
Generate.output ch ~enable_source_maps ~context;
412403
if times () then Format.eprintf "compilation: %a@." Timer.print t;
413404
generated_js
414405
in

compiler/lib-wasm/generate.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,12 @@ let add_start_function = G.add_start_function
13151315

13161316
let add_init_function = G.add_init_function
13171317

1318-
let output ch ~context =
1318+
let output ch ~enable_source_maps ~context =
13191319
let t = Timer.make () in
13201320
let fields = G.output ~context in
1321-
Wat_output.f ch fields;
1321+
if enable_source_maps || Debug.find "wat" ()
1322+
then Wat_output.f ch fields
1323+
else Wasm_output.f ch fields;
13221324
if times () then Format.eprintf " output: %a@." Timer.print t
13231325

13241326
let wasm_output ch ~context =

compiler/lib-wasm/generate.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ val add_start_function : context:Code_generation.context -> Wasm_ast.var -> unit
3333

3434
val add_init_function : context:Code_generation.context -> to_link:string list -> unit
3535

36-
val output : out_channel -> context:Code_generation.context -> unit
36+
val output :
37+
out_channel -> enable_source_maps:bool -> context:Code_generation.context -> unit
3738

3839
val wasm_output : out_channel -> context:Code_generation.context -> unit

0 commit comments

Comments
 (0)