let rec successors block = match block with | [] -> raise CanonError | T.JUMP(_, s)::_ -> s | T.CJUMP(_, _, _, t, f)::_ -> [f;t] | _::t -> successors t let traceSchedule (blocks, ldone) = let blocks = Array.of_list blocks in let marks = Array.make (Array.length blocks) false in let lbl = Hashtbl.create (Array.length blocks) in Array.iteri (fun i b -> match b with | T.LABEL((_, id))::_ -> Hashtbl.add lbl id i | _ -> ()) blocks; let rec outer_loop i = if i = Array.length blocks then [] else if marks.(i) then outer_loop (i+1) else let rec inner_loop j = marks.(j) <- true; let b = blocks.(j) in let succ = List.find_opt (fun i->match i with | Some j -> not marks.(j) | None -> false) (List.map (fun (_, id) -> Hashtbl.find_opt lbl id) (successors b)) in b::(match succ with | Some (Some k) -> inner_loop k | _ -> outer_loop (i+1)) in inner_loop i in outer_loop 0