aboutsummaryrefslogtreecommitdiff
path: root/main.ml
diff options
context:
space:
mode:
Diffstat (limited to 'main.ml')
-rw-r--r--main.ml19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.ml b/main.ml
index 1bb6704..2f8d57c 100644
--- a/main.ml
+++ b/main.ml
@@ -9,3 +9,22 @@ open Instptr
9open Reg 9open Reg
10open Urm 10open Urm
11 11
12let exec_with_resource func filename =
13 let file = open_in filename in
14 let res = func file in
15 close_in file; res
16
17let read_prgm = exec_with_resource (fun f -> string_of_file f |> program_of_string)
18let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string)
19let run run_func prgm regs = urm_mk prgm regs |> run_func |> regs_string |> print_endline
20
21let run_mode_of_string = function
22 | "run" -> urm_run
23 | "trace" -> urm_run_trace
24 | _ -> failwith "Invalid run mode"
25
26let () = 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