-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify the command line interface under one parser (interactive and in…
…terpreter)
- Loading branch information
1 parent
06b5b10
commit 9c89c64
Showing
7 changed files
with
78 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
let print_exec_state (m : Machine.mchn) = | ||
print_endline @@ Pretty_printer.string_of_exec_state (fst m) | ||
|
||
let print_reg_state (m : Machine.mchn) = | ||
let open Pretty_printer in | ||
let rs = (snd m).reg in | ||
print_endline "+-----------------------"; | ||
Machine.RegMap.iter (fun r w -> | ||
print_endline @@ string_of_reg_word r w) rs; | ||
print_endline "+-----------------------" | ||
|
||
let interpreter (m_init : Machine.mchn) = | ||
let m_final = Machine.run m_init in | ||
print_reg_state m_final; | ||
Printf.printf "Final execution state: %s\n" | ||
(Pretty_printer.string_of_exec_state (fst m_final)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
open Libinterp | ||
|
||
let print_exec_state (m : Machine.mchn) = | ||
print_endline @@ Pretty_printer.string_of_exec_state (fst m) | ||
|
||
let print_reg_state (m : Machine.mchn) = | ||
let open Pretty_printer in | ||
let rs = (snd m).reg in | ||
print_endline "+-----------------------"; | ||
Machine.RegMap.iter (fun r w -> | ||
print_endline @@ string_of_reg_word r w) rs; | ||
print_endline "+-----------------------" | ||
|
||
let () = | ||
(* very basic commandline argument parsing (to be improved) *) | ||
let filename = | ||
match Sys.argv |> Array.to_list |> List.tl with | ||
| [filename] -> filename | ||
| _ -> | ||
Printf.eprintf "usage: %s <input filename>\n" Sys.argv.(0); | ||
exit 1 | ||
let addr_max = (Int32.to_int Int32.max_int)/4096 in | ||
let (mode, filename_prog, regfile_name, size_mem) = | ||
Cli_parser.parse_arguments addr_max | ||
in | ||
|
||
(* Parse initial memory (program) *) | ||
let prog = | ||
match Program.parse_prog filename with | ||
match Program.parse_prog filename_prog with | ||
| Ok prog -> prog | ||
| Error msg -> | ||
Printf.eprintf "Parse error: %s\n" msg; | ||
Printf.eprintf "Program parse error: %s\n" msg; | ||
exit 1 | ||
in | ||
let addr_max = Z.of_int ((Int32.to_int Int32.max_int)/4096) in | ||
|
||
let init_regfile = Machine.init_reg_state addr_max in | ||
let stk_addr = | ||
Z.(if !Parameters.flags.stack then (size_mem/ ~$2) else ~$0) | ||
in | ||
|
||
(* Parse initial register file *) | ||
let regfile = | ||
let init_regfile = (Machine.init_reg_state size_mem) in | ||
if regfile_name = "" | ||
then init_regfile | ||
else | ||
(match Program.parse_regfile regfile_name size_mem stk_addr with | ||
| Ok regs -> | ||
(Machine.RegMap.fold | ||
(fun r w rf -> Machine.RegMap.add r w rf) regs) init_regfile | ||
| Error msg -> | ||
Printf.eprintf "Regfile parse error: %s\n" msg; | ||
exit 1) | ||
in | ||
let m_init = Program.init_machine prog (Some size_mem) regfile in | ||
|
||
match mode with | ||
| Cli_parser.Interactive_mode -> | ||
let module Cfg = struct let addr_max : Z.t = size_mem end in | ||
let module Ui = Interactive_ui.MkUi (Cfg) in | ||
let prog_panel_start = ref Z.zero in | ||
let stk_panel_start = ref stk_addr in | ||
Ui.render_loop ~show_stack:(!Parameters.flags.stack) prog_panel_start stk_panel_start m_init | ||
|
||
let m_init = Program.init_machine prog (Some addr_max) init_regfile in | ||
let m_final = Machine.run m_init in | ||
print_reg_state m_final; | ||
Printf.printf "Final execution state: %s\n" | ||
(Pretty_printer.string_of_exec_state (fst m_final)) | ||
| Cli_parser.Interpreter_mode -> | ||
Interpreter_ui.interpreter m_init |