From f3ac7e54d710ca031bdee874ccf7f831005f12f3 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Thu, 10 Mar 2016 13:43:43 +0100
Subject: [PATCH] Fix the version number (that was shifted by 1) used when
 generating package name.

---
 Makefile.dev      |  2 +-
 Makefile.version  |  2 ++
 _oasis            |  2 +-
 src/lv6version.ml |  4 ++--
 src/main.ml       | 11 +++++++---
 src/soc2c.ml      | 51 ++++++++++++++++++++++++-----------------------
 test/lus2lic.sum  | 28 +++++++++++++-------------
 7 files changed, 54 insertions(+), 46 deletions(-)

diff --git a/Makefile.dev b/Makefile.dev
index 4c248a8d..bac7e8a1 100644
--- a/Makefile.dev
+++ b/Makefile.dev
@@ -65,7 +65,7 @@ pull:
 # opam-ing
 
 NAME=lustre-v6
-PACKNAME=$(NAME).$(VERSION)
+PACKNAME=$(NAME).$(PRE_VERSION)
 WWW=/import/www/DIST-TOOLS/SYNCHRONE
 HTTP=http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE
 
diff --git a/Makefile.version b/Makefile.version
index 9ed47ef5..8110a3b1 100644
--- a/Makefile.version
+++ b/Makefile.version
@@ -7,6 +7,8 @@ SHA:=$(shell git log -1 --pretty=format:"%h")
 COMMIT_NB:=$(shell git log --pretty=oneline  | wc -l)
 
 VERSION:=1.$(COMMIT_NB)
+PRE_COMMIT_NB:=$(shell echo $(COMMIT_NB) - 1 | bc)
+PRE_VERSION:=1.$(PRE_COMMIT_NB)
 
 gen_version:
 	rm -f src/lv6version.ml
diff --git a/_oasis b/_oasis
index 3e5858b0..a56ee93d 100644
--- a/_oasis
+++ b/_oasis
@@ -1,6 +1,6 @@
 OASISFormat: 0.4
 Name:        lustre-v6
-Version:     1.645
+Version:     1.646
 Synopsis:    The Lustre V6 Verimag compiler
 Description: This package contains:
              - lus2lic: the (current) name of the compiler (and interpreter via -exec).
diff --git a/src/lv6version.ml b/src/lv6version.ml
index 1f9b9616..6ee8dad1 100644
--- a/src/lv6version.ml
+++ b/src/lv6version.ml
@@ -1,7 +1,7 @@
 (** Automatically generated from Makefile *) 
 let tool = "lus2lic"
 let branch = "master"
-let commit = "645"
-let sha_1 = "099bb28416511cb8ed4d182290d387dc7dc8b538"
+let commit = "646"
+let sha_1 = "c7bc0ba6abc8bb6c2d083d44e7e025e846accb13"
 let str = (branch ^ "." ^ commit ^ " (" ^ sha_1 ^ ")")
 let maintainer = "jahier@imag.fr"
diff --git a/src/main.ml b/src/main.ml
index de9a2ff8..66a455d9 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 03/02/2016 (at 15:09) by Erwan Jahier> *)
+(* Time-stamp: <modified the 01/03/2016 (at 15:21) by Erwan Jahier> *)
 
 open Lv6Verbose
 open AstV6
@@ -73,6 +73,11 @@ let (gen_rif_interface : LicPrg.t -> Lv6Id.idref option -> Lv6MainArgs.t -> unit
   output_string opt.oc ("#outputs "^ (String.concat " " outvars_str) ^"\n");
   flush opt.oc
 
+(* make sur f is fresh *)
+let fresh f =
+  if not (Sys.file_exists f) then f else 
+    Filename.temp_file ~temp_dir:Filename.current_dir_name "_" f
+    
 
 (* Generates a lutin env and a lustre oracle for the node *)
 let (gen_autotest_files : LicPrg.t -> Lv6Id.idref option -> Lv6MainArgs.t -> unit) =
@@ -128,7 +133,7 @@ let (gen_autotest_files : LicPrg.t -> Lv6Id.idref option -> Lv6MainArgs.t -> uni
     let invars_str  = List.map (fun (n,t) -> n^":"^(my_type_to_string true t)) invars in
     let outvars_str = List.map (fun (n,t) -> n^":"^(my_type_to_string false t)) outvars in
     let name = main_node.Lv6Id.id_id in
-    let lutin_file_name = ("_"^name^"_env.lut") in
+    let lutin_file_name = fresh ("_"^name^"_env.lut") in
     let oc = open_out lutin_file_name in
     LicDump.dump_entete oc; 
     output_string oc ("node " ^ (name) ^ "_env("^ (String.concat ";" outvars_str) ^ 
@@ -137,7 +142,7 @@ let (gen_autotest_files : LicPrg.t -> Lv6Id.idref option -> Lv6MainArgs.t -> uni
     flush oc; 
     close_out oc;
     output_string stdout (lutin_file_name ^" generated.\n"); 
-    let oracle_file_name = ("_"^name^"_oracle.lus") in
+    let oracle_file_name = fresh ("_"^name^"_oracle.lus") in
     let oc = open_out oracle_file_name in
     let invars,outvars=soc.Soc.profile in
     let locals = List.map (fun (n,t) -> n^"_bis",t) outvars in
diff --git a/src/soc2c.ml b/src/soc2c.ml
index 0ead09b6..c5daf12e 100644
--- a/src/soc2c.ml
+++ b/src/soc2c.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 03/12/2015 (at 10:52) by Erwan JAHIER> *)
+(* Time-stamp: <modified the 02/03/2016 (at 16:45) by Erwan Jahier> *)
 
 
 (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
@@ -183,6 +183,7 @@ let (soc2c: int -> out_channel -> out_channel -> Soc.tbl -> Soc.t -> unit) =
           hfmt "%s_type* %s_new_ctx();\n" ctx_name ctx_name;
           cfmt "%s_type* %s_new_ctx(){" ctx_name ctx_name;
           cfmt "
+
    %s_type* ctx = (%s_type*)calloc(1, sizeof(%s_type));
    // ctx->client_data = cdata;
    %s_reset(ctx);
@@ -391,7 +392,7 @@ int main(){" ^ (
           let inputs_decl = Printf.sprintf "\n  %s" (String.concat "" inputs_t) in
           let outputs_decl = Printf.sprintf "%s" (String.concat "" outputs_t) in
           let ctx_decl = if SocUtils.is_memory_less soc then "" else 
-              ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);\n\n"
+                           ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);\n\n"
           in
           inputs_decl ^ outputs_decl ^ ctx_decl
         | Lv6MainArgs.Heap -> ("
@@ -558,7 +559,7 @@ int main(){
           let inputs_decl = Printf.sprintf "\n  %s" (String.concat "" inputs_t) in
           let outputs_decl = Printf.sprintf "%s" (String.concat "" outputs_t) in
           let ctx_decl = if SocUtils.is_memory_less soc then "" else 
-              ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);\n"
+               ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);\n" 
           in
           inputs_decl ^ outputs_decl ^ ctx_decl
         | Lv6MainArgs.Heap -> ("
@@ -654,14 +655,14 @@ let (gen_loop_file4ogensim : Soc.t -> string -> out_channel -> Soc.tbl -> unit)
   
   putc  ("#include \""^base ^".h\"
                               
-#define tickBegin  0xe0000000
-");
+                              #define tickBegin  0xe0000000
+                              ");
   List.iteri define_define (inputs_io@ outputs_io);
   
 
   putc  (
       "/* Main procedure *************************/
-int main(){" ^ (
+       int main(){" ^ (
         match io_transmit_mode () with
         | Lv6MainArgs.Stack ->
            let to_c_decl (n,t) = ((Soc2cUtil.data_type_to_c t n)^ ";\n  ") in
@@ -674,13 +675,13 @@ int main(){" ^ (
            in
            inputs_decl ^ outputs_decl ^ ctx_decl
         | Lv6MainArgs.Heap -> ("
- /* Context allocation */
- " ^ (if SocUtils.is_memory_less soc then ctx^"_type* ctx = &"^ctx^";\n"
+                                /* Context allocation */
+                                " ^ (if SocUtils.is_memory_less soc then ctx^"_type* ctx = &"^ctx^";\n"
                                      else ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);")
                               )
         | Lv6MainArgs.HeapStack -> ("
-/* Context allocation */
-      " ^ (if SocUtils.is_memory_less soc then ctx^""
+                                     /* Context allocation */
+                                     " ^ (if SocUtils.is_memory_less soc then ctx^""
                                           else ctx^"_type* ctx ;\n"^ ctx^"_reset(ctx);")
                                    )
     ));
@@ -691,13 +692,13 @@ int main(){" ^ (
   let outputs_decl = Printf.sprintf "#outputs %s" (String.concat " " outputs_t) in
   
   putc  ("
-  /* Main loop */
-  while(1){
-    // notify the simulator that it is time to load the inputs from Lurette
-    // to the specified address
-    *((unsigned int*)tickBegin) = 0;
-    // load inputs from the memory locations
-");
+          /* Main loop */
+          while(1){
+          // notify the simulator that it is time to load the inputs from Lurette
+          // to the specified address
+          *((unsigned int*)tickBegin) = 0;
+          // load inputs from the memory locations
+          ");
   List.iter2 
     (fun (id,t)  (id_flat,_) -> 
      let t = Soc2cUtil.data_type_to_c t "" in
@@ -716,9 +717,9 @@ int main(){" ^ (
   let io = if SocUtils.is_memory_less soc then io else if io = "" then "ctx" else io^",ctx" in
   putc ("    " ^ step^"("^io^");
 
-    // now write the output to the memory which will be output to Lurette
-");
-    List.iter2
+                              // now write the output to the memory which will be output to Lurette
+                              ");
+  List.iter2
     (fun (id,t) (id_flat,_) -> 
      let t = Soc2cUtil.data_type_to_c t "" in
      let str = Printf.sprintf "	 *((%s*)_%s) = %s;\n" t id id_flat in
@@ -727,8 +728,8 @@ int main(){" ^ (
     outputs_io outputs_exp;
 
   putc "}\n  return 1;       
-}        
-"
+        }        
+        "
 
 (****************************************************************************)
 (* The entry point for lus2lic --to-c *)
@@ -771,8 +772,8 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
     if args.Lv6MainArgs.gen_wcet then gen_main_wcet_file main_soc base stbl;
     
     output_string och "
-#include <stdlib.h>
-#include <string.h>
+                       #include <stdlib.h>
+                       #include <string.h>
 
 #ifndef _SOC2C_PREDEF_TYPES
 #define _SOC2C_PREDEF_TYPES
@@ -821,7 +822,7 @@ typedef float _float;
     Printf.printf "%s has been generated.\n" cfile;
     flush stdout;
     let node = args.main_node in
-    let execfile = if args.Lv6MainArgs.outfile = "" then (node^"4otawa.out")
+    let execfile = if args.Lv6MainArgs.outfile = "" then (node^".out")
       else args.Lv6MainArgs.outfile 
     in
     let cflags = try Sys.getenv "CFLAGS" with Not_found -> "" in
diff --git a/test/lus2lic.sum b/test/lus2lic.sum
index 328b3b25..41bf56d2 100644
--- a/test/lus2lic.sum
+++ b/test/lus2lic.sum
@@ -1,5 +1,5 @@
 ==> lus2lic0.sum <==
-Test Run By jahier on Wed Feb 10 14:51:38 
+Test Run By jahier on Thu Mar 10 13:40:07 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic0 tests ===
@@ -64,7 +64,7 @@ XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/lecte
 XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/s.lus
 
 ==> lus2lic1.sum <==
-Test Run By jahier on Wed Feb 10 14:51:38 
+Test Run By jahier on Thu Mar 10 13:40:08 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic1 tests ===
@@ -396,7 +396,7 @@ PASS: gcc -o multipar.exec multipar_multipar.c multipar_multipar_loop.c
 PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c multipar.lus  {}
 
 ==> lus2lic2.sum <==
-Test Run By jahier on Wed Feb 10 14:51:55 
+Test Run By jahier on Thu Mar 10 13:40:24 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic2 tests ===
@@ -741,7 +741,7 @@ PASS: gcc -o zzz2.exec zzz2_zzz2.c zzz2_zzz2_loop.c
 PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c zzz2.lus  {}
 
 ==> lus2lic3.sum <==
-Test Run By jahier on Wed Feb 10 14:52:33 
+Test Run By jahier on Thu Mar 10 13:41:01 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic3 tests ===
@@ -1243,7 +1243,7 @@ PASS: ./myec2c {-o multipar.c multipar.ec}
 PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node multipar.lus {}
 
 ==> lus2lic4.sum <==
-Test Run By jahier on Wed Feb 10 14:52:45 
+Test Run By jahier on Thu Mar 10 13:41:12 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic4 tests ===
@@ -1764,14 +1764,14 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {}
 # of unexpected failures	4
 ===============================
 # Total number of failures: 23
-lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 0 seconds
-lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 17 seconds
-lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 38 seconds
-lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 12 seconds
-lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 41 seconds
+lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 1 seconds
+lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 16 seconds
+lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 37 seconds
+lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 11 seconds
+lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 39 seconds
 * Ref time: 
-0.06user 0.01system 1:48.12elapsed 0%CPU (0avgtext+0avgdata 5160maxresident)k
-32inputs+0outputs (0major+5567minor)pagefaults 0swaps
+0.04user 0.03system 1:44.01elapsed 0%CPU (0avgtext+0avgdata 5184maxresident)k
+32inputs+0outputs (0major+5549minor)pagefaults 0swaps
 * Quick time (-j 4):
-0.04user 0.01system 0:47.41elapsed 0%CPU (0avgtext+0avgdata 5188maxresident)k
-32inputs+0outputs (0major+5578minor)pagefaults 0swaps
+0.04user 0.02system 0:46.66elapsed 0%CPU (0avgtext+0avgdata 5232maxresident)k
+32inputs+0outputs (0major+5564minor)pagefaults 0swaps
-- 
GitLab