From 3e0c5de7c0434678218a6583887f7b849dc684f9 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 27 Apr 2018 11:59:42 +0200 Subject: Implement trace mode --- reg.ml | 4 ++-- urm.ml | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/reg.ml b/reg.ml index 133ef21..d065838 100644 --- a/reg.ml +++ b/reg.ml @@ -8,7 +8,7 @@ open Common let reg_idx (Reg(idx, _)) = idx let reg_val (Reg(_, value)) = value let reg_compar l r = (reg_val l) - (reg_val r) -let reg_string (Reg (index, value)) = (string_of_int index) ^ ": " ^ (string_of_int value) +let reg_string (Reg (index, value)) = "(" ^ (string_of_int index) ^ "," ^ (string_of_int value) ^ ")" let regs_get reglist index = List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val @@ -16,5 +16,5 @@ let regs_get reglist index = let regs_set reglist index value = Reg(index, value) :: List.filter (fun (Reg(idx, _)) -> idx != index) reglist -let regs_string reglist = List.map (reg_string) reglist |> String.concat ", " +let regs_string reglist = List.map (reg_string) reglist |> String.concat "," diff --git a/urm.ml b/urm.ml index be9f7e4..3b7068b 100644 --- a/urm.ml +++ b/urm.ml @@ -23,12 +23,18 @@ let urm_apply urm = | _, _ -> { instptr = urm.instptr ; regs = urm.regs } |> urm_move_down in if instptr_end urm.instptr then urm else aux (instptr_get urm.instptr) -(* Launches the URM *) -let rec urm_run = function +let rec urm_run_pre pre = function | { instptr = InstPtr(_, []) ; regs = reg_list } -> reg_list - | urm -> urm_apply urm |> urm_run + | urm -> pre urm; urm_apply urm |> urm_run_pre pre -let urm_run_trace = urm_run (* TODO *) +let urm_run = urm_run_pre (fun _ -> ()) + +let urm_run_trace = + let print_func u = + print_endline (instptr_string u.instptr); + print_endline (regs_string u.regs); + print_newline () + in urm_run_pre (print_func) (* Creates an URM from a command list and a register list *) let urm_mk cmd_list reg_list = { instptr = (instptr_mk cmd_list) ; regs = reg_list } -- cgit v1.2.3