Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use more precise Wasm types #1907

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion compiler/bin-wasm_of_ocaml/build_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ let info =
~description:"Wasm_of_ocaml is a compiler from OCaml bytecode to WebAssembly."

let command =
let t = Cmdliner.Term.(const Compile.run $ Cmd_arg.options_runtime_only) in
let t = Cmdliner.Term.(const Compile.run $ Cmd_arg.options_runtime_only ()) in
Cmdliner.Cmd.v info t
4 changes: 2 additions & 2 deletions compiler/bin-wasm_of_ocaml/cmd_arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type t =
; effects : Config.effects_backend
}

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

let options_runtime_only =
let options_runtime_only () =
let runtime_files =
let doc = "Link JavaScript and WebAssembly files [$(docv)]. " in
Arg.(value & pos_all string [] & info [] ~docv:"RUNTIME_FILES" ~doc)
Expand Down
4 changes: 2 additions & 2 deletions compiler/bin-wasm_of_ocaml/cmd_arg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ type t =
; effects : Config.effects_backend
}

val options : t Cmdliner.Term.t
val options : unit -> t Cmdliner.Term.t

val options_runtime_only : t Cmdliner.Term.t
val options_runtime_only : unit -> t Cmdliner.Term.t
18 changes: 14 additions & 4 deletions compiler/bin-wasm_of_ocaml/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ let times = Debug.find "times"

let debug_mem = Debug.find "mem"

let debug_wat = Debug.find "wat"

let () = Sys.catch_break true

let update_sourcemap ~sourcemap_root ~sourcemap_don't_inline_content sourcemap_file =
Expand Down Expand Up @@ -425,7 +427,11 @@ let run
else None)
@@ fun opt_tmp_map_file ->
let unit_data =
Fs.with_intermediate_file (Filename.temp_file unit_name ".wat")
(if debug_wat ()
then
fun f ->
f (Filename.concat (Filename.dirname output_file) (unit_name ^ ".wat"))
else Fs.with_intermediate_file (Filename.temp_file unit_name ".wat"))
@@ fun wat_file ->
let strings, fragments =
output_gen wat_file (output code ~unit_name:(Some unit_name))
Expand Down Expand Up @@ -454,7 +460,9 @@ let run
ic
in
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
Fs.with_intermediate_file (Filename.temp_file "code" ".wat")
(if debug_wat ()
then fun f -> f (Filename.chop_extension output_file ^ ".wat")
else Fs.with_intermediate_file (Filename.temp_file "code" ".wat"))
@@ fun wat_file ->
let dir = Filename.chop_extension output_file ^ ".assets" in
Link.gen_dir dir
Expand Down Expand Up @@ -575,8 +583,10 @@ let info name =
~doc:"Wasm_of_ocaml compiler"
~description:"Wasm_of_ocaml is a compiler from OCaml bytecode to WebAssembly."

let term = Cmdliner.Term.(const run $ Cmd_arg.options)
let options = Cmd_arg.options ()

let term = Cmdliner.Term.(const run $ options)

let command =
let t = Cmdliner.Term.(const run $ Cmd_arg.options) in
let t = Cmdliner.Term.(const run $ options) in
Cmdliner.Cmd.v (info "compile") t
6 changes: 3 additions & 3 deletions compiler/bin-wasm_of_ocaml/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type t =
; enable_source_maps : bool
}

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

let command =
let t = Cmdliner.Term.(const f $ options) in
let command () =
let t = Cmdliner.Term.(const f $ options ()) in
Cmdliner.Cmd.v info t
2 changes: 1 addition & 1 deletion compiler/bin-wasm_of_ocaml/link.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

val command : unit Cmdliner.Cmd.t
val command : unit -> unit Cmdliner.Cmd.t
2 changes: 1 addition & 1 deletion compiler/bin-wasm_of_ocaml/wasm_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let () =
(Cmdliner.Cmd.group
~default:Compile.term
(Compile.info "wasm_of_ocaml")
[ Link.command
[ Link.command ()
; Build_runtime.command
; Compile.command
; Preprocess.command
Expand Down
4 changes: 3 additions & 1 deletion compiler/lib-wasm/closure_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ open Code
type closure =
{ functions : (Var.t * int) list
; free_variables : Var.t list
; mutable id : int option
}

module SCC = Strongly_connected_components.Make (Var)
Expand Down Expand Up @@ -144,7 +145,8 @@ let rec traverse var_depth closures program pc depth =
in
List.iter
~f:(fun (f, _) ->
closures := Var.Map.add f { functions; free_variables } !closures)
closures :=
Var.Map.add f { functions; free_variables; id = None } !closures)
functions;
fun_lst)
components
Expand Down
1 change: 1 addition & 0 deletions compiler/lib-wasm/closure_conversion.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
type closure =
{ functions : (Code.Var.t * int) list
; free_variables : Code.Var.t list
; mutable id : int option
}

val f : Code.program -> Code.program * closure Code.Var.Map.t
Loading
Loading