Skip to content

Commit

Permalink
Start function: directly generate wasm code
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Jun 4, 2024
1 parent 41c9467 commit c19af49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
5 changes: 5 additions & 0 deletions compiler/lib/wasm/wa_generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1243,3 +1243,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
2 changes: 2 additions & 0 deletions compiler/lib/wasm/wa_generate.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,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
17 changes: 2 additions & 15 deletions compiler/lib/wasm/wa_link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,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
~opt_sourcemap_url: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 =
Expand Down

0 comments on commit c19af49

Please sign in to comment.