blob: c6a059e76ecd8f997f7f5bbb836dde8c09604ec0 (
plain)
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
|
(*
* UPEM / L3 / Functional programming / Project: URM
* Pacien TRAN-GIRARD, Adam NAILI
*)
open Common
open Parser
open Instptr
open Reg
open Urm
open Eurm
let exec_with_resource func filename =
let file = open_in filename in
let res = func file in
close_in file; res
let read_prgm lexer = exec_with_resource (fun f -> string_of_file f |> program_of_string lexer)
let read_regs = exec_with_resource (fun f -> string_of_file f |> regs_of_string)
let run run_func prgm regs = urm_mk prgm regs |> run_func |> regs_string |> print_endline
let run_mode_of_string = function
| "run" -> urm_run
| "trace" -> urm_run_trace
| _ -> failwith "Invalid run mode"
let lexer_of_string = function
| "urm" -> (urm_program_of_lex)
| "eurm" -> (fun toks -> eurm_program_of_lex toks |> urm_from_eurm)
| _ -> failwith "Invalid lang"
let () = match Sys.argv with
| [| _; "run-tests" |] -> () (* handled in test files *)
| [| _; mode; lang; prgm; regs |] -> run (run_mode_of_string mode) (read_prgm (lexer_of_string lang) prgm) (read_regs regs)
| _ -> print_endline "Usage: urm <run | trace> <urm | eurm> <prgmfile> <regfile>"
|