Skip to content

Commit 6ac57ea

Browse files
vouillonhhugo
authored andcommitted
[wasm] Add a debug option to keep wat files
1 parent 3ca0d2e commit 6ac57ea

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed

compiler/bin-wasm_of_ocaml/build_runtime.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ let info =
2525
~description:"Wasm_of_ocaml is a compiler from OCaml bytecode to WebAssembly."
2626

2727
let command =
28-
let t = Cmdliner.Term.(const Compile.run $ Cmd_arg.options_runtime_only) in
28+
let t = Cmdliner.Term.(const Compile.run $ Cmd_arg.options_runtime_only ()) in
2929
Cmdliner.Cmd.v info t

compiler/bin-wasm_of_ocaml/cmd_arg.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type t =
6363
; effects : Config.effects_backend
6464
}
6565

66-
let options =
66+
let options () =
6767
let runtime_files =
6868
let doc = "Link JavaScript and WebAssembly files [$(docv)]. " in
6969
Arg.(value & pos_left ~rev:true 0 string [] & info [] ~docv:"RUNTIME_FILES" ~doc)
@@ -189,7 +189,7 @@ let options =
189189
in
190190
Term.ret t
191191

192-
let options_runtime_only =
192+
let options_runtime_only () =
193193
let runtime_files =
194194
let doc = "Link JavaScript and WebAssembly files [$(docv)]. " in
195195
Arg.(value & pos_all string [] & info [] ~docv:"RUNTIME_FILES" ~doc)

compiler/bin-wasm_of_ocaml/cmd_arg.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ type t =
3434
; effects : Config.effects_backend
3535
}
3636

37-
val options : t Cmdliner.Term.t
37+
val options : unit -> t Cmdliner.Term.t
3838

39-
val options_runtime_only : t Cmdliner.Term.t
39+
val options_runtime_only : unit -> t Cmdliner.Term.t

compiler/bin-wasm_of_ocaml/compile.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ let times = Debug.find "times"
2424

2525
let debug_mem = Debug.find "mem"
2626

27+
let debug_wat = Debug.find "wat"
28+
2729
let () = Sys.catch_break true
2830

2931
let update_sourcemap ~sourcemap_root ~sourcemap_don't_inline_content sourcemap_file =
@@ -425,7 +427,11 @@ let run
425427
else None)
426428
@@ fun opt_tmp_map_file ->
427429
let unit_data =
428-
Fs.with_intermediate_file (Filename.temp_file unit_name ".wat")
430+
(if debug_wat ()
431+
then
432+
fun f ->
433+
f (Filename.concat (Filename.dirname output_file) (unit_name ^ ".wat"))
434+
else Fs.with_intermediate_file (Filename.temp_file unit_name ".wat"))
429435
@@ fun wat_file ->
430436
let strings, fragments =
431437
output_gen wat_file (output code ~unit_name:(Some unit_name))
@@ -454,7 +460,9 @@ let run
454460
ic
455461
in
456462
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
457-
Fs.with_intermediate_file (Filename.temp_file "code" ".wat")
463+
(if debug_wat ()
464+
then fun f -> f (Filename.chop_extension output_file ^ ".wat")
465+
else Fs.with_intermediate_file (Filename.temp_file "code" ".wat"))
458466
@@ fun wat_file ->
459467
let dir = Filename.chop_extension output_file ^ ".assets" in
460468
Link.gen_dir dir
@@ -575,8 +583,10 @@ let info name =
575583
~doc:"Wasm_of_ocaml compiler"
576584
~description:"Wasm_of_ocaml is a compiler from OCaml bytecode to WebAssembly."
577585

578-
let term = Cmdliner.Term.(const run $ Cmd_arg.options)
586+
let options = Cmd_arg.options ()
587+
588+
let term = Cmdliner.Term.(const run $ options)
579589

580590
let command =
581-
let t = Cmdliner.Term.(const run $ Cmd_arg.options) in
591+
let t = Cmdliner.Term.(const run $ options) in
582592
Cmdliner.Cmd.v (info "compile") t

compiler/bin-wasm_of_ocaml/link.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type t =
2929
; enable_source_maps : bool
3030
}
3131

32-
let options =
32+
let options () =
3333
let output_file =
3434
let doc = "Set output file name to [$(docv)]." in
3535
Arg.(required & opt (some string) None & info [ "o" ] ~docv:"FILE" ~doc)
@@ -91,6 +91,6 @@ let info =
9191
"wasm_of_ocaml-link links together several wasm_of_ocaml intermediate files to \
9292
produce either a library or some executable code."
9393

94-
let command =
95-
let t = Cmdliner.Term.(const f $ options) in
94+
let command () =
95+
let t = Cmdliner.Term.(const f $ options ()) in
9696
Cmdliner.Cmd.v info t

compiler/bin-wasm_of_ocaml/link.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717
*)
1818

19-
val command : unit Cmdliner.Cmd.t
19+
val command : unit -> unit Cmdliner.Cmd.t

compiler/bin-wasm_of_ocaml/wasm_of_ocaml.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let () =
4848
(Cmdliner.Cmd.group
4949
~default:Compile.term
5050
(Compile.info "wasm_of_ocaml")
51-
[ Link.command
51+
[ Link.command ()
5252
; Build_runtime.command
5353
; Compile.command
5454
; Preprocess.command

0 commit comments

Comments
 (0)