diff --git a/CHANGES.md b/CHANGES.md index b6aceb20..56e01632 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ ## unreleased -- `wat2wasm` emit wasm files in same dir as wat files +- add `--output` option to `wat2wasm`, `wasm2wat` and `opt` cmd - add `--emit-file` option to `wasm2wat` to emit .wat files - adds flags `--fail-on-trap-only` and `fail-on-assertion-only` - parameterize the `Thread` module on the symbolic memory and the `Choice_monad` module on a Thread diff --git a/example/opt/README.md b/example/opt/README.md index eac22663..0dff811b 100644 --- a/example/opt/README.md +++ b/example/opt/README.md @@ -377,7 +377,7 @@ OPTIONS debug mode -o FILE, --output=FILE - wat + Write output to a file. -u, --unsafe skip typechecking pass diff --git a/example/wasm2wat/README.md b/example/wasm2wat/README.md index 3a8474f9..c5eac4f8 100644 --- a/example/wasm2wat/README.md +++ b/example/wasm2wat/README.md @@ -31,10 +31,10 @@ SYNOPSIS OPTIONS --emit-file - emit (.wat) files from corresponding (.wasm) files + Emit (.wat) files from corresponding (.wasm) files. -o FILE, --output=FILE - wasm + Write output to a file. COMMON OPTIONS --help[=FMT] (default=auto) diff --git a/example/wat2wasm/README.md b/example/wat2wasm/README.md index 3877b02f..57b5c744 100644 --- a/example/wat2wasm/README.md +++ b/example/wat2wasm/README.md @@ -41,7 +41,7 @@ OPTIONS debug mode -o FILE, --output=FILE - wat + Write output to a file. --optimize optimize mode diff --git a/src/bin/owi.ml b/src/bin/owi.ml index dfc9e1c6..078bfa25 100644 --- a/src/bin/owi.ml +++ b/src/bin/owi.ml @@ -39,13 +39,13 @@ let files = let f = existing_non_dir_file in Cmdliner.Arg.(value & pos_all f [] (info [] ~doc)) -let sourcefile ty = - let doc = Fmt.str "%s source file" ty in +let sourcefile = + let doc = "source file" in let f = existing_non_dir_file in Cmdliner.Arg.(required & pos 0 (some f) None (info [] ~doc)) -let outfile ty = - let doc = Fmt.str "%s" ty in +let outfile = + let doc = "Write output to a file." in let string_to_path = Cmdliner.Arg.conv ~docv:"FILE" (Fpath.of_string, Fpath.pp) in @@ -54,8 +54,8 @@ let outfile ty = & opt (some string_to_path) None & info [ "o"; "output" ] ~docv:"FILE" ~doc ) -let emit_files = - let doc = "emit (.wat) files from corresponding (.wasm) files" in +let emit_file = + let doc = "Emit (.wat) files from corresponding (.wasm) files." in Cmdliner.Arg.(value & flag & info [ "emit-file" ] ~doc) let no_exhaustion = @@ -196,8 +196,7 @@ let opt_cmd = let man = [] @ shared_man in Cmd.info "opt" ~version ~doc ~sdocs ~man in - Cmd.v info - Term.(const Cmd_opt.cmd $ debug $ unsafe $ sourcefile "wat" $ outfile "wat") + Cmd.v info Term.(const Cmd_opt.cmd $ debug $ unsafe $ sourcefile $ outfile) let run_cmd = let open Cmdliner in @@ -265,9 +264,7 @@ let wasm2wat_cmd = let man = [] @ shared_man in Cmd.info "wasm2wat" ~version ~doc ~sdocs ~man in - Cmd.v info - Term.( - const Cmd_wasm2wat.cmd $ sourcefile "wasm" $ emit_files $ outfile "wasm" ) + Cmd.v info Term.(const Cmd_wasm2wat.cmd $ sourcefile $ emit_file $ outfile) let wat2wasm_cmd = let open Cmdliner in @@ -280,8 +277,8 @@ let wat2wasm_cmd = in Cmd.v info Term.( - const Cmd_wat2wasm.cmd $ profiling $ debug $ unsafe $ optimize - $ outfile "wat" $ sourcefile "wat" ) + const Cmd_wat2wasm.cmd $ profiling $ debug $ unsafe $ optimize $ outfile + $ sourcefile ) let cli = let open Cmdliner in diff --git a/src/cmd/cmd_opt.ml b/src/cmd/cmd_opt.ml index 42fe99fa..95ff24af 100644 --- a/src/cmd/cmd_opt.ml +++ b/src/cmd/cmd_opt.ml @@ -8,7 +8,7 @@ let optimize_file ~unsafe filename = Compile.File.until_optimize ~unsafe ~optimize:true filename let print_or_emit ~unsafe file outfile = - let+ m = optimize_file ~unsafe file in + let* m = optimize_file ~unsafe file in let m = Binary_to_text.modul m in match outfile with | Some name -> Bos.OS.File.writef name "%a@\n" Text.pp_modul m @@ -16,4 +16,4 @@ let print_or_emit ~unsafe file outfile = let cmd debug unsafe file outfile = if debug then Log.debug_on := true; - Result.bind (print_or_emit ~unsafe file outfile) (fun _ -> Ok ()) + print_or_emit ~unsafe file outfile diff --git a/test/opt/output.t b/test/opt/output.t new file mode 100644 index 00000000..f99c975c --- /dev/null +++ b/test/opt/output.t @@ -0,0 +1,10 @@ + $ owi opt fbinop.wat -o bar.wat + $ owi fmt bar.wat + (module + + (type (sub final (func))) + (func $start + + ) + (start 0) + ) diff --git a/test/wasm2wat/output.t b/test/wasm2wat/output.t new file mode 100644 index 00000000..ad270c4f --- /dev/null +++ b/test/wasm2wat/output.t @@ -0,0 +1,20 @@ + $ owi wasm2wat done.wasm -o bar.wat + $ owi fmt bar.wat + (module + + (type (sub final (func (param i32) (param i32) (result i32)))) + + (type (sub final (func))) + (func (param i32) (param i32) (result i32) + local.get 0 + local.get 1 + i32.add + ) + (func + i32.const 22 + i32.const 20 + call 0 + drop + ) + (start 1) + ) diff --git a/test/wat2wasm/output.t b/test/wat2wasm/output.t new file mode 100644 index 00000000..2cff8873 --- /dev/null +++ b/test/wat2wasm/output.t @@ -0,0 +1,26 @@ + $ owi wat2wasm func.wat -o bar.wasm + $ owi run bar.wasm --debug + typechecking ... + linking ... + interpreting ... + stack : [ ] + running instr: call 1 + calling func : func anonymous + stack : [ ] + running instr: f32.const 40.400_001_525_878_906 + stack : [ f32.const 40.400_001_525_878_906 ] + running instr: call 0 + calling func : func anonymous + stack : [ ] + running instr: f32.const 2.019_999_980_926_513_7 + stack : [ f32.const 2.019_999_980_926_513_7 ] + running instr: local.tee 1 + stack : [ f32.const 2.019_999_980_926_513_7 ] + running instr: local.get 0 + stack : [ f32.const 40.400_001_525_878_906 ; f32.const 2.019_999_980_926_513_7 ] + running instr: f32.add + stack : [ f32.const 42.420_001_983_642_578 ] + stack : [ f32.const 42.420_001_983_642_578 ] + running instr: drop + stack : [ ] + stack : [ ]