open Netlist_ast open Graph exception Combinational_cycle let read_exp (_,exp) = let f a = match a with | Avar x -> [x] | _ -> [] in match exp with | Earg a | Enot a | Eslice (_,_,a) | Eselect (_,a) -> f a | Ebinop (_,a,b) | Econcat (a,b) -> (f a)@(f b) | Emux (a,b,c) -> (f a)@(f b)@(f c) | Ereg _ | Erom _ | Eram _ -> [] let schedule p = let g = mk_graph () in List.iter (add_node g) p.p_eqs; let addlinks (v,e) = let rec is_in x = function | t::q when t=x -> true | t::q -> is_in x q | [] -> false in List.iter (add_edge g (v,e)) (List.filter (fun f -> is_in v (read_exp f)) p.p_eqs ) in try (List.iter addlinks p.p_eqs) with Cycle -> (raise Combinational_cycle) ; { p_eqs=topological g; p_inputs=p.p_inputs; p_outputs=p.p_outputs; p_vars=p.p_vars }