From b207aa9d94a6bea80d498dc748401eea1130284c Mon Sep 17 00:00:00 2001 From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr> Date: Fri, 5 May 2017 15:00:47 +0200 Subject: [PATCH] soc2c: the c code was wrong in presence of user type defined using extern types. Also, the simulation via the _loop.c file was failing in extern types were present as O/I of the main (simulated) node. --- _oasis | 2 +- src/lv6version.ml | 4 ++-- src/soc2c.ml | 27 +++++++++++++++++---------- src/soc2cExtern.ml | 19 ++++++++++++++++++- src/soc2cExtern.mli | 4 +++- src/soc2cGenAssign.ml | 23 ++++++++++++++++++++--- test/lus2lic.sum | 26 +++++++++++++------------- 7 files changed, 74 insertions(+), 31 deletions(-) diff --git a/_oasis b/_oasis index 00385d66..a0e3e5d9 100644 --- a/_oasis +++ b/_oasis @@ -1,6 +1,6 @@ OASISFormat: 0.4 Name: lustre-v6 -Version: 1.688 +Version: 1.689 Synopsis: The Lustre V6 Verimag compiler Description: This package contains: (1) lus2lic: the (current) name of the compiler (and interpreter via -exec). diff --git a/src/lv6version.ml b/src/lv6version.ml index a7588c67..b208bf3d 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 = "688" -let sha_1 = "60e6de1051197066a96927dee9e5c0c5222aa6ee" +let commit = "689" +let sha_1 = "d4fdee068416fe85a1809b1b47b93284d06bba32" let str = (branch ^ "." ^ commit ^ " (" ^ sha_1 ^ ")") let maintainer = "jahier@imag.fr" diff --git a/src/soc2c.ml b/src/soc2c.ml index 41c1b723..4a72a994 100644 --- a/src/soc2c.ml +++ b/src/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 31/01/2017 (at 16:05) by Erwan Jahier> *) +(* Time-stamp: <modified the 05/05/2017 (at 14:16) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -290,7 +290,7 @@ let (type_to_format_string : Data.t -> string) = | Bool -> "%d" | Int -> "%d" | Real-> "%f" - | Extern s -> "%s" + | Extern s -> "%d" | Enum (s, sl) -> "%d" | Struct (sid,_) -> "%s" | Array (ty, sz) -> "%s" @@ -582,8 +582,8 @@ int main(){" ^ (gen_main_loop_body inputs outputs soc ctx)); close_out oc -let (gen_loop_file : Soc.t -> string -> out_channel -> Soc.tbl -> unit) = - fun soc base oc stbl -> +let (gen_loop_file : LicPrg.t -> Soc.t -> string -> out_channel -> Soc.tbl -> unit) = + fun licprg soc base oc stbl -> let putc s = output_string oc s in let ctx = get_ctx_name soc.key in let step = Soc2cDep.step_name soc.key "step" in @@ -687,7 +687,7 @@ void _put_real(char* n, _real _V){ if(ISATTY) printf(\"%s = \", n); printf(\"%f \", _V); if(ISATTY) printf(\"\\n\"); -} +}"^(Soc2cExtern.gen_getters licprg)^" /* Output procedures **********************/ #ifdef CKCHECK void %s_BOT_n(void* cdata){ @@ -738,13 +738,19 @@ int main(){ if io_transmit_mode () = Lv6MainArgs.Stack then let i = fst (List.split inputs) in - let o = List.map (fun (n,t) -> match t with Data.Array(_,_) -> n | _ ->"&"^n) outputs in + let o = List.map + (fun (n,t) -> match t with Data.Array(_,_) -> n | _ ->"&"^n) + outputs + in let io = String.concat "," (i@o) in - let io = if SocUtils.is_memory_less soc then io else if io = "" then "ctx" else io^",ctx" in + let io = if SocUtils.is_memory_less soc then io + else if io = "" then "ctx" else io^",ctx" + in putc (" " ^ step^"("^io^"); // printf(\"" ^ (String.concat " " inputs_fmt)^ " #outs " ^ (String.concat " " outputs_fmt)^ "\\n\"," ^ - (String.concat "," (List.map (fun (id,_) -> ""^id ) (inputs_exp@outputs_exp)))^ + (String.concat "," (List.map (fun (id,_) -> ""^id ) + (inputs_exp@outputs_exp)))^ "); printf(\"" ^ (String.concat " " outputs_fmt)^ "\\n\"," ^ @@ -755,7 +761,8 @@ int main(){ putc (" " ^ step^"(ctx); // printf(\"" ^ (String.concat " " inputs_fmt)^ " #outs " ^ (String.concat " " outputs_fmt)^ "\\n\"," ^ - (String.concat "," (List.map (fun (id,_) -> "ctx->"^id ) (inputs_exp@outputs_exp)))^ + (String.concat "," (List.map (fun (id,_) -> "ctx->"^id ) + (inputs_exp@outputs_exp)))^ "); printf(\"" ^ (String.concat " " outputs_fmt)^ "\\n\"," ^ @@ -908,7 +915,7 @@ typedef float _float; gen_main_wcet_file main_soc base stbl ) else - gen_loop_file main_soc base ocl stbl; + gen_loop_file licprg main_soc base ocl stbl; output_string och " #include <stdlib.h> diff --git a/src/soc2cExtern.ml b/src/soc2cExtern.ml index 73b1adb5..b9f12dbd 100644 --- a/src/soc2cExtern.ml +++ b/src/soc2cExtern.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 06/09/2016 (at 10:39) by Erwan Jahier> *) +(* Time-stamp: <modified the 05/05/2017 (at 14:14) by Erwan Jahier> *) open Soc2cIdent @@ -94,6 +94,23 @@ let (const_declaration : LicPrg.t -> string) = let str = LicPrg.fold_consts const_to_string prg "" in if str = "" then "" else (preambule^str^"\n") +let (gen_getters : LicPrg.t -> string) = + fun prg -> + let type_to_string k t acc = + if is_extern_type t then + Printf.sprintf "%s +_integer _get_%s(char* n) { + _integer r; + r = _get_int(n); + return r; +}" acc (long2s k) + else acc + in + let preambule = "\n/* XXX FIXME: The getters may need to be fixed too */" in + let str = LicPrg.fold_types type_to_string prg "" in + if str = "" then "" else (preambule^""^str^"\n") + + open Soc let (gen_files : Soc.t -> Soc.tbl -> LicPrg.t -> string -> string -> string -> diff --git a/src/soc2cExtern.mli b/src/soc2cExtern.mli index b12c56e5..560fe3e0 100644 --- a/src/soc2cExtern.mli +++ b/src/soc2cExtern.mli @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 03/10/2014 (at 17:42) by Erwan Jahier> *) +(* Time-stamp: <modified the 05/05/2017 (at 11:31) by Erwan Jahier> *) (* [gen_files main_soc licprg cfile hfile] returns a pair of bool that @@ -22,3 +22,5 @@ val gen_files : Soc.t -> Soc.tbl -> LicPrg.t -> string -> string -> string -> bo (* val cpy_declaration : LicPrg.t -> string *) val const_declaration : LicPrg.t -> string +(* ext type getters for the _loop.c file *) +val gen_getters : LicPrg.t -> string diff --git a/src/soc2cGenAssign.ml b/src/soc2cGenAssign.ml index 5b12c602..eb881cfb 100644 --- a/src/soc2cGenAssign.ml +++ b/src/soc2cGenAssign.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 10/01/2017 (at 17:04) by Erwan Jahier> *) +(* Time-stamp: <modified the 05/05/2017 (at 15:00) by Erwan Jahier> *) open Data open Lic @@ -52,12 +52,29 @@ let (f: Data.t -> string) = fun t -> let t_str = Soc2cIdent.type_to_short_string t in let t_def = + match t with + | Bool | Int | Real | Enum _-> + Printf.sprintf " +#ifndef _assign_%s +#define _assign_%s(dest, source, size) dest = source +#endif +" t_str t_str + | Extern _ -> + Printf.sprintf " +#ifndef _assign_%s +#define _assign_%s(dest, source, size) dest = source // XXX fixme if not a basic type +#endif +" t_str t_str + + | Struct _ + | Array _ + | Alpha _ + | Alias _ -> Printf.sprintf " #ifndef _assign_%s #define _assign_%s(dest, source, size) memcpy(dest, source, size) #endif -" - t_str t_str +" t_str t_str in t_def diff --git a/test/lus2lic.sum b/test/lus2lic.sum index 11d6304d..a3031811 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,5 +1,5 @@ ==> lus2lic0.sum <== -Test Run By jahier on Wed May 3 11:10:48 +Test Run By jahier on Fri May 5 14:48:31 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 May 3 11:10:49 +Test Run By jahier on Fri May 5 14:48:32 Native configuration is x86_64-unknown-linux-gnu === lus2lic1 tests === @@ -398,7 +398,7 @@ PASS: sh multipar.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c multipar.lus {} ==> lus2lic2.sum <== -Test Run By jahier on Wed May 3 11:11:42 +Test Run By jahier on Fri May 5 14:49:40 Native configuration is x86_64-unknown-linux-gnu === lus2lic2 tests === @@ -738,7 +738,7 @@ PASS: sh zzz2.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c zzz2.lus {} ==> lus2lic3.sum <== -Test Run By jahier on Wed May 3 11:12:38 +Test Run By jahier on Fri May 5 14:50:52 Native configuration is x86_64-unknown-linux-gnu === lus2lic3 tests === @@ -1243,7 +1243,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node multipar.lus {} ==> lus2lic4.sum <== -Test Run By jahier on Wed May 3 11:14:21 +Test Run By jahier on Fri May 5 14:52:50 Native configuration is x86_64-unknown-linux-gnu === lus2lic4 tests === @@ -1761,13 +1761,13 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {} =============================== # Total number of failures: 23 lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 1 seconds -lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 53 seconds -lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 56 seconds -lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 103 seconds -lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 51 seconds +lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 67 seconds +lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 72 seconds +lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 117 seconds +lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 63 seconds * Ref time: -0.04user 0.03system 4:24.42elapsed 0%CPU (0avgtext+0avgdata 5608maxresident)k -64inputs+0outputs (0major+6167minor)pagefaults 0swaps +0.06user 0.01system 5:22.26elapsed 0%CPU (0avgtext+0avgdata 5584maxresident)k +96inputs+0outputs (0major+6151minor)pagefaults 0swaps * Quick time (-j 4): -0.04user 0.03system 2:23.84elapsed 0%CPU (0avgtext+0avgdata 5680maxresident)k -64inputs+0outputs (0major+6173minor)pagefaults 0swaps +0.07user 0.00system 2:03.28elapsed 0%CPU (0avgtext+0avgdata 5572maxresident)k +160inputs+0outputs (0major+6170minor)pagefaults 0swaps -- GitLab