Skip to content

Commit

Permalink
add debug option and use Bos.OS.File.writef
Browse files Browse the repository at this point in the history
  • Loading branch information
Laplace-Demon committed Aug 22, 2024
1 parent cacde25 commit 30e0962
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/ast/binary_encoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,10 @@ let write_file filename content =
let _dir, filename = Fpath.split_base filename in
let filename, _ext = Fpath.split_ext filename in
let filename = Fpath.add_ext ".wasm" filename in
let filename = Fpath.to_string filename in
let oc = Out_channel.open_bin filename in
Out_channel.output_string oc content;
Out_channel.close oc
Bos.OS.File.writef filename "%s" content

let convert (filename : Fpath.t) ~unsafe ~optimize m =
Log.debug0 "bin encoding ...@\n";
let+ m = Compile.Text.until_optimize ~unsafe ~optimize m in
let* m = Compile.Text.until_optimize ~unsafe ~optimize m in
let content = encode m in
write_file filename content
3 changes: 2 additions & 1 deletion src/bin/owi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ let rac_cmd =
let man = [] @ shared_man in
Cmd.info "rac" ~version ~doc ~sdocs ~man
in
Cmd.v info Term.(const Cmd_rac.cmd $ unsafe $ add_assert_to_assume $ files)
Cmd.v info
Term.(const Cmd_rac.cmd $ debug $ unsafe $ add_assert_to_assume $ files)

let run_cmd =
let open Cmdliner in
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/cmd_rac.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ let cmd_one unsafe add_assert_to_assume file =
| ".wat" ->
let* text_modul = Parse.Text.Module.from_file file in
let* binary_modul = Compile.Text.until_binary ~unsafe text_modul in
let+ instrumented_binary_modul =
let* instrumented_binary_modul =
Code_generator.generate add_assert_to_assume binary_modul
in
let instrumented_text_modul =
Binary_to_text.modul instrumented_binary_modul
in

let content = Fmt.str "%a" Text.pp_modul instrumented_text_modul in
let filename = Fpath.add_ext ".instrumented" filename in
let filename = Fpath.add_ext ".wat" filename in
let filename = Fpath.to_string filename in
let oc = Out_channel.open_bin filename in
Out_channel.output_string oc content;
Out_channel.close oc
let* () =
Binary_encoder.convert filename ~unsafe ~optimize:false
instrumented_text_modul
in
Bos.OS.File.writef filename "%a" Text.pp_modul instrumented_text_modul
| ext -> Error (`Unsupported_file_extension ext)

let cmd unsafe add_assert_to_assume files =
let cmd debug unsafe add_assert_to_assume files =
if debug then Log.debug_on := true;
list_iter (cmd_one unsafe add_assert_to_assume) files
2 changes: 1 addition & 1 deletion src/cmd/cmd_rac.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(* Copyright © 2021-2024 OCamlPro *)
(* Written by the Owi programmers *)

val cmd : bool -> bool -> Fpath.t list -> unit Result.t
val cmd : bool -> bool -> bool -> Fpath.t list -> unit Result.t

0 comments on commit 30e0962

Please sign in to comment.