From ee0620ab054f2c486c2aef747fd81cad909ee340 Mon Sep 17 00:00:00 2001
From: Cesar Roux Dit Buisson <cr1013@imperial.ac.uk>
Date: Thu, 24 Sep 2015 12:05:19 +0100
Subject: [PATCH] Add run_trm wrap around logged version

Unfortunately pretty formatting and indentation doesn't work correctly, though this doesn't stop it from working.
---
 generator/log.ml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/generator/log.ml b/generator/log.ml
index e0e870d..8862bc6 100644
--- a/generator/log.ml
+++ b/generator/log.ml
@@ -117,6 +117,11 @@ struct
     let lines_list = snd @@ List.fold_left (fun (st, acc) ed -> (ed, String.sub s st (ed - st) :: acc)) (0, []) (end_line_markers s)
     in append_token lines_list
 
+(* Wrap the entire logged version in a callable run_trm function, and add a call to return run(code). *)
+(* Assumes entry point called run *)
+let ppf_run_wrap s =
+  Format.sprintf "function run_trm(code) {@;<1 2>@[<v 1>@,%s@,return run(code);@,}@]" s
+
 (* Take a String in form of "\n      return somefunctions(sas, ad);" and wrap it in order to allow log of function enter and exit *)
 (* TODO: Handle skipping of case where return does not contain function evaluation. (By regexp? No Brackets?) *)
 let ppf_return_wrap l s =
@@ -126,7 +131,7 @@ let ppf_return_wrap l s =
     @,var res = %s\
     @,log_custom({line: %d, type: \"exit\"});\
     @,return res;
-    @]@,}());@,@," l funccall l
+    @]}());@,@," l funccall l
 
   let add_log_info s =
     let buf = Buffer.create 16 in
@@ -166,7 +171,7 @@ let ppf_return_wrap l s =
   let logged_output s =
     let str_ppf = Format.str_formatter in
     Format.fprintf str_ppf (Scanf.format_from_string s "");
-    add_log_info (Format.flush_str_formatter ())
+    ppf_run_wrap (add_log_info (Format.flush_str_formatter ()))
   (* let bad_output = Format.flush_str_formatter () in *)
   (* let pretty_output = global_replace lfs "\n" bad_output in *)
   (* add_log_info pretty_output *)
-- 
GitLab