Skip to content
Snippets Groups Projects
Commit cda63b94 authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Soc2c: Print user typedef in the good order (wrt type dependencies)

nb:  unexpected failures 133-> 131
parent c1159ec0
No related branches found
No related tags found
No related merge requests found
(* 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 = *) (* 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) = ...@@ -57,7 +57,7 @@ let rec (lic_type_to_c: Lic.type_ -> string -> string) =
let field_to_c (id,(tf,_opt)) = let field_to_c (id,(tf,_opt)) =
Printf.sprintf "\n %s;" (type_to_string (Lic2soc.lic_to_data_type tf) (id2s id)) Printf.sprintf "\n %s;" (type_to_string (Lic2soc.lic_to_data_type tf) (id2s id))
in in
((Printf.sprintf "struct { %s } " ((Printf.sprintf "struct { %s\n }"
(String.concat "" (List.map field_to_c fl)))^ " " ^ n) (String.concat "" (List.map field_to_c fl)))^ " " ^ n)
| Enum_type_eff (name, l) -> "_integer"^ " " ^ n | Enum_type_eff (name, l) -> "_integer"^ " " ^ n
| _ -> type_to_string (Lic2soc.lic_to_data_type t) 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) = ...@@ -137,6 +137,7 @@ let (gao2c : Soc.tbl -> 'a soc_pp -> Soc.gao -> unit) =
let gen_assign2 vi vo = let gen_assign2 vi vo =
Soc2cUtil.gen_assign (Soc.data_type_of_var_expr vi) Soc2cUtil.gen_assign (Soc.data_type_of_var_expr vi)
(string_of_var_expr sp.soc vi) (string_of_var_expr sp.soc vo) (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 in
let l = List.map2 gen_assign2 vel_out vel_in in let l = List.map2 gen_assign2 vel_out vel_in in
String.concat "" l String.concat "" l
...@@ -284,6 +285,24 @@ let (typedef_of_soc : Soc.t -> string) = ...@@ -284,6 +285,24 @@ let (typedef_of_soc : Soc.t -> string) =
str str
module KeySet = Set.Make(struct type t = Soc.key let compare = compare end) 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) = let (typedef : LicPrg.t -> Soc.tbl -> Soc.t -> string) =
fun licprg soc_tbl main_soc -> fun licprg soc_tbl main_soc ->
...@@ -321,13 +340,27 @@ let (typedef : LicPrg.t -> Soc.tbl -> Soc.t -> string) = ...@@ -321,13 +340,27 @@ let (typedef : LicPrg.t -> Soc.tbl -> Soc.t -> string) =
in in
List.fold_left memless_soc_to_string "" socs List.fold_left memless_soc_to_string "" socs
in in
(* There are also typedef that comes from user in Lustre V6 *) let to_c k t =
let user_typedef = Printf.sprintf "typedef %s;\n" (lic_type_to_c t (long2s k))
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 ""
in 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 "// User typedef \n"^user_typedef
^"// Memoryless soc ctx typedef \n"^soc_ctx_typedef_without ^"// Memoryless soc ctx typedef \n"^soc_ctx_typedef_without
^"// Memoryfull soc ctx typedef \n"^soc_ctx_typedef_with ^"// Memoryfull soc ctx typedef \n"^soc_ctx_typedef_with
......
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 Native configuration is i686-pc-linux-gnu
=== lus2lic tests === === lus2lic tests ===
...@@ -513,7 +513,7 @@ PASS: ./lus2lic {-ec -o /tmp/morel5.ec should_work/morel5.lus} ...@@ -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: ./myec2c {-o /tmp/morel5.c /tmp/morel5.ec}
PASS: ../utils/test_lus2lic_no_node should_work/morel5.lus PASS: ../utils/test_lus2lic_no_node should_work/morel5.lus
PASS: ./lus2lic {-2c should_work/morel5.lus -n morel5} 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 {-o /tmp/bred.lic should_work/bred.lus}
PASS: ./lus2lic {-ec -o /tmp/bred.ec should_work/bred.lus} PASS: ./lus2lic {-ec -o /tmp/bred.ec should_work/bred.lus}
PASS: ./myec2c {-o /tmp/bred.c /tmp/bred.ec} PASS: ./myec2c {-o /tmp/bred.c /tmp/bred.ec}
...@@ -1053,7 +1053,7 @@ PASS: ./lus2lic {-ec -o /tmp/Gyroscope.ec should_work/Gyroscope.lus} ...@@ -1053,7 +1053,7 @@ PASS: ./lus2lic {-ec -o /tmp/Gyroscope.ec should_work/Gyroscope.lus}
PASS: ./myec2c {-o /tmp/Gyroscope.c /tmp/Gyroscope.ec} 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 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} 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 {-o /tmp/test_map.lic should_work/test_map.lus}
PASS: ./lus2lic {-ec -o /tmp/test_map.ec 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} 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 ...@@ -1482,9 +1482,9 @@ XPASS: Test bad programs (semantics): lus2lic {-o /tmp/bug.lic should_fail/seman
=== lus2lic Summary === === lus2lic Summary ===
# of expected passes 1279 # of expected passes 1281
# of unexpected failures 133 # of unexpected failures 131
# of unexpected successes 21 # of unexpected successes 21
# of expected failures 37 # 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 testcase ./lus2lic.tests/progression.exp completed in 0 seconds
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 testcase ./lus2lic.tests/progression.exp completed in 0 seconds
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment