diff --git a/compiler/obc/control.ml b/compiler/obc/control.ml index 8572366..4d3460e 100644 --- a/compiler/obc/control.ml +++ b/compiler/obc/control.ml @@ -96,7 +96,7 @@ let is_deadcode = function (* TODO Etrange puisque c'est apres la passe de deadc | _ -> false let rec joinlist j l = - let l = List.filter (fun a -> not (is_deadcode a)) l in + let rec join_next l = match l with | [] -> [] | [s1] -> [s1] @@ -104,11 +104,24 @@ let rec joinlist j l = match s1, s2 with | Acase(e1, h1), Acase(e2, h2) when Obc_compare.exp_compare e1 e2 = 0 -> - if is_modified_handlers j e1 h1 then - s1::(joinlist j (s2::l)) + let fused_switch = Acase(e1, joinhandlers j h1 h2) in + if is_modified_handlers j e2 h1 then + fused_switch::(join_first l) else - joinlist j ((Acase(e1, joinhandlers j h1 h2))::l) - | s1, s2 -> s1::(joinlist j (s2::l)) + join_next (fused_switch::l) + | s1, s2 -> s1::(join_first (s2::l)) + and join_first l = + match l with + | [] -> [] + | (Acase(e1, h1))::l -> + if is_modified_handlers j e1 h1 then + (Acase(e1, h1))::(join_next l) + else + join_next ((Acase(e1, h1))::l) + | _ -> join_next l + in + join_first l + and join_block j b = { b with b_body = joinlist j b.b_body }