From 0728f3dae73e028fc8c90fef8a1b07d1a9badfbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Wed, 27 Apr 2011 08:26:40 +0200 Subject: [PATCH] More work on code generation --- compiler/minils/analysis/interference.ml | 4 ++-- compiler/obc/obc_printer.ml | 2 ++ compiler/obc/obc_utils.ml | 4 ++++ compiler/obc/transformations/memalloc_apply.ml | 15 +++++++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/compiler/minils/analysis/interference.ml b/compiler/minils/analysis/interference.ml index febc347..18e6737 100644 --- a/compiler/minils/analysis/interference.ml +++ b/compiler/minils/analysis/interference.ml @@ -8,8 +8,8 @@ open Interference_graph open Containers open Printf -let print_interference_graphs = true -let verbose_mode = true +let print_interference_graphs = false +let verbose_mode = false let print_debug0 s = if verbose_mode then Format.printf s diff --git a/compiler/obc/obc_printer.ml b/compiler/obc/obc_printer.ml index 33852f4..3b4348d 100644 --- a/compiler/obc/obc_printer.ml +++ b/compiler/obc/obc_printer.ml @@ -8,6 +8,8 @@ open Global_printer let print_vd ff vd = fprintf ff "@["; + if vd.v_mutable then + fprintf ff "mutable "; print_ident ff vd.v_ident; fprintf ff ": "; print_type ff vd.v_type; diff --git a/compiler/obc/obc_utils.ml b/compiler/obc/obc_utils.ml index c333edb..be8ec61 100644 --- a/compiler/obc/obc_utils.ml +++ b/compiler/obc/obc_utils.ml @@ -96,6 +96,10 @@ let find_step_method cd = let find_reset_method cd = List.find (fun m -> m.m_name = Mreset) cd.cd_methods +let replace_step_method st cd = + let f md = if md.m_name = Mstep then st else md in + { cd with cd_methods = List.map f cd.cd_methods } + let obj_ref_name o = match o with | Oobj obj diff --git a/compiler/obc/transformations/memalloc_apply.ml b/compiler/obc/transformations/memalloc_apply.ml index 5b5dc69..1f9ee4d 100644 --- a/compiler/obc/transformations/memalloc_apply.ml +++ b/compiler/obc/transformations/memalloc_apply.ml @@ -69,7 +69,7 @@ let memalloc_subst_map inputs outputs mems subst_lists = let repr = choose_representative env inputs outputs mems ty l in let env = List.fold_left (fun env iv -> IvarEnv.add iv repr env) env l in let mutables = - if (List.length l > 2) || (List.mem (Ivar (var_name repr)) mems) then + if (List.length l > 1) || (List.mem (Ivar (var_name repr)) mems) then IdentSet.add (var_name repr) mutables else mutables @@ -111,7 +111,13 @@ let var_decs _ (env, mutables,j) vds = (* remove unnecessary outputs *) acc else ( - let vd = if IdentSet.mem vd.v_ident mutables then { vd with v_mutable = true } else vd in + let vd = + if IdentSet.mem vd.v_ident mutables then ( + Format.printf "%s is mutable@."; + { vd with v_mutable = true } + ) else + vd + in vd::acc ) with @@ -146,6 +152,11 @@ let class_def funs acc cd = let mem_alloc = (add_other_vars md cd) @ cd.cd_mem_alloc in let env, mutables = memalloc_subst_map inputs outputs mems mem_alloc in let cd, _ = Obc_mapfold.class_def funs (env, mutables, cd.cd_objs) cd in + (* remove unnecessary outputs*) + let m_outputs = List.filter (fun vd -> is_not_linear vd.v_linearity) md.m_outputs in + let md = find_step_method cd in + let md = { md with m_outputs = m_outputs } in + let cd = replace_step_method md cd in cd, acc let program p =