Added a pass to normalize memories

This adds a copy for outputs that are also
memories.
This commit is contained in:
Cédric Pasteur 2011-04-19 17:19:40 +02:00
parent 845d084658
commit 802178fb28
2 changed files with 37 additions and 0 deletions

View file

@ -34,4 +34,7 @@ let compile_program p =
(* Scheduling *)
let p = pass "Scheduling" true Schedule.program p pp in
(* Normalize memories*)
let p = pass "Normalize memories" true Normalize_mem.program p pp in
p

View file

@ -0,0 +1,34 @@
open Minils
open Mls_mapfold
(** Adds an extra equation for outputs that are also memories.
For instance, if o is an output, then:
o = v fby e
becomes
mem_o = v fby e;
o = mem_o
*)
let eq _ (v, eqs) 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 *)
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::eq_copy::eqs)
else
eq, (v, eq::eqs)
| _, _ ->
eq, (v, eq::eqs)
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 = eqs }, 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
p