From 6b86b86e9da031928b6bc69cea9b9d7d0c80dcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20G=C3=A9rard?= Date: Wed, 20 Apr 2011 19:23:35 +0200 Subject: [PATCH] really fix normalize_mem. in the old fix was missing the renaming, and there was wrong equations order : f () returns x [here rename x by mem_x] mem_x = fby ... x = mem_x so the simplest was : f () returns out_x var x; [ nothing to do] out_x = x x = fby ... pay attention to the order of equations since we are after the scheduling.. probably it should be done before the scheduling anyway ? --- compiler/minils/mls_utils.ml | 2 +- .../minils/transformations/normalize_mem.ml | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) 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