-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathmain.ml
More file actions
57 lines (49 loc) · 1.88 KB
/
Copy pathmain.ml
File metadata and controls
57 lines (49 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
open Wasm_components
let name = "wasm"
let version = "1.1"
let configure () =
Wasm.Import.register (Wasm.Utf8.decode "spectest") Wasm.Spectest.lookup;
Wasm.Import.register (Wasm.Utf8.decode "env") Wasm.Env.lookup
let banner () =
print_endline (name ^ " " ^ version ^ " reference interpreter")
let usage = "Usage: " ^ name ^ " [option] [file ...]"
let args = ref []
let add_arg source = args := !args @ [source]
let quote s = "\"" ^ String.escaped s ^ "\""
let argspec = Arg.align
[
"-", Arg.Set Wasm_components.Flags.interactive,
" run interactively (default if no files given)";
"-e", Arg.String add_arg, " evaluate string";
"-i", Arg.String (fun file -> add_arg ("(input " ^ quote file ^ ")")),
" read script from file";
"-o", Arg.String (fun file -> add_arg ("(output " ^ quote file ^ ")")),
" write module to file";
"-w", Arg.Int (fun n -> Wasm_components.Flags.width := n),
" configure output width (default is 80)";
"-s", Arg.Set Flags.print_sig, " show module signatures";
"-u", Arg.Set Flags.unchecked, " unchecked, do not perform validation";
"-h", Arg.Clear Flags.harness, " exclude harness for JS conversion";
"-d", Arg.Set Flags.dry, " dry, do not run program";
"-t", Arg.Set Flags.trace, " trace execution";
"-v", Arg.Unit banner, " show version"
]
let () =
Printexc.record_backtrace true;
try
configure ();
Arg.parse argspec
(fun file -> add_arg ("(input " ^ quote file ^ ")")) usage;
List.iter (fun arg -> if not (Run.run_string arg) then exit 1) !args;
if !args = [] then Wasm_components.Flags.interactive := true;
if !Wasm_components.Flags.interactive then begin
Wasm_components.Flags.print_sig := true;
banner ();
Run.run_stdin ()
end
with exn ->
flush_all ();
prerr_endline
(Sys.argv.(0) ^ ": uncaught exception " ^ Printexc.to_string exn);
Printexc.print_backtrace stderr;
exit 2