From 9253be2f37805f297061e9b241db6dd075b11b96 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Thu, 19 Jun 2014 11:12:07 +0200
Subject: [PATCH] Soc2c: Fix 2 bugs in the C code generation.

The first one in Soc2cIdent.type_to_short_string when enum and int were both
translated by "i" ; as a consequence, some different soc ctx get the same name.

The second one was due to the fact that car ident in gao switches were
printed incorrectly (missing "ctx->" or "node_no_mem_ctx.").

nb:  unexpected failures 162-> 149
---
 src/soc2c.ml                                  | 13 ++++-
 src/soc2cIdent.ml                             |  4 +-
 src/soc2cUtil.ml                              | 14 +++++-
 test/lus2lic.sum                              | 50 +++++++++----------
 test/lus2lic.time                             |  2 +-
 .../{modes3x2-v2.lus => modes3x2_v2.lus}      |  2 +-
 .../{modes3x2-v3.lus => modes3x2_v3.lus}      |  2 +-
 7 files changed, 54 insertions(+), 33 deletions(-)
 rename test/should_work/{modes3x2-v2.lus => modes3x2_v2.lus} (96%)
 rename test/should_work/{modes3x2-v3.lus => modes3x2_v3.lus} (95%)

diff --git a/src/soc2c.ml b/src/soc2c.ml
index b2e47b4a..781fc1da 100644
--- a/src/soc2c.ml
+++ b/src/soc2c.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 18/06/2014 (at 17:53) by Erwan Jahier> *)
+(* Time-stamp: <modified the 19/06/2014 (at 10:44) by Erwan Jahier> *)
 
 
 (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
@@ -107,7 +107,16 @@ let (gao2c : Soc.tbl -> 'a soc_pp -> Soc.gao -> unit) =
             sprintf "\n    case %s:\n   %s" (id2s v) gaol_block
           in
           let cases = List.map to_case_str id_gao_l in
-          let str = sprintf "   switch(%s){%s\n   }\n" (id2s id) (String.concat "\n" cases) in
+          let ctx_opt = 
+            let il,ol = sp.soc.profile in
+            if List.mem_assoc id il || List.mem_assoc id ol then
+              (if is_memory_less sp.soc then Soc2cUtil.ML_IO sp.soc.key 
+               else Soc2cUtil.M_IO)
+            else Soc2cUtil.Local 
+          in
+          let str = sprintf "   switch(%s){%s\n   }\n" 
+            (Soc2cUtil.ctx_var ctx_opt id) 
+            (String.concat "\n" cases) in
           str
         )
         | Call(vel_out, Assign, vel_in) -> (
diff --git a/src/soc2cIdent.ml b/src/soc2cIdent.ml
index 4e6a680d..085ad61b 100644
--- a/src/soc2cIdent.ml
+++ b/src/soc2cIdent.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 18/06/2014 (at 17:48) by Erwan Jahier> *)
+(* Time-stamp: <modified the 19/06/2014 (at 10:20) by Erwan Jahier> *)
 
 let colcol = Str.regexp "::"
 let id2s id = (* XXX Refuser les noms de module à la con plutot *)
@@ -24,7 +24,7 @@ let rec (type_to_short_string : Data.t -> string) =
         | Data.Int -> "i"
         | Data.Real-> "r"
         | Data.Extern s -> s 
-        | Data.Enum  (s, sl) -> "i" (* s *) 
+        | Data.Enum  (s, sl) -> "e" (* s *) 
         | Data.Struct (sid,_) -> sid
         | Data.Array (ty, sz) -> Printf.sprintf "%sp%d" (type_to_short_string ty) sz 
         | Data.Alias(n,_) -> n
diff --git a/src/soc2cUtil.ml b/src/soc2cUtil.ml
index 295d4b64..35bbd87a 100644
--- a/src/soc2cUtil.ml
+++ b/src/soc2cUtil.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 18/06/2014 (at 17:48) by Erwan Jahier> *)
+(* Time-stamp: <modified the 19/06/2014 (at 10:42) by Erwan Jahier> *)
 
 
 (* exported *) 
@@ -28,6 +28,18 @@ let (step_name : Soc.key -> string -> string) =
     id2s str
 
 
+type var_kind = (* XXX poor names: fixme! *)
+  | ML_IO of Soc.key (* for idents that are part of a MemoryLess soc interface *)
+  | M_IO (* for idents that are part of a soc interface with Memories*)
+  | Local (* for soc local variables *)
+
+let (ctx_var : var_kind -> Ident.t -> string) =
+  fun opt id -> 
+    match opt with
+      | ML_IO sk -> Printf.sprintf "%s.%s" (Soc2cIdent.get_soc_name sk) (id2s id)
+      | M_IO  ->  Printf.sprintf "ctx->%s" (id2s id)
+      | Local -> Printf.sprintf "%s" (id2s id)
+
 (* exported *) 
 let (gen_step_call : Soc.t -> Soc.t -> string list -> string list -> 
      string -> string -> string -> string) =
diff --git a/test/lus2lic.sum b/test/lus2lic.sum
index b2a6b21f..a1910c22 100644
--- a/test/lus2lic.sum
+++ b/test/lus2lic.sum
@@ -1,4 +1,4 @@
-Test Run By jahier on Wed Jun 18 18:25:10 2014
+Test Run By jahier on Thu Jun 19 10:58:46 2014
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic tests ===
@@ -62,9 +62,6 @@ PASS: ./myec2c {-o /tmp/mouse2.c /tmp/mouse2.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/mouse2.lus
 PASS: ./lus2lic {-2c should_work/mouse2.lus -n mouse2}
 FAIL: Check that the generated C code compiles  : gcc mouse2_mouse2.c mouse2_mouse2_loop.c 
-PASS: ./lus2lic {-o /tmp/modes3x2-v3.lic should_work/modes3x2-v3.lus}
-PASS: ./lus2lic {-ec -o /tmp/modes3x2-v3.ec should_work/modes3x2-v3.lus}
-FAIL: Try ec2c on the result: ./myec2c {-o /tmp/modes3x2-v3.c /tmp/modes3x2-v3.ec}
 PASS: ./lus2lic {-o /tmp/dep.lic should_work/dep.lus}
 PASS: ./lus2lic {-ec -o /tmp/dep.ec should_work/dep.lus}
 PASS: ./myec2c {-o /tmp/dep.c /tmp/dep.ec}
@@ -82,7 +79,7 @@ PASS: ./lus2lic {-ec -o /tmp/testPilote.ec should_work/testPilote.lus}
 PASS: ./myec2c {-o /tmp/testPilote.c /tmp/testPilote.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/testPilote.lus
 PASS: ./lus2lic {-2c should_work/testPilote.lus -n testPilote}
-FAIL: Check that the generated C code compiles  : gcc testPilote_testPilote.c testPilote_testPilote_loop.c 
+PASS: gcc testPilote_testPilote.c testPilote_testPilote_loop.c 
 PASS: ./lus2lic {-o /tmp/redIf.lic should_work/redIf.lus}
 PASS: ./lus2lic {-ec -o /tmp/redIf.ec should_work/redIf.lus}
 PASS: ./myec2c {-o /tmp/redIf.c /tmp/redIf.ec}
@@ -189,7 +186,7 @@ PASS: ./lus2lic {-ec -o /tmp/testCapt.ec should_work/testCapt.lus}
 PASS: ./myec2c {-o /tmp/testCapt.c /tmp/testCapt.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/testCapt.lus
 PASS: ./lus2lic {-2c should_work/testCapt.lus -n testCapt}
-FAIL: Check that the generated C code compiles  : gcc testCapt_testCapt.c testCapt_testCapt_loop.c 
+PASS: gcc testCapt_testCapt.c testCapt_testCapt_loop.c 
 PASS: ./lus2lic {-o /tmp/nc7.lic should_work/nc7.lus}
 PASS: ./lus2lic {-ec -o /tmp/nc7.ec should_work/nc7.lus}
 PASS: ./myec2c {-o /tmp/nc7.c /tmp/nc7.ec}
@@ -342,11 +339,6 @@ PASS: ./myec2c {-o /tmp/double_delay.c /tmp/double_delay.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/double_delay.lus
 PASS: ./lus2lic {-2c should_work/double_delay.lus -n double_delay}
 PASS: gcc double_delay_double_delay.c double_delay_double_delay_loop.c 
-PASS: ./lus2lic {-o /tmp/modes3x2-v2.lic should_work/modes3x2-v2.lus}
-PASS: ./lus2lic {-ec -o /tmp/modes3x2-v2.ec should_work/modes3x2-v2.lus}
-PASS: ./myec2c {-o /tmp/modes3x2-v2.c /tmp/modes3x2-v2.ec}
-FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/modes3x2-v2.lus
-FAIL: Generate c code  : ./lus2lic {-2c should_work/modes3x2-v2.lus -n modes3x2-v2}
 PASS: ./lus2lic {-o /tmp/struct_with.lic should_work/struct_with.lus}
 PASS: ./lus2lic {-ec -o /tmp/struct_with.ec should_work/struct_with.lus}
 PASS: ./myec2c {-o /tmp/struct_with.c /tmp/struct_with.ec}
@@ -390,12 +382,17 @@ PASS: ./myec2c {-o /tmp/onlyroll2.c /tmp/onlyroll2.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/onlyroll2.lus
 PASS: ./lus2lic {-2c should_work/onlyroll2.lus -n onlyroll2}
 FAIL: Check that the generated C code compiles  : gcc onlyroll2_onlyroll2.c onlyroll2_onlyroll2_loop.c 
+PASS: ./lus2lic {-o /tmp/modes3x2_v2.lic should_work/modes3x2_v2.lus}
+PASS: ./lus2lic {-ec -o /tmp/modes3x2_v2.ec should_work/modes3x2_v2.lus}
+PASS: ./myec2c {-o /tmp/modes3x2_v2.c /tmp/modes3x2_v2.ec}
+FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/modes3x2_v2.lus
+FAIL: Generate c code  : ./lus2lic {-2c should_work/modes3x2_v2.lus -n modes3x2_v2}
 PASS: ./lus2lic {-o /tmp/X6.lic should_work/X6.lus}
 PASS: ./lus2lic {-ec -o /tmp/X6.ec should_work/X6.lus}
 PASS: ./myec2c {-o /tmp/X6.c /tmp/X6.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/X6.lus
 PASS: ./lus2lic {-2c should_work/X6.lus -n X6}
-FAIL: Check that the generated C code compiles  : gcc X6_X6.c X6_X6_loop.c 
+PASS: gcc X6_X6.c X6_X6_loop.c 
 PASS: ./lus2lic {-o /tmp/zzz2.lic should_work/zzz2.lus}
 PASS: ./lus2lic {-ec -o /tmp/zzz2.ec should_work/zzz2.lus}
 PASS: ./myec2c {-o /tmp/zzz2.c /tmp/zzz2.ec}
@@ -680,7 +677,7 @@ PASS: ./lus2lic {-ec -o /tmp/PCOND1.ec should_work/PCOND1.lus}
 PASS: ./myec2c {-o /tmp/PCOND1.c /tmp/PCOND1.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/PCOND1.lus
 PASS: ./lus2lic {-2c should_work/PCOND1.lus -n PCOND1}
-FAIL: Check that the generated C code compiles  : gcc PCOND1_PCOND1.c PCOND1_PCOND1_loop.c 
+PASS: gcc PCOND1_PCOND1.c PCOND1_PCOND1_loop.c 
 PASS: ./lus2lic {-o /tmp/TIME_STABLE1.lic should_work/TIME_STABLE1.lus}
 PASS: ./lus2lic {-ec -o /tmp/TIME_STABLE1.ec should_work/TIME_STABLE1.lus}
 PASS: ./myec2c {-o /tmp/TIME_STABLE1.c /tmp/TIME_STABLE1.ec}
@@ -707,7 +704,7 @@ PASS: ./lus2lic {-ec -o /tmp/lustre_test1_ok.ec should_work/lustre_test1_ok.lus}
 PASS: ./myec2c {-o /tmp/lustre_test1_ok.c /tmp/lustre_test1_ok.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/lustre_test1_ok.lus
 PASS: ./lus2lic {-2c should_work/lustre_test1_ok.lus -n lustre_test1_ok}
-FAIL: Check that the generated C code compiles  : gcc lustre_test1_ok_lustre_test1_ok.c lustre_test1_ok_lustre_test1_ok_loop.c 
+PASS: gcc lustre_test1_ok_lustre_test1_ok.c lustre_test1_ok_lustre_test1_ok_loop.c 
 PASS: ./lus2lic {-o /tmp/compteur.lic should_work/compteur.lus}
 PASS: ./lus2lic {-ec -o /tmp/compteur.ec should_work/compteur.lus}
 PASS: ./myec2c {-o /tmp/compteur.c /tmp/compteur.ec}
@@ -759,7 +756,7 @@ PASS: ./lus2lic {-ec -o /tmp/sample_time_change.ec should_work/sample_time_chang
 PASS: ./myec2c {-o /tmp/sample_time_change.c /tmp/sample_time_change.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/sample_time_change.lus
 PASS: ./lus2lic {-2c should_work/sample_time_change.lus -n sample_time_change}
-FAIL: Check that the generated C code compiles  : gcc sample_time_change_sample_time_change.c sample_time_change_sample_time_change_loop.c 
+PASS: gcc sample_time_change_sample_time_change.c sample_time_change_sample_time_change_loop.c 
 PASS: ./lus2lic {-o /tmp/test_enum.lic should_work/test_enum.lus}
 PASS: ./lus2lic {-ec -o /tmp/test_enum.ec should_work/test_enum.lus}
 PASS: ./myec2c {-o /tmp/test_enum.c /tmp/test_enum.ec}
@@ -803,7 +800,7 @@ PASS: ./lus2lic {-ec -o /tmp/multiclock.ec should_work/multiclock.lus}
 PASS: ./myec2c {-o /tmp/multiclock.c /tmp/multiclock.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/multiclock.lus
 PASS: ./lus2lic {-2c should_work/multiclock.lus -n multiclock}
-FAIL: Check that the generated C code compiles  : gcc multiclock_multiclock.c multiclock_multiclock_loop.c 
+PASS: gcc multiclock_multiclock.c multiclock_multiclock_loop.c 
 PASS: ./lus2lic {-o /tmp/nc2.lic should_work/nc2.lus}
 PASS: ./lus2lic {-ec -o /tmp/nc2.ec should_work/nc2.lus}
 PASS: ./myec2c {-o /tmp/nc2.c /tmp/nc2.ec}
@@ -1124,6 +1121,9 @@ PASS: ./myec2c {-o /tmp/simpleRed.c /tmp/simpleRed.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/simpleRed.lus
 PASS: ./lus2lic {-2c should_work/simpleRed.lus -n simpleRed}
 FAIL: Check that the generated C code compiles  : gcc simpleRed_simpleRed.c simpleRed_simpleRed_loop.c 
+PASS: ./lus2lic {-o /tmp/modes3x2_v3.lic should_work/modes3x2_v3.lus}
+PASS: ./lus2lic {-ec -o /tmp/modes3x2_v3.ec should_work/modes3x2_v3.lus}
+FAIL: Try ec2c on the result: ./myec2c {-o /tmp/modes3x2_v3.c /tmp/modes3x2_v3.ec}
 PASS: ./lus2lic {-o /tmp/pre_x.lic should_work/pre_x.lus}
 PASS: ./lus2lic {-ec -o /tmp/pre_x.ec should_work/pre_x.lus}
 PASS: ./myec2c {-o /tmp/pre_x.c /tmp/pre_x.ec}
@@ -1147,7 +1147,7 @@ PASS: ./lus2lic {-ec -o /tmp/X2.ec should_work/X2.lus}
 PASS: ./myec2c {-o /tmp/X2.c /tmp/X2.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/X2.lus
 PASS: ./lus2lic {-2c should_work/X2.lus -n X2}
-FAIL: Check that the generated C code compiles  : gcc X2_X2.c X2_X2_loop.c 
+PASS: gcc X2_X2.c X2_X2_loop.c 
 PASS: ./lus2lic {-o /tmp/alias.lic should_work/alias.lus}
 PASS: ./lus2lic {-ec -o /tmp/alias.ec should_work/alias.lus}
 PASS: ./myec2c {-o /tmp/alias.c /tmp/alias.ec}
@@ -1193,7 +1193,7 @@ PASS: ./lus2lic {-ec -o /tmp/ck3.ec should_work/ck3.lus}
 PASS: ./myec2c {-o /tmp/ck3.c /tmp/ck3.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/ck3.lus
 PASS: ./lus2lic {-2c should_work/ck3.lus -n ck3}
-FAIL: Check that the generated C code compiles  : gcc ck3_ck3.c ck3_ck3_loop.c 
+PASS: gcc ck3_ck3.c ck3_ck3_loop.c 
 PASS: ./lus2lic {-o /tmp/zzz.lic should_work/zzz.lus}
 PASS: ./lus2lic {-ec -o /tmp/zzz.ec should_work/zzz.lus}
 PASS: ./myec2c {-o /tmp/zzz.c /tmp/zzz.ec}
@@ -1306,7 +1306,7 @@ PASS: ./lus2lic {-ec -o /tmp/PCOND.ec should_work/PCOND.lus}
 PASS: ./myec2c {-o /tmp/PCOND.c /tmp/PCOND.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/PCOND.lus
 PASS: ./lus2lic {-2c should_work/PCOND.lus -n PCOND}
-FAIL: Check that the generated C code compiles  : gcc PCOND_PCOND.c PCOND_PCOND_loop.c 
+PASS: gcc PCOND_PCOND.c PCOND_PCOND_loop.c 
 PASS: ./lus2lic {-o /tmp/EDGE.lic should_work/EDGE.lus}
 PASS: ./lus2lic {-ec -o /tmp/EDGE.ec should_work/EDGE.lus}
 PASS: ./myec2c {-o /tmp/EDGE.c /tmp/EDGE.ec}
@@ -1333,13 +1333,13 @@ PASS: ./lus2lic {-ec -o /tmp/ck2.ec should_work/ck2.lus}
 PASS: ./myec2c {-o /tmp/ck2.c /tmp/ck2.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/ck2.lus
 PASS: ./lus2lic {-2c should_work/ck2.lus -n ck2}
-FAIL: Check that the generated C code compiles  : gcc ck2_ck2.c ck2_ck2_loop.c 
+PASS: gcc ck2_ck2.c ck2_ck2_loop.c 
 PASS: ./lus2lic {-o /tmp/X.lic should_work/X.lus}
 PASS: ./lus2lic {-ec -o /tmp/X.ec should_work/X.lus}
 PASS: ./myec2c {-o /tmp/X.c /tmp/X.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/X.lus
 PASS: ./lus2lic {-2c should_work/X.lus -n X}
-FAIL: Check that the generated C code compiles  : gcc X_X.c X_X_loop.c 
+PASS: gcc X_X.c X_X_loop.c 
 PASS: ./lus2lic {-o /tmp/Condact.lic should_work/Condact.lus}
 PASS: ./lus2lic {-ec -o /tmp/Condact.ec should_work/Condact.lus}
 PASS: ./myec2c {-o /tmp/Condact.c /tmp/Condact.ec}
@@ -1362,7 +1362,7 @@ PASS: ./lus2lic {-ec -o /tmp/clock1_2ms.ec should_work/clock1_2ms.lus}
 PASS: ./myec2c {-o /tmp/clock1_2ms.c /tmp/clock1_2ms.ec}
 FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/clock1_2ms.lus
 PASS: ./lus2lic {-2c should_work/clock1_2ms.lus -n clock1_2ms}
-FAIL: Check that the generated C code compiles  : gcc clock1_2ms_clock1_2ms.c clock1_2ms_clock1_2ms_loop.c 
+PASS: gcc clock1_2ms_clock1_2ms.c clock1_2ms_clock1_2ms_loop.c 
 PASS: ./lus2lic {-o /tmp/decl.lic should_work/decl.lus}
 PASS: ./lus2lic {-ec -o /tmp/decl.ec should_work/decl.lus}
 PASS: ./myec2c {-o /tmp/decl.c /tmp/decl.ec}
@@ -1479,9 +1479,9 @@ XPASS: Test bad programs (semantics): lus2lic {-o /tmp/bug.lic should_fail/seman
 
 		=== lus2lic Summary ===
 
-# of expected passes		1247
-# of unexpected failures	162
+# of expected passes		1260
+# of unexpected failures	149
 # of unexpected successes	21
 # of expected failures		37
-testcase ./lus2lic.tests/non-reg.exp completed in 125 seconds
+testcase ./lus2lic.tests/non-reg.exp completed in 143 seconds
 testcase ./lus2lic.tests/progression.exp completed in 0 seconds
diff --git a/test/lus2lic.time b/test/lus2lic.time
index 5bc31045..7ffb5592 100644
--- a/test/lus2lic.time
+++ b/test/lus2lic.time
@@ -1,2 +1,2 @@
-testcase ./lus2lic.tests/non-reg.exp completed in 125 seconds
+testcase ./lus2lic.tests/non-reg.exp completed in 143 seconds
 testcase ./lus2lic.tests/progression.exp completed in 0 seconds
diff --git a/test/should_work/modes3x2-v2.lus b/test/should_work/modes3x2_v2.lus
similarity index 96%
rename from test/should_work/modes3x2-v2.lus
rename to test/should_work/modes3x2_v2.lus
index eb8bca0c..3d45b710 100644
--- a/test/should_work/modes3x2-v2.lus
+++ b/test/should_work/modes3x2_v2.lus
@@ -63,7 +63,7 @@ let
 		 else (0 -> pre z);
 tel
 
-node modes3x2(x:data; on_off, toggle: bool) returns (res: data);
+node modes3x2_V2(x:data; on_off, toggle: bool) returns (res: data);
 var
 	y, z : data;	
 	sby : bool;
diff --git a/test/should_work/modes3x2-v3.lus b/test/should_work/modes3x2_v3.lus
similarity index 95%
rename from test/should_work/modes3x2-v3.lus
rename to test/should_work/modes3x2_v3.lus
index bfda61ee..b6040751 100644
--- a/test/should_work/modes3x2-v3.lus
+++ b/test/should_work/modes3x2_v3.lus
@@ -41,7 +41,7 @@ let
 		 else (0 -> pre z);
 tel
 
-node modes3x2(x:data; on_off, toggle: bool) returns (res: data);
+node modes3x2_v3(x:data; on_off, toggle: bool) returns (res: data);
 var
 	y, z : data;	
 	sby : bool;
-- 
GitLab