diff --git a/lib/soc2c.ml b/lib/soc2c.ml index a29c4352da746ecb50e4c5c7d58c16846b97cf04..12cc427fa6ab73fa42d39705d1837fc17e154e31 100644 --- a/lib/soc2c.ml +++ b/lib/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 07/07/2022 (at 16:46) by Erwan Jahier> *) +(* Time-stamp: <modified the 08/07/2022 (at 11:04) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -243,21 +243,21 @@ let one_file() = Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_one_file - updates/returns the list of created C files *) let (soc2c : int -> out_channel -> out_channel -> Soc.tbl -> Soc.key -> string list -> Soc.t -> string list) = - fun pass hfile cfile stbl msoc_key cfiles_acc soc -> + fun pass hfile_main_oc cfile_main_oc stbl msoc_key cfiles_acc soc -> if inlined_soc soc.key then cfiles_acc (* don't generate code if inlined *) else let ctx_name = get_ctx_name soc.key in let ctx_name_type = ctx_name^"_type" in if pass=1 then ( (* Only for ctx of memoryless nodes + main node *) if SocUtils.ctx_is_global soc then - Printf.kprintf (fun t -> output_string cfile t) "static %s %s;\n" ctx_name_type ctx_name; + Printf.kprintf (fun t -> output_string cfile_main_oc t) "static %s %s;\n" ctx_name_type ctx_name; cfiles_acc ) else ( let dir = Lv6MainArgs.global_opt.Lv6MainArgs.dir in let base0 = (string_of_soc_key soc.key) in let base = Filename.concat dir base0 in let cfile,hfile,cfiles_acc = - if one_file() || msoc_key = soc.key then cfile, hfile, cfiles_acc else + if one_file() || msoc_key = soc.key then cfile_main_oc, hfile_main_oc, cfiles_acc else let _cfile0 = (base0^".c") in let hfile0 = (base0^".h") in let cfile = (base^".c") in @@ -268,8 +268,6 @@ let (soc2c : int -> out_channel -> out_channel -> Soc.tbl -> Soc.key -> Lv6util.entete cfile_oc "/*" "*/" ; Lv6util.entete hfile_oc "/*" "*/" ; Printf.fprintf cfile_oc "#include \"%s\"\n" hfile0; - Printf.fprintf hfile_oc "#include \"lustre_types.h\"\n"; - Printf.fprintf hfile_oc "#include \"lustre_consts.h\"\n"; Printf.fprintf hfile_oc "#ifndef _%s_H_FILE \n" base0; Printf.fprintf hfile_oc "#define _%s_H_FILE \n" base0; flush cfile_oc; @@ -278,6 +276,7 @@ let (soc2c : int -> out_channel -> out_channel -> Soc.tbl -> Soc.key -> (if List.mem cfile cfiles_acc then cfiles_acc else cfile::cfiles_acc) in let hfmt fmt = Printf.kprintf (fun t -> output_string hfile t) fmt in + let main_hfmt fmt = Printf.kprintf (fun t -> output_string hfile_main_oc t) fmt in let cfmt fmt = Printf.kprintf (fun t -> output_string cfile t) fmt in let hput str = output_string hfile str in let cput str = output_string cfile str in @@ -287,12 +286,14 @@ let (soc2c : int -> out_channel -> out_channel -> Soc.tbl -> Soc.key -> let (used_soc:Soc.key list) = KeySet.elements (get_used_soc soc) in List.iter (fun sk -> if inlined_soc sk then () else - hfmt "#include \"%s.h\"\n" (string_of_soc_key sk) + hfmt "#include \"%s.h\"\n" (string_of_soc_key sk) ) used_soc; - if msoc_key <> soc.key then hfmt "%s\n" (Soc2cDep.typedef_of_soc soc); + if msoc_key <> soc.key then hfmt "#include \"%s.h\"\n" (string_of_soc_key msoc_key) ); - + + main_hfmt "/* Soc2cDep.typedef_of_soc XXX */ \n%s\n" "" ; + (* (Soc2cDep.typedef_of_soc soc); *) if SocUtils.is_memory_less soc then () else ( cfmt "// Memory initialisation for %s\n" ctx_name; hfmt "void %s_reset(%s_type* ctx);\n" ctx_name ctx_name; @@ -430,13 +431,14 @@ let (typedef_all : LicPrg.t -> Soc.tbl -> Soc.t -> string) = ) (acc,visited) soc.instances in - let acc = acc ^ ( - if one_file() || soc.key = main_soc.key then + let acc = acc ^ "/* Soc2cDep.typedef_of_soc YYY */\n" ^( + (* if one_file() || soc.key = main_soc.key then *) Soc2cDep.typedef_of_soc soc - else - (Printf.sprintf "#include \"%s.h\"\n" (string_of_soc_key soc.key)) + (* else *) + (* (Printf.sprintf "#include \"%s.h\"\n" (string_of_soc_key soc.key)) *) ) in + acc,visited in let soc_ctx_typedef_with_mem = @@ -444,7 +446,7 @@ let (typedef_all : LicPrg.t -> Soc.tbl -> Soc.t -> string) = fst (soc_with_mem ("",visited) main_soc) in (* Then we still have to print memoryless soc that can not appear - as a soc instance *) + as a soc instance let soc_ctx_typedef_without_mem = let socs = Soc.SocMap.bindings soc_tbl in let socs = snd (List.split socs) in @@ -453,8 +455,10 @@ let (typedef_all : LicPrg.t -> Soc.tbl -> Soc.t -> string) = in List.fold_left memless_soc_to_string "" socs in -"// Memoryless soc ctx typedef \n"^soc_ctx_typedef_without_mem - ^"// Memoryfull soc ctx typedef \n"^soc_ctx_typedef_with_mem + "// Memoryless soc ctx typedef \n"^soc_ctx_typedef_without_mem + ^ +*) + "// Memoryfull soc ctx typedef \n"^soc_ctx_typedef_with_mem @@ -644,7 +648,7 @@ int main(){" ^ (gen_main_loop_body inputs outputs soc ctx)); close_out oc -(* generate a node_loop.c and a node_loop_ios.ch *) +(* generate a node_loop.c and a node_loop_io.{ch} *) let (gen_loop_file : string -> LicPrg.t -> Soc.t -> string -> out_channel -> out_channel -> out_channel -> Soc.tbl -> unit) = fun fn licprg soc base main_oc readinput_oc_c readinput_oc_h stbl -> @@ -1055,10 +1059,7 @@ typedef float _float; #define _"^base0^"_TYPES\n"); output_string och (user_typedef licprg); flush och; - output_string och ((typedef_all licprg stbl main_soc ) - ^ "#endif // end of _"^base0^"_TYPES -"); - + if needs_hfile || args.Lv6MainArgs.ext_types then ( puth (Printf.sprintf "\n#ifndef _%s_H_FILE\n" base0); puth (Printf.sprintf "#include \"%s\"\n" ext_hfile0); @@ -1091,6 +1092,8 @@ typedef float _float; ); ) else cfiles_acc in + output_string och (typedef_all licprg stbl main_soc); + putc "//// Defining step functions\n"; let cfiles_acc = List.fold_left (soc2c 2 och occ stbl msoc) cfiles_acc socs in @@ -1189,6 +1192,8 @@ struct dro_desc_t DRO_DESC_NAME = { List.iter (fun t -> output_string och (Soc2cGenAssign.f t)) assign_ext_types_list ); + output_string och ("#endif // end of _"^base0^"_TYPES\n"); + flush occ; close_out occ; flush och; close_out och; if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then ( @@ -1326,7 +1331,8 @@ fi else gcc in output_string ocsh (gcc^"\n\n"); - flush ocsh; + flush ocsh; + close_out types_h_oc; close_out ocsh; let call_script = Printf.sprintf "sh %s.sh" (Filename.concat dir node) in diff --git a/test/lus2lic.sum b/test/lus2lic.sum index c0636f6436281af16d043b6509677bb493d2e667..1bd1a7c2aff01baeb13fcd6ab937773c0fc674fe 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,5 +1,5 @@ ==> lus2lic0.sum <== -Test run by jahier on Thu Jul 7 16:46:41 +Test run by jahier on Fri Jul 8 11:05:01 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 Thu Jul 7 16:46:42 +Test run by jahier on Fri Jul 8 11:05:02 Native configuration is x86_64-pc-linux-gnu === lus2lic1 tests === @@ -626,7 +626,7 @@ PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c multipar.lus {} PASS: /home/jahier/lus2lic/test/../utils/compare_lv6_and_lv6_en multipar.lus {} ==> lus2lic2.sum <== -Test run by jahier on Thu Jul 7 16:52:45 +Test run by jahier on Fri Jul 8 11:10:45 Native configuration is x86_64-pc-linux-gnu === lus2lic2 tests === @@ -1171,7 +1171,7 @@ PASS: /home/jahier/lus2lic/test/../utils/compare_lv6_and_lv6_en zzz2.lus {} PASS: /home/jahier/lus2lic/test/../utils/compare_gcc_and_clang zzz2.lus {} ==> lus2lic3.sum <== -Test run by jahier on Thu Jul 7 16:59:28 +Test run by jahier on Fri Jul 8 11:17:46 Native configuration is x86_64-pc-linux-gnu === lus2lic3 tests === @@ -1686,7 +1686,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node multipar.lus {} ==> lus2lic4.sum <== -Test run by jahier on Thu Jul 7 17:00:43 +Test run by jahier on Fri Jul 8 11:19:06 Native configuration is x86_64-pc-linux-gnu === lus2lic4 tests === @@ -2211,11 +2211,11 @@ PASS: /home/jahier/lus2lic/test/../utils/compare_gcc_and_clang multipar.lus {} =============================== # Total number of failures: 17 lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 1 seconds -lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 363 seconds -lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 403 seconds -lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 75 seconds -lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 62 seconds +lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 343 seconds +lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 421 seconds +lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 80 seconds +lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 67 seconds * Ref time: -331.09user 94.27system 15:03.86elapsed 47%CPU (0avgtext+0avgdata 76972maxresident)k -2968inputs+488936outputs (0major+22995187minor)pagefaults 0swaps +326.87user 90.70system 15:12.28elapsed 45%CPU (0avgtext+0avgdata 77356maxresident)k +36856inputs+488872outputs (79major+22973722minor)pagefaults 0swaps * Quick time (-j 4):