From 45552c629fedcb120c3fa59e5a71293bce192ec7 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Tue, 30 Aug 2016 14:33:12 +0200
Subject: [PATCH] -ec: translate merge into if-then-else.

---
 src/licDump.ml | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/src/licDump.ml b/src/licDump.ml
index df271a00..88c9b869 100644
--- a/src/licDump.ml
+++ b/src/licDump.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 26/08/2016 (at 10:32) by Erwan Jahier> *)
+(* Time-stamp: <modified the 26/08/2016 (at 16:49) by Erwan Jahier> *)
 
 open Lv6errors
 open Printf
@@ -586,14 +586,34 @@ and string_of_val_exp_eff_core ve_core =
        )
      )
   | Merge (ve, cl) -> (
+    if global_opt.lv4 then (
+      let c1, cl = match cl with c1::cl -> c1,cl | [] -> assert false (*sno*) in
+      let get_cond_and_then (id,ve) =
+        let clk = match ve.ve_clk with
+          | [On((cc,cv,Bool_type_eff),_)] -> cv
+          | _ -> assert false (* SNO *)
+        in
+        let expr = string_of_val_exp_eff ve in
+        clk, expr
+      in
+      let print_case c =
+        let clk,expr = get_cond_and_then c in
+        Printf.sprintf " if %s then current(%s) else " clk expr
+      in
+      let cl_str = List.map print_case cl in
+      let clk1,expr1 = get_cond_and_then c1 in
+      let last_case = "current("^expr1^") (*"^clk1^"*)\n" in
+      let str = (String.concat "" cl_str) ^ last_case in
+      str
+    ) else (
     "merge " ^ (string_of_val_exp_eff ve) ^ " " ^
-      (String.concat " " 
-                     (List.map 
-                        (fun (id,ve) -> "( "^(string_of_const_eff id.it) ^ " -> " ^ 
-                                          (string_of_val_exp_eff ve)^" )")
-                        cl
-                     )
+      (String.concat
+         " " (List.map 
+                (fun (id,ve) -> "( "^(string_of_const_eff id.it) ^ " -> " ^ 
+                                  (string_of_val_exp_eff ve)^" )")
+                cl)
       )
+    )
   )
   | CallByNameLic(by_name_op_eff, fl) -> 
      (match by_name_op_eff.it with
@@ -614,7 +634,7 @@ and string_of_val_exp_eff_core ve_core =
 
 and wrap_long_line str = 
   if String.length str < 75 then str else
-    let str_list = Str.split (Str.regexp " ") str in
+    let str_list = Str.split (Str.regexp "[ \t]+") str in
     let new_str, reste =
       List.fold_left
         (fun (accl, acc_str) str ->
@@ -649,23 +669,15 @@ and (string_of_eq : Lic.eq_info srcflagged -> string) =
   fun eq_eff ->
   string_of_eq_info_eff eq_eff.it
 
-
-
 and wrap_long_profile str = 
-
   if String.length str < 75 then str else
-    "\n"^(
-    Str.global_replace (Str.regexp "returns") "\nreturns"
-                       (Str.global_replace (Str.regexp "(") "(\n\t"
-                                           (Str.global_replace (Str.regexp "; ") ";\n\t" str)))  
+    "\n"^(Str.global_replace (Str.regexp "returns") "\nreturns" str)
 
 and (profile_of_node_exp_eff: Lic.node_exp -> string) =
   fun neff ->
-  
   ("(" ^ (string_of_type_decl_list  neff.inlist_eff "; ") ^ ") returns (" ^
 	  (string_of_type_decl_list neff.outlist_eff "; ") ^ ")")
 
-
 and (string_of_node_def : Lic.node_def -> string list) =
   function
   | ExternLic
-- 
GitLab