From fb10a7040944aa3799dcf5767893dbdab2088d74 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <jahier@imag.fr> Date: Thu, 2 Oct 2014 17:57:12 +0200 Subject: [PATCH] soc2c: use macros instead of memcpy for copying arrays. Also provide a default version of those macros using memcpy. --- src/lic2soc.ml | 4 +-- src/lic2soc.mli | 6 ++++- src/soc2c.ml | 7 +++++- src/soc2cGenAssign.ml | 53 +++++++++++++++++++++++++++++++++++++++ src/soc2cUtil.ml | 5 ++-- test/lus2lic.sum | 28 ++++++++++----------- test/lus2lic.time | 18 +++++++------- todo.org | 32 ------------------------ todo.org_archive | 58 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 150 insertions(+), 61 deletions(-) create mode 100644 src/soc2cGenAssign.ml diff --git a/src/lic2soc.ml b/src/lic2soc.ml index a647013a..69c6f46f 100644 --- a/src/lic2soc.ml +++ b/src/lic2soc.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 01/09/2014 (at 14:32) by Erwan Jahier> *) +(** Time-stamp: <modified the 02/10/2014 (at 17:43) by Erwan Jahier> *) (* XXX ce module est mal écrit. A reprendre. (R1) *) @@ -60,7 +60,7 @@ let rec lic_to_data_type: (Lic.type_ -> Data.t) = nb : i raise an exception here because I've got no Lxm.t to use to display a nice error message. If ever Polymorphic is raised at the toplevel, its means that my "try/with Polymorphic" is not - done at the right place + done at the right place (as usual) *) raise Polymorphic diff --git a/src/lic2soc.mli b/src/lic2soc.mli index c08eed8a..37244fad 100644 --- a/src/lic2soc.mli +++ b/src/lic2soc.mli @@ -1,7 +1,11 @@ -(** Time-stamp: <modified the 08/04/2013 (at 14:12) by Erwan Jahier> *) +(** Time-stamp: <modified the 02/10/2014 (at 17:42) by Erwan Jahier> *) val f: LicPrg.t -> Lic.node_key -> Soc.key * Soc.tbl val user_var_prefix:string + +exception Polymorphic + +(* raises the Polymorphic exception if Lic.type_ is polymorphic *) val lic_to_data_type: Lic.type_ -> Data.t diff --git a/src/soc2c.ml b/src/soc2c.ml index d6c6ff89..b951fbfb 100644 --- a/src/soc2c.ml +++ b/src/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 24/09/2014 (at 11:44) by Erwan Jahier> *) +(* Time-stamp: <modified the 02/10/2014 (at 17:11) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -606,6 +606,11 @@ typedef float _float; puth "/////////////////////////////////////////////////\n"; putc "//// Defining step functions\n"; List.iter (soc2c 2 och occ stbl) socs; + + puth "/////////////////////////////////////////////////\n"; + puth "// Defining complex types assignements \n"; + List.iter (fun t -> puth (Soc2cGenAssign.f t)) (Soc2cGenAssign.gen_used_types licprg); + puth "#endif\n"; flush occ; close_out occ; flush och; close_out och; diff --git a/src/soc2cGenAssign.ml b/src/soc2cGenAssign.ml new file mode 100644 index 00000000..e8c7dffe --- /dev/null +++ b/src/soc2cGenAssign.ml @@ -0,0 +1,53 @@ +(* Time-stamp: <modified the 02/10/2014 (at 17:41) by Erwan Jahier> *) + +module OrderedData = struct + type t = Data.t + let compare = compare +end + +module DataSet = Set.Make(OrderedData) + +let (var_info_to_data : Lic.var_info -> Data.t) = + fun vi -> + Lic2soc.lic_to_data_type vi.var_type_eff + +let (update_set : DataSet.t -> Lic.var_info -> DataSet.t) = + fun acc vi -> + try + let t = var_info_to_data vi in + (match t with + | Data.Array _ -> DataSet.add t acc + | _ -> acc) + with Lic2soc.Polymorphic -> + (* migth be raised by var_info_to_data *) + acc + +(* exported *) +let (gen_used_types : LicPrg.t -> Data.t list) = + fun prg -> + let tset = + LicPrg.fold_nodes + (fun _nk ne acc -> + let acc = List.fold_left update_set acc ne.inlist_eff in + let acc = List.fold_left update_set acc ne.outlist_eff in + acc + ) + prg + DataSet.empty + in + DataSet.elements tset + +(* exported *) +let (f: Data.t -> string) = + fun t -> + let t_str = Soc2cIdent.type_to_short_string t in + let t_def = Printf.sprintf " +#ifndef _assign_%s +#define _assign_%s(dest, source) memcpy(dest, source, sizeof(dest)) +#endif +" + t_str t_str + in + t_def + + diff --git a/src/soc2cUtil.ml b/src/soc2cUtil.ml index 5ff57413..c49354bd 100644 --- a/src/soc2cUtil.ml +++ b/src/soc2cUtil.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 01/10/2014 (at 11:05) by Erwan Jahier> *) +(* Time-stamp: <modified the 02/10/2014 (at 17:46) by Erwan Jahier> *) open Soc2cIdent open Soc @@ -36,7 +36,8 @@ let rec (gen_assign : Data.t -> string -> string -> string -> string) = Printf.sprintf " %s = %s;\n" vi vo | Data.Alpha(_) (* dead code ? *) | Data.Array(_) -> - Printf.sprintf " memcpy(%s, %s, %s);\n" vi vo size + let t_str = Soc2cIdent.type_to_short_string t in + Printf.sprintf " _assign_%s(%s, %s);\n" t_str vi vo | Data.Extern (id) -> (* what should i do for extern types? Ask the user to provide the diff --git a/test/lus2lic.sum b/test/lus2lic.sum index 942d8833..59c96a69 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,5 +1,5 @@ ==> lus2lic0.sum <== -Test Run By jahier on Thu Oct 2 14:42:39 +Test Run By jahier on Thu Oct 2 17:54:48 Native configuration is x86_64-unknown-linux-gnu === lus2lic0 tests === @@ -63,7 +63,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 Thu Oct 2 14:42:45 +Test Run By jahier on Thu Oct 2 17:54:40 Native configuration is x86_64-unknown-linux-gnu === lus2lic1 tests === @@ -397,7 +397,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 Thu Oct 2 14:42:41 +Test Run By jahier on Thu Oct 2 17:54:42 Native configuration is x86_64-unknown-linux-gnu === lus2lic2 tests === @@ -727,7 +727,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 Thu Oct 2 14:42:37 +Test Run By jahier on Thu Oct 2 17:54:46 Native configuration is x86_64-unknown-linux-gnu === lus2lic3 tests === @@ -1230,7 +1230,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 Thu Oct 2 14:42:43 +Test Run By jahier on Thu Oct 2 17:54:44 Native configuration is x86_64-unknown-linux-gnu === lus2lic4 tests === @@ -1726,14 +1726,14 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {} # of unexpected failures 3 =============================== # Total number of failures: 14 -lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 2 seconds -lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 30 seconds -lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 73 seconds -lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 48 seconds -lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 136 seconds +lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 0 seconds +lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 39 seconds +lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 78 seconds +lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 52 seconds +lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 137 seconds * Ref time: -0.06user 0.07system 4:31.90elapsed 0%CPU (0avgtext+0avgdata 3008maxresident)k -96inputs+0outputs (0major+14880minor)pagefaults 0swaps +0.04user 0.08system 5:13.43elapsed 0%CPU (0avgtext+0avgdata 3004maxresident)k +96inputs+0outputs (0major+14864minor)pagefaults 0swaps * Quick time (-j 4): -0.07user 0.05system 2:21.44elapsed 0%CPU (0avgtext+0avgdata 3008maxresident)k -120inputs+0outputs (0major+14890minor)pagefaults 0swaps +0.06user 0.07system 2:21.38elapsed 0%CPU (0avgtext+0avgdata 3008maxresident)k +120inputs+0outputs (0major+14876minor)pagefaults 0swaps diff --git a/test/lus2lic.time b/test/lus2lic.time index 1f16616d..ff982113 100644 --- a/test/lus2lic.time +++ b/test/lus2lic.time @@ -1,11 +1,11 @@ -lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 2 seconds -lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 30 seconds -lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 73 seconds -lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 48 seconds -lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 136 seconds +lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 0 seconds +lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 39 seconds +lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 78 seconds +lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 52 seconds +lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 137 seconds * Ref time: -0.06user 0.07system 4:31.90elapsed 0%CPU (0avgtext+0avgdata 3008maxresident)k -96inputs+0outputs (0major+14880minor)pagefaults 0swaps +0.04user 0.08system 5:13.43elapsed 0%CPU (0avgtext+0avgdata 3004maxresident)k +96inputs+0outputs (0major+14864minor)pagefaults 0swaps * Quick time (-j 4): -0.07user 0.05system 2:21.44elapsed 0%CPU (0avgtext+0avgdata 3008maxresident)k -120inputs+0outputs (0major+14890minor)pagefaults 0swaps +0.06user 0.07system 2:21.38elapsed 0%CPU (0avgtext+0avgdata 3008maxresident)k +120inputs+0outputs (0major+14876minor)pagefaults 0swaps diff --git a/todo.org b/todo.org index 6f053092..197557f9 100644 --- a/todo.org +++ b/todo.org @@ -551,36 +551,4 @@ file:~/lus2lic/src/evalClock.ml::83 I would like suggestion something to be added in the C code generation part of the v6 compiler. -*** Generate a copy of memcpy and replace the sizeof operator with the actual size of the structure. - -It seems that the "assert" operator will generate "array" structure where -the number of the element depending on the -number of the arguments to the "assert". The generated C code tries to make -a copy of this structure with -memcpy and giving sizeof(the_structure_to_copy) as the argument. - -Since OTAWA does not handle memcpy, could you generate a version of memcpy -(contains a for loop) for each memcpy call. -(Or just to paste the for loop to replace the memcpy call), while the -iteration count of the for loop is given (in actual value) -so that ORANGE can handle it..... - -The followings were raised by Pascal: - -*** The expansion of nodes with -efn --expand-following-nodes [easy] - -the current available options are: - --en, --expand-nodes - Expand the main node (use the first node if no one is -specified). --den, --do_not-expand-nodes <string> - Do not expand the specified node (meaningful with -en only of -course). - -It might be better if another option such as -efn --expand-following-nodes -<string> -The nodes which are not in the string will not be expanded. - - ** Generate macro for simple predef op in -2c mode. diff --git a/todo.org_archive b/todo.org_archive index 6f758b1c..fc122154 100644 --- a/todo.org_archive +++ b/todo.org_archive @@ -1231,6 +1231,64 @@ grep "FAIL:" lus2lic*.log | grep "exec" | grep "\-2c" | sed s/'FAIL: Try to comp :ARCHIVE_CATEGORY: lv6 :END: +* The expansion of nodes with -efn --expand-following-nodes [easy] + :PROPERTIES: + :ARCHIVE_TIME: 2014-10-02 Thu 14:54 + :ARCHIVE_FILE: ~/lus2lic/todo.org + :ARCHIVE_OLPATH: a classer/Willie's wishes + :ARCHIVE_CATEGORY: lv6 + :END: + +the current available options are: + +-en, --expand-nodes + Expand the main node (use the first node if no one is +specified). +-den, --do_not-expand-nodes <string> + Do not expand the specified node (meaningful with -en only of +course). + +It might be better if another option such as -efn --expand-following-nodes +<string> +The nodes which are not in the string will not be expanded. + +* Generate a copy of memcpy and replace the sizeof operator with the actual size of the structure. + :PROPERTIES: + :ARCHIVE_TIME: 2014-10-02 Thu 17:54 + :ARCHIVE_FILE: ~/lus2lic/todo.org + :ARCHIVE_OLPATH: a classer/Willie's wishes + :ARCHIVE_CATEGORY: lv6 + :END: + + It seems that the "assert" operator will generate "array" structure + where the number of the element depending on the number of the + arguments to the "assert". The generated C code tries to make a + copy of this structure with memcpy and giving + sizeof(the_structure_to_copy) as the argument. + + Since OTAWA does not handle memcpy, could you generate a version of + memcpy (contains a for loop) for each memcpy call. (Or just to + paste the for loop to replace the memcpy call), while the iteration + count of the for loop is given (in actual value) so that ORANGE can + handle it..... + + +je comprend pas tout, mais ce que je retiens, c'est de remplacer les memcpy +par des appels a des fonctions (ou des macros) qui par default utiliseraient +des memcpy + +genre + + _assign_ip2(ctx.x, ctx.y); + +#+BEGIN_SRC C +#ifndef _assign_ip2 +#define _assign_ip2(dest, source) memcpy(dest, source, sizeof(dest)) +#endif +#+END_SRC + + + -- GitLab