Fixed normalization of fby

The incorrect behaviour was introduced in commit
6b86b86e9d.

We should have:
       o = v fby e
     becomes
       mem_o = v fby e;
       o = mem_o

The old way would break with:
 v = true fby false fby v
that would generate unschedulable code.
This commit is contained in:
Cédric Pasteur 2011-09-08 11:45:43 +02:00
parent 2105d7ad18
commit 70787757aa
2 changed files with 21 additions and 36 deletions

View file

@ -40,7 +40,10 @@ let compile_program p =
let p =
pass "Automata minimization checks" true Tomato.tomato_checks p pp in
*)
(* Normalize memories*)
let p = pass "Normalize memories" true Normalize_mem.program p pp in
(* Scheduling *)
let p =
if !Compiler_options.use_interf_scheduler then
@ -49,9 +52,6 @@ let compile_program p =
pass "Scheduling" true Schedule.program p pp
in
(* Normalize memories*)
let p = pass "Normalize memories" true Normalize_mem.program p pp in
(* Memory allocation *)
let p = pass "memory allocation" !do_mem_alloc Interference.program p pp in

View file

@ -11,49 +11,34 @@ open Mls_mapfold
o = mem_o
*)
let fix_vd_ad env vd ad =
if Env.mem vd.v_ident env then
let x_copy = Env.find vd.v_ident env in
{ vd with v_ident = x_copy }, { ad with a_name = Some (Idents.name x_copy) }
else
vd, ad
let eq _ (outputs, eqs, env) eq = match eq.eq_lhs, eq.eq_rhs.e_desc with
let eq _ (outputs, v, eqs) eq = match eq.eq_lhs, eq.eq_rhs.e_desc with
| Evarpat x, Efby _ ->
if Mls_utils.vd_mem x outputs then
let ty = eq.eq_rhs.e_ty in
let lin = eq.eq_rhs.e_linearity in
let ck = eq.eq_rhs.e_base_ck in
let x_copy = Idents.gen_var "normalize_mem" ("out_"^(Idents.name x)) in
let exp_x =
mk_exp ck ~ck:ck ~ct:(Clocks.Ck ck) ty ~linearity:lin
(Eextvalue (mk_extvalue ~clock:ck ~ty:ty ~linearity:lin (Wvar x)))
in
let eq_copy = { eq with eq_lhs = Evarpat x_copy; eq_rhs = exp_x } in
let env = Env.add x x_copy env in
eq, (outputs, eq::eq_copy::eqs, env)
let vd = Mls_utils.vd_find x outputs in
let x_mem = Idents.gen_var "normalize_mem" ("mem_"^(Idents.name x)) in
let vd_mem = { vd with v_ident = x_mem } in
let exp_mem_x = mk_extvalue_exp vd.v_clock vd.v_type
~clock:vd.v_clock ~linearity:vd.v_linearity (Wvar x_mem) in
(* mem_o = v fby e *)
let eq_copy = { eq with eq_lhs = Evarpat x_mem } in
(* o = mem_o *)
let eq = { eq with eq_rhs = exp_mem_x } in
eq, (outputs, vd_mem::v, eq::eq_copy::eqs)
else (* this memory is not an output *)
eq, (outputs, eq::eqs, env)
eq, (outputs, v, eq::eqs)
| _, _ ->
eq, (outputs, eq::eqs, env)
eq, (outputs, v, eq::eqs)
(* Leave contract unchanged (no output defined in it) *)
let contract funs acc c = c, acc
let node funs acc nd =
let nd, (_, eqs, env) = Mls_mapfold.node_dec funs (nd.n_output, [], Env.empty) nd in
let v = Env.fold
(fun x _ acc -> (Mls_utils.vd_find x nd.n_output)::acc) env nd.n_local in
(* update the signature of the node *)
let f = Modules.find_value nd.n_name in
let o, sig_o = List.split (List.map2 (fix_vd_ad env) nd.n_output f.node_outputs) in
let f = { f with node_outputs = sig_o } in
Modules.replace_value nd.n_name f;
let nd, (_, v, eqs) = Mls_mapfold.node_dec funs (nd.n_output, nd.n_local, []) nd in
(* return updated node *)
{ nd with n_local = v; n_equs = List.rev eqs; n_output = o }, acc
{ nd with n_local = v; n_equs = List.rev eqs }, acc
let program p =
let funs = { Mls_mapfold.defaults with
eq = eq; node_dec = node; contract = contract } in
let p, _ = Mls_mapfold.program_it funs ([], [], Env.empty) p in
eq = eq; node_dec = node; contract = contract } in
let p, _ = Mls_mapfold.program_it funs ([], [], []) p in
p