diff options
Diffstat (limited to 'main.ml')
-rw-r--r-- | main.ml | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -9,3 +9,22 @@ open Instptr | |||
9 | open Reg | 9 | open Reg |
10 | open Urm | 10 | open Urm |
11 | 11 | ||
12 | let exec_with_resource func filename = | ||
13 | let file = open_in filename in | ||
14 | let res = func file in | ||
15 | close_in file; res | ||
16 | |||
17 | let read_prgm = exec_with_resource (fun f -> string_of_file f |> program_of_string) | ||
18 | let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string) | ||
19 | let run run_func prgm regs = urm_mk prgm regs |> run_func |> regs_string |> print_endline | ||
20 | |||
21 | let run_mode_of_string = function | ||
22 | | "run" -> urm_run | ||
23 | | "trace" -> urm_run_trace | ||
24 | | _ -> failwith "Invalid run mode" | ||
25 | |||
26 | let () = match Sys.argv with | ||
27 | | [| _; "run-tests" |] -> () (* handled in test files *) | ||
28 | | [| _; mode; prgm; regs |] -> run (run_mode_of_string mode) (read_prgm prgm) (read_regs regs) | ||
29 | | _ -> print_endline "Usage: urm <run-tests | run <prgmfile> <regfile> | trace <prgmfile> <regfile>>" | ||
30 | |||