From 33867a832491f05bb1a88b7c7f9c4a68f3e812f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 4 Jun 2024 14:47:40 +0200 Subject: [PATCH] Start function: directly generate wasm code --- compiler/lib/wasm/wa_generate.ml | 5 +++++ compiler/lib/wasm/wa_generate.mli | 2 ++ compiler/lib/wasm/wa_link.ml | 16 ++-------------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/compiler/lib/wasm/wa_generate.ml b/compiler/lib/wasm/wa_generate.ml index 27a85ae44..7dcc3ca6d 100644 --- a/compiler/lib/wasm/wa_generate.ml +++ b/compiler/lib/wasm/wa_generate.ml @@ -1269,3 +1269,8 @@ let output ch ~context ~debug = let module G = Generate (Wa_gc_target) in let fields = G.output ~context in Wa_wat_output.f ~debug ch fields + +let wasm_output ch ~context = + let module G = Generate (Wa_gc_target) in + let fields = G.output ~context in + Wa_wasm_output.f ch fields diff --git a/compiler/lib/wasm/wa_generate.mli b/compiler/lib/wasm/wa_generate.mli index d7e2e8662..836a6393d 100644 --- a/compiler/lib/wasm/wa_generate.mli +++ b/compiler/lib/wasm/wa_generate.mli @@ -38,3 +38,5 @@ val output : -> context:Wa_code_generation.context -> debug:Parse_bytecode.Debug.t -> unit + +val wasm_output : out_channel -> context:Wa_code_generation.context -> unit diff --git a/compiler/lib/wasm/wa_link.ml b/compiler/lib/wasm/wa_link.ml index e2282b316..e14c5cd32 100644 --- a/compiler/lib/wasm/wa_link.ml +++ b/compiler/lib/wasm/wa_link.ml @@ -385,23 +385,11 @@ let read_info z = info_from_sexp (Sexp.from_string (Zip.read_entry z ~name:"info let generate_start_function ~to_link ~out_file = let t1 = Timer.make () in - Fs.gen_file out_file - @@ fun wasm_file -> - let wat_file = Filename.chop_extension out_file ^ ".wat" in - (Filename.gen_file wat_file + Filename.gen_file out_file @@ fun ch -> let context = Wa_generate.start () in Wa_generate.add_init_function ~context ~to_link:("prelude" :: to_link); - Wa_generate.output - ch - ~context - ~debug:(Parse_bytecode.Debug.create ~include_cmis:false false)); - Wa_binaryen.optimize - ~profile:(Driver.profile 1) - ~opt_input_sourcemap:None - ~opt_output_sourcemap:None - ~input_file:wat_file - ~output_file:wasm_file; + Wa_generate.wasm_output ch ~context; if times () then Format.eprintf " generate start: %a@." Timer.print t1 let output_js js =