Commit acde7631 authored by erwan's avatar erwan
Browse files

Fix: The C code for arrays of arrays constants was generating a gcc warning

parent 6dd0fc32
Pipeline #36569 passed with stages
in 3 minutes and 38 seconds
S src
S bin
S lib
S ../lutils/src
S ../rdbg/src
B _build/src
B _build/bin
B _build/lib
B ../lutils/_build/src
B ../rdbg/_build/src
(* Time-stamp: <modified the 29/08/2019 (at 17:11) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/02/2020 (at 14:03) by Erwan Jahier> *)
(* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
......@@ -119,19 +119,23 @@ let (step2c : Soc.tbl -> 'a soc_pp -> Soc.step_method -> unit) =
(match sp.soc.key with
| ("Lustre::eq",(Array _)::_,_) ->
let str = Printf.sprintf
" *out = memcmp((const void *) i1, (const void *) i2, %s)==0;\n" ctype in
" *out = memcmp((const void *) i1, (const void *) i2, %s)==0;\n"
ctype in
sp.cput str
| ("Lustre::eq",(Struct _)::_,_) ->
let str = Printf.sprintf
" *out = memcmp((const void *) &i1, (const void *) &i2, %s)==0;\n" ctype in
" *out = memcmp((const void *) &i1, (const void *) &i2, %s)==0;\n"
ctype in
sp.cput str
| ("Lustre::neq",(Array _)::_,_) ->
let str = Printf.sprintf
" *out = !memcmp((const void *) i1, (const void *) i2, %s)==0;\n" ctype in
" *out = !memcmp((const void *) i1, (const void *) i2, %s)==0;\n"
ctype in
sp.cput str
| ("Lustre::neq",(Struct _)::_,_) ->
let str = Printf.sprintf
" *out = !memcmp((const void *) &i1, (const void *) &i2, %s)==0;\n" ctype in
" *out = !memcmp((const void *) &i1, (const void *) &i2, %s)==0;\n"
ctype in
sp.cput str
| n -> sp.cput (Soc2cDep.get_predef_op n)
)
......@@ -452,31 +456,44 @@ let rec (const_to_c: Lic.const -> string) =
Indeed, arrays constant need to be defined in a .c
*)
let (constdef : LicPrg.t -> string*string) =
fun licprg ->
let to_c k = function
| Lic.Extern_const_eff _ -> "",""
(* | Lic.Array_const_eff (ctab, Array_type_eff(_t,s)) -> ( *)
| Lic.Array_const_eff (ctab, _t) -> (
fun licprg ->
let rec (array_type_to_c: string -> string -> int -> Lic.type_ -> string) =
fun name acc s t -> match t with
| Lic.Array_type_eff (t2, s2) ->
array_type_to_c name (Printf.sprintf "%s [%i]" acc s) s2 t2
| Lic.Bool_type_eff-> Printf.sprintf "_boolean %s %s[%i]" name acc s
| Lic.Int_type_eff -> Printf.sprintf "_integer %s %s[%i]" name acc s
| Lic.Real_type_eff -> Printf.sprintf "_real %s %s[%i]" name acc s
| Lic.External_type_eff _ -> assert false
| Lic.Abstract_type_eff _ -> assert false
| Lic.Enum_type_eff _ -> assert false
| Lic.Struct_type_eff _ -> assert false
| Lic.TypeVar _ -> assert false
in
let to_c k = function
| Lic.Extern_const_eff _ -> "",""
(* | Lic.Array_const_eff (ctab, Array_type_eff(_t,s)) -> ( *)
| Lic.Array_const_eff (ctab, t) -> (
let vl = List.map const_to_c ctab in
let s = List.length vl in
let tab_exp = "{"^(String.concat ", " vl)^"}" in
Printf.sprintf "const %s [%i];\n" (long2s k) s,
Printf.sprintf "const %s [%i] = %s;\n" (long2s k) s tab_exp
Printf.sprintf "const %s;\n" (array_type_to_c (long2s k) "" s t),
Printf.sprintf "const %s = %s;\n" (array_type_to_c (long2s k) "" s t) tab_exp
)
| c ->
| c ->
Printf.sprintf "#define %s %s\n"
(long2s k)
(const_to_c c),""
in
let strh,strc = LicPrg.fold_consts
(fun k t (acc_h,acc_c) ->
let h,c = to_c k t in
(acc_h^h,acc_c^c)) licprg ("","")
in
(if strh = "" then "" else
"\n// Constant definitions \n" ^ strh),
(if strc = "" then "" else
"\n// Constant definitions \n" ^ strc)
in
let strh,strc = LicPrg.fold_consts
(fun k t (acc_h,acc_c) ->
let h,c = to_c k t in
(acc_h^h,acc_c^c)) licprg ("","")
in
(if strh = "" then "" else
"\n// Constant definitions \n" ^ strh),
(if strc = "" then "" else
"\n// Constant definitions \n" ^ strc)
(****************************************************************************)
......@@ -923,6 +940,7 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
Soc2cExtern.gen_files main_soc stbl licprg ext_cfile ext_hfile hfile
in
Lv6util.entete consts_h_oc "/*" "*/" ;
output_string consts_h_oc "#include \"lustre_types.h\"";
output_string consts_h_oc const_def_h;
Lv6util.entete consts_c_oc "/*" "*/" ;
output_string consts_c_oc "#include \"lustre_consts.h\"";
......@@ -966,7 +984,6 @@ typedef float _float;
#include <stdlib.h>
#include <string.h>
#include \"lustre_types.h\"
#include \"lustre_consts.h\"
";
......
==> lus2lic0.sum <==
Test run by jahier on Fri Feb 14 11:11:29
Test run by jahier on Fri Feb 14 11:52:31
Native configuration is x86_64-pc-linux-gnu
=== lus2lic0 tests ===
......@@ -66,7 +66,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 Fri Feb 14 11:11:29
Test run by jahier on Fri Feb 14 11:52:32
Native configuration is x86_64-pc-linux-gnu
=== lus2lic1 tests ===
......@@ -343,6 +343,9 @@ PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c matrice.lus {}
PASS: ./lus2lic {-2c matrice2.lus -n matrice2}
PASS: sh matrice2.sh
PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c matrice2.lus {}
PASS: ./lus2lic {-2c matrix_constant.lus -n matrix_constant}
PASS: sh matrix_constant.sh
PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c matrix_constant.lus {}
PASS: ./lus2lic {-2c minmax1.lus -n minmax1}
PASS: sh minmax1.sh
PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c minmax1.lus {}
......@@ -409,7 +412,7 @@ PASS: sh multipar.sh
PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c multipar.lus {}
==> lus2lic2.sum <==
Test run by jahier on Fri Feb 14 11:11:54
Test run by jahier on Fri Feb 14 11:53:00
Native configuration is x86_64-pc-linux-gnu
=== lus2lic2 tests ===
......@@ -749,7 +752,7 @@ PASS: sh zzz2.sh
PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c zzz2.lus {}
==> lus2lic3.sum <==
Test run by jahier on Fri Feb 14 11:12:25
Test run by jahier on Fri Feb 14 11:53:34
Native configuration is x86_64-pc-linux-gnu
=== lus2lic3 tests ===
......@@ -1147,6 +1150,10 @@ PASS: ./lus2lic {} {-lic -o matrice2.lic matrice2.lus}
PASS: ./lus2lic {-ec -o matrice2.ec matrice2.lus}
PASS: ./myec2c {-o matrice2.c matrice2.ec}
PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node matrice2.lus {}
PASS: ./lus2lic {} {-lic -o matrix_constant.lic matrix_constant.lus}
PASS: ./lus2lic {-ec -o matrix_constant.ec matrix_constant.lus}
PASS: ./myec2c {-o matrix_constant.c matrix_constant.ec}
PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node matrix_constant.lus {}
PASS: ./lus2lic {} {-lic -o minmax1.lic minmax1.lus}
PASS: ./lus2lic {-ec -o minmax1.ec minmax1.lus}
PASS: ./myec2c {-o minmax1.c minmax1.ec}
......@@ -1259,7 +1266,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node multipar.lus {}
==> lus2lic4.sum <==
Test run by jahier on Fri Feb 14 11:13:05
Test run by jahier on Fri Feb 14 11:54:15
Native configuration is x86_64-pc-linux-gnu
=== lus2lic4 tests ===
......@@ -1751,7 +1758,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {}
=== lus2lic1 Summary ===
# of expected passes 330
# of expected passes 333
# of unexpected failures 1
==> lus2lic2.sum <==
......@@ -1764,7 +1771,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {}
==> lus2lic3.sum <==
=== lus2lic3 Summary ===
# of expected passes 491
# of expected passes 495
# of unexpected failures 5
# of unresolved testcases 1
......@@ -1776,14 +1783,14 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {}
# of unexpected failures 7
===============================
# Total number of failures: 15
lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 0 seconds
lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 25 seconds
lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 31 seconds
lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 40 seconds
lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 16 seconds
lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 1 seconds
lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 28 seconds
lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 34 seconds
lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 41 seconds
lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 18 seconds
* Ref time:
60.66user 19.96system 1:52.11elapsed 71%CPU (0avgtext+0avgdata 284016maxresident)k
0inputs+141512outputs (0major+11144113minor)pagefaults 0swaps
66.86user 22.59system 2:01.44elapsed 73%CPU (0avgtext+0avgdata 283984maxresident)k
0inputs+142256outputs (0major+11205615minor)pagefaults 0swaps
* Quick time (-j 4):
67.26user 21.07system 1:11.03elapsed 124%CPU (0avgtext+0avgdata 283796maxresident)k
0inputs+136976outputs (0major+10867311minor)pagefaults 0swaps
76.54user 24.41system 1:18.16elapsed 129%CPU (0avgtext+0avgdata 282848maxresident)k
0inputs+141112outputs (0major+11127257minor)pagefaults 0swaps
const f=false;
const t=true;
const mask=[
[f,t,f,f,f,f,t],
[t,f,t,f,f,f,f],
[f,t,f,t,f,f,f],
[t,f,f,f,f,t,f]];
node matrix_constant(x:bool^7^4) returns (z:bool^7^4);
let
z = map<< map<<or, 7>>, 4 >>(mask, x);
tel
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment