From e4101799eebec8a13c8bb4588c8f7d9663858902 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Mon, 2 Jul 2018 18:56:14 +0100 Subject: Fix get_recursive_functions to not only pick up non-mutually recursive functions The code to do this is rather ugly. It would be nice to have a generic callgraph representation we could just query and not use the rewriter in a weird way to extract this info. --- src/c_backend.ml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/c_backend.ml b/src/c_backend.ml index d18ca354..8a41df67 100644 --- a/src/c_backend.ml +++ b/src/c_backend.ml @@ -2684,6 +2684,26 @@ let rec get_recursive_functions (Defs defs) = match defs with | DEF_internal_mutrec fundefs :: defs -> IdSet.union (List.map id_of_fundef fundefs |> IdSet.of_list) (get_recursive_functions (Defs defs)) + + | (DEF_fundef fdef as def) :: defs -> + let open Rewriter in + let ids = ref IdSet.empty in + let collect_funcalls e_aux annot = + match e_aux with + | E_app (id, args) -> (ids := IdSet.add id !ids; E_aux (e_aux, annot)) + | _ -> E_aux (e_aux, annot) + in + let map_exp = { + id_exp_alg with + e_aux = (fun (e_aux, annot) -> collect_funcalls e_aux annot) + } in + let map_defs = { rewriters_base with rewrite_exp = (fun _ -> fold_exp map_exp) } in + let _ = rewrite_def map_defs def in + if IdSet.mem (id_of_fundef fdef) !ids then + IdSet.add (id_of_fundef fdef) (get_recursive_functions (Defs defs)) + else + get_recursive_functions (Defs defs) + | _ :: defs -> get_recursive_functions (Defs defs) | [] -> IdSet.empty -- cgit v1.2.3