From c7381837951b72ede7427b7809d7d6cbbd677598 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Wed, 4 Dec 2024 21:54:25 +0100 Subject: [PATCH] use named arguments for cmd_replay, update smtml dep --- dune-project | 2 +- owi.opam | 2 +- src/bin/owi.ml | 26 +++++++++++++------------- src/cmd/cmd_opt.ml | 14 +++++++------- src/cmd/cmd_opt.mli | 4 ++-- src/cmd/cmd_replay.ml | 4 ++-- src/cmd/cmd_replay.mli | 9 ++++++++- src/cmd/cmd_wasm2wat.ml | 10 +++++----- src/cmd/cmd_wasm2wat.mli | 5 ++++- src/cmd/cmd_wat2wasm.ml | 12 ++++++------ src/cmd/cmd_wat2wasm.mli | 4 ++-- 11 files changed, 51 insertions(+), 41 deletions(-) diff --git a/dune-project b/dune-project index e258872d..5e25d364 100644 --- a/dune-project +++ b/dune-project @@ -52,7 +52,7 @@ ocaml_intrinsics (prelude (>= 0.3)) sedlex - (smtml (>= 0.3.1)) + (smtml (>= 0.4.1)) uutf xmlm (processor (>= 0.2)) diff --git a/owi.opam b/owi.opam index 3803a647..baf724e6 100644 --- a/owi.opam +++ b/owi.opam @@ -29,7 +29,7 @@ depends: [ "ocaml_intrinsics" "prelude" {>= "0.3"} "sedlex" - "smtml" {>= "0.3.1"} + "smtml" {>= "0.4.1"} "uutf" "xmlm" "processor" {>= "0.2"} diff --git a/src/bin/owi.ml b/src/bin/owi.ml index 70e9167d..ef8ef52e 100644 --- a/src/bin/owi.ml +++ b/src/bin/owi.ml @@ -56,11 +56,11 @@ let files = let f = existing_non_dir_file in Arg.(value & pos_all f [] (info [] ~doc)) -let sourcefile = +let source_file = let doc = "source file" in Arg.(required & pos 0 (some existing_non_dir_file) None (info [] ~doc)) -let outfile = +let out_file = let doc = "Write output to a file." in let string_to_path = Arg.conv ~docv:"FILE" (Fpath.of_string, Fpath.pp) in Arg.( @@ -209,9 +209,9 @@ let opt_info = let opt_cmd = let+ debug and+ unsafe - and+ sourcefile - and+ outfile in - Cmd_opt.cmd ~debug ~unsafe ~file:sourcefile ~outfile + and+ source_file + and+ out_file in + Cmd_opt.cmd ~debug ~unsafe ~source_file ~out_file (* owi instrument *) @@ -333,8 +333,8 @@ let replay_cmd = let replay_file = Cmdliner.Arg.conv (parse, Fpath.pp) in let doc = "Which replay file to use" in Arg.(required & opt (some replay_file) None & info [ "replay-file" ] ~doc) - and+ sourcefile in - Cmd_replay.cmd ~profiling ~debug ~unsafe ~optimize ~replay_file ~sourcefile + and+ source_file in + Cmd_replay.cmd ~profiling ~debug ~unsafe ~optimize ~replay_file ~source_file (* owi conc *) @@ -373,12 +373,12 @@ let wasm2wat_info = Cmd.info "wasm2wat" ~version ~doc ~sdocs ~man let wasm2wat_cmd = - let+ sourcefile + let+ source_file and+ emit_file = let doc = "Emit (.wat) files from corresponding (.wasm) files." in Arg.(value & flag & info [ "emit-file" ] ~doc) - and+ outfile in - Cmd_wasm2wat.cmd ~file:sourcefile ~emit_file ~outfile + and+ out_file in + Cmd_wasm2wat.cmd ~source_file ~emit_file ~out_file (* owi wat2wasm *) @@ -394,9 +394,9 @@ let wat2wasm_cmd = and+ debug and+ unsafe and+ optimize - and+ outfile - and+ sourcefile in - Cmd_wat2wasm.cmd ~profiling ~debug ~unsafe ~optimize ~outfile ~file:sourcefile + and+ out_file + and+ source_file in + Cmd_wat2wasm.cmd ~profiling ~debug ~unsafe ~optimize ~out_file ~source_file (* owi *) diff --git a/src/cmd/cmd_opt.ml b/src/cmd/cmd_opt.ml index bc3dc53a..c103588b 100644 --- a/src/cmd/cmd_opt.ml +++ b/src/cmd/cmd_opt.ml @@ -4,17 +4,17 @@ open Syntax -let optimize_file ~unsafe filename = +let optimize_file ~unsafe ~source_file = Compile.File.until_optimize ~unsafe ~rac:false ~srac:false ~optimize:true - filename + source_file -let print_or_emit ~unsafe file outfile = - let* m = optimize_file ~unsafe file in +let print_or_emit ~unsafe ~source_file ~out_file = + let* m = optimize_file ~unsafe ~source_file in let m = Binary_to_text.modul m in - match outfile with + match out_file with | Some name -> Bos.OS.File.writef name "%a@\n" Text.pp_modul m | None -> Ok (Fmt.pr "%a@\n" Text.pp_modul m) -let cmd ~debug ~unsafe ~file ~outfile = +let cmd ~debug ~unsafe ~source_file ~out_file = if debug then Log.debug_on := true; - print_or_emit ~unsafe file outfile + print_or_emit ~unsafe ~source_file ~out_file diff --git a/src/cmd/cmd_opt.mli b/src/cmd/cmd_opt.mli index 965f9cb4..6100f7e8 100644 --- a/src/cmd/cmd_opt.mli +++ b/src/cmd/cmd_opt.mli @@ -5,6 +5,6 @@ val cmd : debug:bool -> unsafe:bool - -> file:Fpath.t - -> outfile:Fpath.t option + -> source_file:Fpath.t + -> out_file:Fpath.t option -> unit Result.t diff --git a/src/cmd/cmd_replay.ml b/src/cmd/cmd_replay.ml index 2027f24e..0b242a09 100644 --- a/src/cmd/cmd_replay.ml +++ b/src/cmd/cmd_replay.ml @@ -115,7 +115,7 @@ let run_file ~unsafe ~optimize filename model = let c = Interpret.Concrete.modul link_state.envs m in c -let cmd profiling debug unsafe optimize replay_file file = +let cmd ~profiling ~debug ~unsafe ~optimize ~replay_file ~source_file = if profiling then Log.profiling_on := true; if debug then Log.debug_on := true; let* model = @@ -141,5 +141,5 @@ let cmd profiling debug unsafe optimize replay_file file = in Array.of_list model in - let+ () = run_file ~unsafe ~optimize file model in + let+ () = run_file ~unsafe ~optimize source_file model in Fmt.pr "All OK@." diff --git a/src/cmd/cmd_replay.mli b/src/cmd/cmd_replay.mli index 8301e917..26e38754 100644 --- a/src/cmd/cmd_replay.mli +++ b/src/cmd/cmd_replay.mli @@ -2,4 +2,11 @@ (* Copyright © 2021-2024 OCamlPro *) (* Written by the Owi programmers *) -val cmd : bool -> bool -> bool -> bool -> Fpath.t -> Fpath.t -> unit Result.t +val cmd : + profiling:bool + -> debug:bool + -> unsafe:bool + -> optimize:bool + -> replay_file:Fpath.t + -> source_file:Fpath.t + -> unit Result.t diff --git a/src/cmd/cmd_wasm2wat.ml b/src/cmd/cmd_wasm2wat.ml index 4407f19e..8511b6d3 100644 --- a/src/cmd/cmd_wasm2wat.ml +++ b/src/cmd/cmd_wasm2wat.ml @@ -5,17 +5,17 @@ open Syntax (** Utility function to handle writing to a file or printing to stdout *) -let cmd ~file ~emit_file ~outfile = - let ext = Fpath.get_ext file in +let cmd ~source_file ~emit_file ~out_file = + let ext = Fpath.get_ext source_file in match ext with | ".wasm" -> - let _dir, wat_file = Fpath.split_base file in + let _dir, wat_file = Fpath.split_base source_file in let wat_file = Fpath.set_ext "wat" wat_file in - let* m = Parse.Binary.Module.from_file file in + let* m = Parse.Binary.Module.from_file source_file in let m = Binary_to_text.modul m in let outname, output = begin - match outfile with + match out_file with | Some name -> (name, true) | None -> (wat_file, false) end diff --git a/src/cmd/cmd_wasm2wat.mli b/src/cmd/cmd_wasm2wat.mli index b8b0f96f..1cbd13ca 100644 --- a/src/cmd/cmd_wasm2wat.mli +++ b/src/cmd/cmd_wasm2wat.mli @@ -3,4 +3,7 @@ (* Written by the Owi programmers *) val cmd : - file:Fpath.t -> emit_file:bool -> outfile:Fpath.t option -> unit Result.t + source_file:Fpath.t + -> emit_file:bool + -> out_file:Fpath.t option + -> unit Result.t diff --git a/src/cmd/cmd_wat2wasm.ml b/src/cmd/cmd_wat2wasm.ml index 4b9c65c5..3643cd02 100644 --- a/src/cmd/cmd_wat2wasm.ml +++ b/src/cmd/cmd_wat2wasm.ml @@ -4,15 +4,15 @@ open Syntax -let cmd_one ~unsafe ~optimize outfile file = - let ext = Fpath.get_ext file in +let cmd_one ~unsafe ~optimize ~out_file ~source_file = + let ext = Fpath.get_ext source_file in match ext with | ".wat" -> - let* modul = Parse.Text.Module.from_file file in - Binary_encoder.convert outfile file ~unsafe ~optimize modul + let* modul = Parse.Text.Module.from_file source_file in + Binary_encoder.convert out_file source_file ~unsafe ~optimize modul | ext -> Error (`Unsupported_file_extension ext) -let cmd ~profiling ~debug ~unsafe ~optimize ~outfile ~file = +let cmd ~profiling ~debug ~unsafe ~optimize ~out_file ~source_file = if profiling then Log.profiling_on := true; if debug then Log.debug_on := true; - cmd_one ~unsafe ~optimize outfile file + cmd_one ~unsafe ~optimize ~out_file ~source_file diff --git a/src/cmd/cmd_wat2wasm.mli b/src/cmd/cmd_wat2wasm.mli index a491c20e..7cd0fcc8 100644 --- a/src/cmd/cmd_wat2wasm.mli +++ b/src/cmd/cmd_wat2wasm.mli @@ -7,6 +7,6 @@ val cmd : -> debug:bool -> unsafe:bool -> optimize:bool - -> outfile:Fpath.t option - -> file:Fpath.t + -> out_file:Fpath.t option + -> source_file:Fpath.t -> unit Result.t