File tree Expand file tree Collapse file tree 5 files changed +63
-5
lines changed Expand file tree Collapse file tree 5 files changed +63
-5
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,9 @@ let with_runtime_files ~runtime_wasm_files f =
9090
9191let build_runtime ~runtime_file =
9292 (* Keep this variables in sync with gen/gen.ml *)
93- let variables = [] in
93+ let variables =
94+ [ " wasi" , Config.Flag. wasi () ; " trap-on-exception" , Config.Flag. trap_on_exception () ]
95+ in
9496 match
9597 List. find_opt Runtime_files. precompiled_runtimes ~f: (fun (flags , _ ) ->
9698 assert (
@@ -107,7 +109,9 @@ let build_runtime ~runtime_file =
107109 ; file = module_name ^ " .wat"
108110 ; source = Contents contents
109111 })
110- Runtime_files. wat_files
112+ (if Config.Flag. wasi ()
113+ then (" libc" , Runtime_files. wasi_libc) :: Runtime_files. wat_files
114+ else Runtime_files. wat_files)
111115 in
112116 Runtime. build
113117 ~link_options: [ " -g" ]
Original file line number Diff line number Diff line change 2727 gen/gen.exe
2828 ../../runtime/wasm/runtime.js
2929 ../../runtime/wasm/deps.json
30+ ../../runtime/wasm/runtime-wasi.js
31+ ../../runtime/wasm/deps-wasi.json
32+ ../../runtime/wasm/libc.wasm
3033 (glob_files ../../runtime/wasm/*.wat)
3134 (glob_files ../../runtime/wasm/runtime-*.wasm))
3235 (action
Original file line number Diff line number Diff line change @@ -3,9 +3,9 @@ let read_file ic = really_input_string ic (in_channel_length ic)
33(* Keep the two variables below in sync with function build_runtime in
44 ../compile.ml *)
55
6- let default_flags = []
6+ let default_flags = [ " trap-on-exception " , false ]
77
8- let interesting_runtimes = [ [] ]
8+ let interesting_runtimes = [ [ " wasi " , false ]; [ " wasi " , true ] ]
99
1010let name_runtime l =
1111 let flags = List. filter_map (fun (k , v ) -> if v then Some k else None ) l in
@@ -30,10 +30,19 @@ let () =
3030 Format. printf
3131 " let dependencies = \" %s\" @."
3232 (String. escaped (read_file (open_in_bin Sys. argv.(2 ))));
33+ Format. printf
34+ " let js_wasi_launcher = \" %s\" @."
35+ (String. escaped (read_file (open_in_bin Sys. argv.(3 ))));
36+ Format. printf
37+ " let wasi_dependencies = \" %s\" @."
38+ (String. escaped (read_file (open_in_bin Sys. argv.(4 ))));
39+ Format. printf
40+ " let wasi_libc = \" %s\" @."
41+ (String. escaped (read_file (open_in_bin Sys. argv.(5 ))));
3342 let wat_files, runtimes =
3443 List. partition
3544 (fun f -> Filename. check_suffix f " .wat" )
36- (Array. to_list (Array. sub Sys. argv 3 (Array. length Sys. argv - 3 )))
45+ (Array. to_list (Array. sub Sys. argv 6 (Array. length Sys. argv - 6 )))
3746 in
3847 Format. printf
3948 " let wat_files = [%a]@."
Original file line number Diff line number Diff line change @@ -407,6 +407,32 @@ let rec rewrite_list st l = List.iter ~f:(rewrite st) l
407407
408408and rewrite st elt =
409409 match elt with
410+ | { desc =
411+ List
412+ ({ desc = Atom " try" ; _ }
413+ :: ( { desc = List ({ desc = Atom " result" ; _ } :: _); _ }
414+ :: { desc = List ({ desc = Atom " do" ; loc = _, pos_after_do } :: body)
415+ ; loc = _, pos_after_body
416+ }
417+ :: _
418+ | { desc = List ({ desc = Atom " do" ; loc = _, pos_after_do } :: body)
419+ ; loc = _, pos_after_body
420+ }
421+ :: _ ))
422+ ; loc = pos, pos'
423+ }
424+ when false (* ZZZ StringMap.find "trap-on-exception" st.variables*) ->
425+ write st pos;
426+ Buffer. add_string st.buf " (block" ;
427+ skip st pos_after_do;
428+ rewrite_list st body;
429+ write st pos_after_body;
430+ skip st pos'
431+ | { desc = List ({ desc = Atom " throw" ; _ } :: _); loc = pos, pos' }
432+ when false (* ZZZ StringMap.find "trap-on-exception" st.variables*) ->
433+ write st pos;
434+ Buffer. add_string st.buf " (unreachable)" ;
435+ skip st pos'
410436 | { desc =
411437 List
412438 [ { desc = Atom " @if" ; _ }
Original file line number Diff line number Diff line change 1616 ../../compiler/bin-wasm_of_ocaml/wasmoo_link_wasm.exe
1717 --binaryen=-g
1818 --binaryen-opt=-O3
19+ --disable wasi
20+ %{target}
21+ %{read-lines:args})))
22+
23+ (rule
24+ (target runtime-wasi.wasm)
25+ (deps
26+ args
27+ (glob_files *.wat))
28+ (action
29+ (run
30+ wasmoo_util
31+ link
32+ --binaryen=-g
33+ --binaryen-opt=-O3
34+ --enable wasi
1935 %{target}
2036 %{read-lines:args})))
2137
You can’t perform that action at this time.
0 commit comments