File tree 5 files changed +63
-5
lines changed 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 =
90
90
91
91
let build_runtime ~runtime_file =
92
92
(* 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
94
96
match
95
97
List. find_opt Runtime_files. precompiled_runtimes ~f: (fun (flags , _ ) ->
96
98
assert (
@@ -107,7 +109,9 @@ let build_runtime ~runtime_file =
107
109
; file = module_name ^ " .wat"
108
110
; source = Contents contents
109
111
})
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)
111
115
in
112
116
Runtime. build
113
117
~link_options: [ " -g" ]
Original file line number Diff line number Diff line change 27
27
gen/gen.exe
28
28
../../runtime/wasm/runtime.js
29
29
../../runtime/wasm/deps.json
30
+ ../../runtime/wasm/runtime-wasi.js
31
+ ../../runtime/wasm/deps-wasi.json
32
+ ../../runtime/wasm/libc.wasm
30
33
(glob_files ../../runtime/wasm/*.wat)
31
34
(glob_files ../../runtime/wasm/runtime-*.wasm))
32
35
(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)
3
3
(* Keep the two variables below in sync with function build_runtime in
4
4
../compile.ml *)
5
5
6
- let default_flags = []
6
+ let default_flags = [ " trap-on-exception " , false ]
7
7
8
- let interesting_runtimes = [ [] ]
8
+ let interesting_runtimes = [ [ " wasi " , false ]; [ " wasi " , true ] ]
9
9
10
10
let name_runtime l =
11
11
let flags = List. filter_map (fun (k , v ) -> if v then Some k else None ) l in
@@ -30,10 +30,19 @@ let () =
30
30
Format. printf
31
31
" let dependencies = \" %s\" @."
32
32
(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 ))));
33
42
let wat_files, runtimes =
34
43
List. partition
35
44
(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 )))
37
46
in
38
47
Format. printf
39
48
" 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
407
407
408
408
and rewrite st elt =
409
409
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'
410
436
| { desc =
411
437
List
412
438
[ { desc = Atom " @if" ; _ }
Original file line number Diff line number Diff line change 16
16
../../compiler/bin-wasm_of_ocaml/wasmoo_link_wasm.exe
17
17
--binaryen=-g
18
18
--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
19
35
%{target}
20
36
%{read-lines:args})))
21
37
You can’t perform that action at this time.
0 commit comments