diff options
| author | Alasdair Armstrong | 2018-07-02 18:56:14 +0100 |
|---|---|---|
| committer | Alasdair Armstrong | 2018-07-02 18:58:16 +0100 |
| commit | e4101799eebec8a13c8bb4588c8f7d9663858902 (patch) | |
| tree | 34dd06660182852d2f07f2958b6e58e0d1d99cdd /src | |
| parent | 03b583083bc184af4e195e3cb53f5d47f6912403 (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/c_backend.ml | 20 |
1 files changed, 20 insertions, 0 deletions
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 |
