From 60aab16d1e371ee1bbb61e6f3e542ef83ae6dcfe Mon Sep 17 00:00:00 2001
From: xthirioux <thirioux@enseeiht.fr>
Date: Tue, 2 Feb 2016 18:35:15 +0100
Subject: [PATCH] Bug solved in automaton part

---
 src/automata.ml             | 26 ++++++++++++++++++++++++--
 src/main_lustre_compiler.ml |  2 ++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/automata.ml b/src/automata.ml
index 4a98cef6..ec08590c 100755
--- a/src/automata.ml
+++ b/src/automata.ml
@@ -68,7 +68,16 @@ let expr_of_exit loc restart state conds tag =
   mkexpr loc (Expr_when (List.fold_right add_branch conds (mkidentpair loc restart state), state, tag))
 
 let rec unless_read reads handler =
+  let res =
   List.fold_left (fun read (_, c, _, _) -> get_expr_vars read c) reads handler.hand_unless
+  in
+(
+(*
+Format.eprintf "unless_reads %s = %a@." handler.hand_state (fprintf_list ~sep:" , " (fun fmt v -> Format.fprintf fmt "%s" v)) (ISet.elements reads);
+Format.eprintf "unless_reads' %s = %a@." handler.hand_state (fprintf_list ~sep:" , " (fun fmt v -> Format.fprintf fmt "%s" v)) (ISet.elements res);
+*)
+res
+)
 
 let rec until_read reads handler =
   List.fold_left (fun read (_, c, _, _) -> get_expr_vars read c) reads handler.hand_until
@@ -79,8 +88,19 @@ let rec handler_read reads handler =
     List.fold_left (fun read stmt ->
       match stmt with
       | Eq eq -> get_expr_vars read eq.eq_rhs
-      | Aut aut -> List.fold_left handler_read read aut.aut_handlers ) reads handler.hand_stmts
-  in ISet.diff allvars locals
+      | Aut aut -> automata_read read aut) reads handler.hand_stmts
+  in let res = ISet.diff allvars locals
+     in
+(
+(*
+Format.eprintf "handler_allvars %s = %a@." handler.hand_state (fprintf_list ~sep:" , " (fun fmt v -> Format.fprintf fmt "%s" v)) (ISet.elements allvars);
+Format.eprintf "handler_read %s = %a@." handler.hand_state (fprintf_list ~sep:" , " (fun fmt v -> Format.fprintf fmt "%s" v)) (ISet.elements res);
+*)
+res
+)
+
+and automata_read reads aut =
+  List.fold_left (fun read handler -> until_read (handler_read (unless_read read handler) handler) handler) reads aut.aut_handlers
 
 let rec handler_write writes handler =
   let locals = List.fold_left (fun locals v -> ISet.add v.var_id locals) ISet.empty handler.hand_locals in
@@ -117,6 +137,7 @@ let vars_of_aut_state aut_state =
   [aut_state.incoming_r'; aut_state.incoming_r; aut_state.actual_r; aut_state.incoming_s'; as_clock aut_state.incoming_s; as_clock aut_state.actual_s]
 
 let node_of_unless nused used node aut_id aut_state handler =
+(*Format.eprintf "node_of_unless %s@." node.node_id;*)
   let inputs = unless_read ISet.empty handler in
   let var_inputs = aut_state.incoming_r :: aut_state.incoming_s :: (node_vars_of_idents node inputs) in
   let var_outputs = aut_state.actual_r :: aut_state.actual_s :: [] in
@@ -160,6 +181,7 @@ let mk_frename used outputs =
   (fun name -> try IMap.find name table with Not_found -> name)
 
 let node_of_assign_until nused used node aut_id aut_state handler =
+(*Format.eprintf "node_of_assign_until %s@." node.node_id;*)
   let writes = handler_write ISet.empty handler in
   let inputs = ISet.diff (handler_read (until_read ISet.empty handler) handler) writes in
   let frename = mk_frename used writes in
diff --git a/src/main_lustre_compiler.ml b/src/main_lustre_compiler.ml
index 5e84c33e..a0d5b623 100644
--- a/src/main_lustre_compiler.ml
+++ b/src/main_lustre_compiler.ml
@@ -98,6 +98,8 @@ let rec compile_source dirname basename extension =
   (* Removing automata *)
   let prog = Automata.expand_decls prog in
 
+  Log.report ~level:4 (fun fmt -> fprintf fmt "After automata expansion:@.@[<v 2>@ %a@]@," Printers.pp_prog prog);
+
   (* Importing source *)
   let _ = Modules.load_program ISet.empty prog in
 
-- 
GitLab