From 72cac326a850e83908a07cbb4c577ed3eec93eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Wed, 19 Oct 2011 16:31:40 +0200 Subject: [PATCH] Fixed normalization of fby We should normalize not only outputs but also other fbys to generate correct code. The test shows a program that was compiled incorrectly. --- compiler/minils/transformations/normalize_mem.ml | 12 +++++++++++- test/good/fbyfby2.ept | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/good/fbyfby2.ept diff --git a/compiler/minils/transformations/normalize_mem.ml b/compiler/minils/transformations/normalize_mem.ml index 402dc68..56c3201 100644 --- a/compiler/minils/transformations/normalize_mem.ml +++ b/compiler/minils/transformations/normalize_mem.ml @@ -11,6 +11,15 @@ open Mls_mapfold o = mem_o *) +let memory_vars_vds nd = + let build env l = + List.fold_left (fun env vd -> Env.add vd.v_ident vd env) env l + in + let env = build Env.empty nd.n_output in + let env = build env nd.n_local in + let mem_var_tys = Mls_utils.node_memory_vars nd in + List.map (fun (x, _) -> Env.find x env) mem_var_tys + 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 @@ -33,7 +42,8 @@ let eq _ (outputs, v, eqs) eq = match eq.eq_lhs, eq.eq_rhs.e_desc with let contract funs acc c = c, acc let node funs acc nd = - let nd, (_, v, eqs) = Mls_mapfold.node_dec funs (nd.n_output, nd.n_local, []) nd in + let outputs_mems = nd.n_output @ memory_vars_vds nd in + let nd, (_, v, eqs) = Mls_mapfold.node_dec funs (outputs_mems, nd.n_local, []) nd in (* return updated node *) { nd with n_local = v; n_equs = List.rev eqs }, acc diff --git a/test/good/fbyfby2.ept b/test/good/fbyfby2.ept new file mode 100644 index 0000000..86199ef --- /dev/null +++ b/test/good/fbyfby2.ept @@ -0,0 +1,6 @@ +node f() returns (o:bool) +var x:bool; +let + o = x; + x = true fby false fby x; +tel \ No newline at end of file