Skip to content

Commit

Permalink
use named arguments for cmd_replay, update smtml dep
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Dec 4, 2024
1 parent 9626504 commit c738183
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
ocaml_intrinsics
(prelude (>= 0.3))
sedlex
(smtml (>= 0.3.1))
(smtml (>= 0.4.1))
uutf
xmlm
(processor (>= 0.2))
Expand Down
2 changes: 1 addition & 1 deletion owi.opam
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ depends: [
"ocaml_intrinsics"
"prelude" {>= "0.3"}
"sedlex"
"smtml" {>= "0.3.1"}
"smtml" {>= "0.4.1"}
"uutf"
"xmlm"
"processor" {>= "0.2"}
Expand Down
26 changes: 13 additions & 13 deletions src/bin/owi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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.(
Expand Down Expand Up @@ -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 *)

Expand Down Expand Up @@ -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 *)

Expand Down Expand Up @@ -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 *)

Expand All @@ -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 *)

Expand Down
14 changes: 7 additions & 7 deletions src/cmd/cmd_opt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/cmd/cmd_opt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/cmd/cmd_replay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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@."
9 changes: 8 additions & 1 deletion src/cmd/cmd_replay.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/cmd/cmd_wasm2wat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/cmd_wasm2wat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions src/cmd/cmd_wat2wasm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/cmd/cmd_wat2wasm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c738183

Please sign in to comment.