diff --git a/compiler/minils/mls_utils.ml b/compiler/minils/mls_utils.ml index dde7852..16f9623 100644 --- a/compiler/minils/mls_utils.ml +++ b/compiler/minils/mls_utils.ml @@ -36,7 +36,7 @@ let rec bounds_list ty = (** @return the [var_dec] object corresponding to the name [n] in a list of [var_dec]. *) let rec vd_find n = function - | [] -> Format.eprintf "Not found var %s@." (name n); raise Not_found + | [] -> (*Format.eprintf "Not found var %s@." (name n);*) raise Not_found | vd::l -> if vd.v_ident = n then vd else vd_find n l diff --git a/compiler/minils/transformations/normalize_mem.ml b/compiler/minils/transformations/normalize_mem.ml index bb83348..2a4d9cb 100644 --- a/compiler/minils/transformations/normalize_mem.ml +++ b/compiler/minils/transformations/normalize_mem.ml @@ -9,26 +9,30 @@ open Mls_mapfold o = mem_o *) -let eq _ (v, eqs) eq = match eq.eq_lhs, eq.eq_rhs.e_desc with +let rec vd_replace vd by_vd vd_l = match vd_l with + | [] -> [] + | h::t -> if h.v_ident = vd.v_ident then by_vd::t else h::(vd_replace vd by_vd t) + +let eq _ (locals, eqs, outs) eq = match eq.eq_lhs, eq.eq_rhs.e_desc with | Evarpat x, Efby _ -> - if not (Mls_utils.vd_mem x v) then (* this memory is also an output *) + (try + let vd_out = Mls_utils.vd_find x outs in (* this memory is also an output *) let ty = eq.eq_rhs.e_ty in - let x_copy = Idents.gen_var "normalize_mem" ("mem_"^(Idents.name x)) in - let vd = mk_var_dec ~clock:eq.eq_rhs.e_ck x_copy ty in - let x_copy_exp = mk_exp ty (Eextvalue (mk_extvalue ~ty:ty (Wvar x_copy))) in - let eq_copy = { eq with eq_rhs = x_copy_exp } in - let eq = { eq with eq_lhs = Evarpat x_copy } in - eq, (vd::v, eq_copy::eq::eqs) - else - eq, (v, eq::eqs) + let x_copy = Idents.gen_var "normalize_mem" ("out_"^(Idents.name x)) in + let vd_x_copy = mk_var_dec ~clock:eq.eq_rhs.e_ck x_copy ty in + let exp_x = mk_exp ty (Eextvalue (mk_extvalue ~ty:ty (Wvar x))) in + let eq_copy = { eq with eq_lhs = Evarpat x_copy; eq_rhs = exp_x } in + eq, (vd_out::locals, eq::eq_copy::eqs, vd_replace vd_out vd_x_copy outs) + with Not_found -> (* this memory is not an output *) + eq, (locals, eq::eqs, outs)) | _, _ -> - eq, (v, eq::eqs) + eq, (locals, eq::eqs, outs) let node funs acc nd = - let nd, (v, eqs) = Mls_mapfold.node_dec funs (nd.n_local, []) nd in - { nd with n_local = v; n_equs = List.rev eqs }, acc + let nd, (v, eqs, o) = Mls_mapfold.node_dec funs (nd.n_local, [], nd.n_output) nd in + { nd with n_local = v; n_equs = List.rev eqs; n_output = o }, acc let program p = let funs = { Mls_mapfold.defaults with eq = eq; node_dec = node } in - let p, _ = Mls_mapfold.program_it funs ([], []) p in + let p, _ = Mls_mapfold.program_it funs ([], [], []) p in p