diff --git a/src/soc2c.ml b/src/soc2c.ml index 603965df8493749522fef2ad8aab2f1db4f63f6d..0074cec79d9b64ebdf340e35ec6391132a022813 100644 --- a/src/soc2c.ml +++ b/src/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 24/06/2014 (at 09:44) by Erwan Jahier> *) +(* Time-stamp: <modified the 24/06/2014 (at 14:26) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -57,7 +57,7 @@ let rec (lic_type_to_c: Lic.type_ -> string -> string) = let field_to_c (id,(tf,_opt)) = Printf.sprintf "\n %s;" (type_to_string (Lic2soc.lic_to_data_type tf) (id2s id)) in - ((Printf.sprintf "struct { %s } " + ((Printf.sprintf "struct { %s\n }" (String.concat "" (List.map field_to_c fl)))^ " " ^ n) | Enum_type_eff (name, l) -> "_integer"^ " " ^ n | _ -> type_to_string (Lic2soc.lic_to_data_type t) n @@ -137,6 +137,7 @@ let (gao2c : Soc.tbl -> 'a soc_pp -> Soc.gao -> unit) = let gen_assign2 vi vo = Soc2cUtil.gen_assign (Soc.data_type_of_var_expr vi) (string_of_var_expr sp.soc vi) (string_of_var_expr sp.soc vo) + (Printf.sprintf "sizeof(%s)" (string_of_var_expr sp.soc vo)) in let l = List.map2 gen_assign2 vel_out vel_in in String.concat "" l @@ -284,6 +285,24 @@ let (typedef_of_soc : Soc.t -> string) = str module KeySet = Set.Make(struct type t = Soc.key let compare = compare end) +module ItemKeySet = Set.Make(struct type t = Lic.item_key let compare = compare end) + +(* To perform the topological sort of typedef. nf stands for "no + fixpoint", that should be done by the caller. it is recursive just + to deal with array of arrays *) +let (find_typedep_nf : Lic.type_ -> Lic.item_key list) = + fun t -> + let rec aux top = function + | Lic.Bool_type_eff | Lic.Int_type_eff | Lic.Real_type_eff + | Lic.External_type_eff _ | Lic.TypeVar _ + -> [] + | Lic.Abstract_type_eff(name,_) + | Lic.Enum_type_eff(name,_) -> if top then [] (* avoid self dep *) else [name] + | Lic.Array_type_eff(t,_) -> aux false t + | Lic.Struct_type_eff(name, fl) -> + if not top then [name] else List.flatten(List.map (fun (_,(t,_)) -> aux false t) fl) + in + aux true t let (typedef : LicPrg.t -> Soc.tbl -> Soc.t -> string) = fun licprg soc_tbl main_soc -> @@ -321,13 +340,27 @@ let (typedef : LicPrg.t -> Soc.tbl -> Soc.t -> string) = in List.fold_left memless_soc_to_string "" socs in - (* There are also typedef that comes from user in Lustre V6 *) - let user_typedef = - let to_c k t = - Printf.sprintf "typedef %s;\n" (lic_type_to_c t (long2s k)) - in - LicPrg.fold_types (fun k t acc -> acc ^ (to_c k t)) licprg "" + let to_c k t = + Printf.sprintf "typedef %s;\n" (lic_type_to_c t (long2s k)) in + let rec (typedef_to_string : Lic.item_key -> Lic.type_ -> string * ItemKeySet.t -> + string * ItemKeySet.t) = + fun k t acc -> + (* topological sort according to type dep *) + if ItemKeySet.mem k (snd acc) then acc else + let type_list = find_typedep_nf t in + let acc = List.fold_left + (fun acc k -> + match LicPrg.find_type licprg k with + | Some t -> typedef_to_string k t acc + | None -> acc (* occurs ? *) + ) + acc type_list + in + ((fst acc)^(to_c k t), ItemKeySet.add k (snd acc)) + in + let user_typedef,_ = LicPrg.fold_types typedef_to_string licprg ("",ItemKeySet.empty) in + "// User typedef \n"^user_typedef ^"// Memoryless soc ctx typedef \n"^soc_ctx_typedef_without ^"// Memoryfull soc ctx typedef \n"^soc_ctx_typedef_with diff --git a/test/lus2lic.sum b/test/lus2lic.sum index a2529e56dab979c2952ee8e0fb1c35da0b18b996..582449356a0905bbc6d27b2b6b38230d35bfec52 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,4 +1,4 @@ -Test Run By jahier on Tue Jun 24 09:50:48 2014 +Test Run By jahier on Tue Jun 24 15:01:05 2014 Native configuration is i686-pc-linux-gnu === lus2lic tests === @@ -513,7 +513,7 @@ PASS: ./lus2lic {-ec -o /tmp/morel5.ec should_work/morel5.lus} PASS: ./myec2c {-o /tmp/morel5.c /tmp/morel5.ec} PASS: ../utils/test_lus2lic_no_node should_work/morel5.lus PASS: ./lus2lic {-2c should_work/morel5.lus -n morel5} -FAIL: Check that the generated C code compiles : gcc morel5_morel5.c morel5_morel5_loop.c +PASS: gcc morel5_morel5.c morel5_morel5_loop.c PASS: ./lus2lic {-o /tmp/bred.lic should_work/bred.lus} PASS: ./lus2lic {-ec -o /tmp/bred.ec should_work/bred.lus} PASS: ./myec2c {-o /tmp/bred.c /tmp/bred.ec} @@ -1053,7 +1053,7 @@ PASS: ./lus2lic {-ec -o /tmp/Gyroscope.ec should_work/Gyroscope.lus} PASS: ./myec2c {-o /tmp/Gyroscope.c /tmp/Gyroscope.ec} FAIL: Try to compare lus2lic -exec and ecexe: ../utils/test_lus2lic_no_node should_work/Gyroscope.lus PASS: ./lus2lic {-2c should_work/Gyroscope.lus -n Gyroscope} -FAIL: Check that the generated C code compiles : gcc Gyroscope_Gyroscope.c Gyroscope_Gyroscope_loop.c +PASS: gcc Gyroscope_Gyroscope.c Gyroscope_Gyroscope_loop.c PASS: ./lus2lic {-o /tmp/test_map.lic should_work/test_map.lus} PASS: ./lus2lic {-ec -o /tmp/test_map.ec should_work/test_map.lus} PASS: ./myec2c {-o /tmp/test_map.c /tmp/test_map.ec} @@ -1482,9 +1482,9 @@ XPASS: Test bad programs (semantics): lus2lic {-o /tmp/bug.lic should_fail/seman === lus2lic Summary === -# of expected passes 1279 -# of unexpected failures 133 +# of expected passes 1281 +# of unexpected failures 131 # of unexpected successes 21 # of expected failures 37 -testcase ./lus2lic.tests/non-reg.exp completed in 139 seconds +testcase ./lus2lic.tests/non-reg.exp completed in 137 seconds testcase ./lus2lic.tests/progression.exp completed in 0 seconds diff --git a/test/lus2lic.time b/test/lus2lic.time index 4aeb9e743b56096fe1f1feedc79a3d208ee11867..484c0604947af1f4c1096adbdd0d5f5fd97e24b4 100644 --- a/test/lus2lic.time +++ b/test/lus2lic.time @@ -1,2 +1,2 @@ -testcase ./lus2lic.tests/non-reg.exp completed in 139 seconds +testcase ./lus2lic.tests/non-reg.exp completed in 137 seconds testcase ./lus2lic.tests/progression.exp completed in 0 seconds