Skip to content

Instantly share code, notes, and snippets.

@aaronjeline
Created March 1, 2019 06:08
Show Gist options
  • Save aaronjeline/f6349d9b531bc91be6d582ef7e23ea08 to your computer and use it in GitHub Desktop.
Save aaronjeline/f6349d9b531bc91be6d582ef7e23ea08 to your computer and use it in GitHub Desktop.
open Core_kernel.Std
open Bap.Std
open Graphlib.Std
open Format
include Self()
module CG = Graphs.Callgraph
(* Every node reaches itself, need to check children *)
let find_recursion prog sub =
let cg = Program.to_graph prog in
let tid = Term.tid sub in
Graphlib.shortest_path (module CG) cg tid tid
(* Collect all subroutines in the program*)
let find_subs prog = Term.enum sub_t prog
let print_subs subs =
let print_sub s = printf "%s\n" (Sub.name s) in
Seq.iter subs print_sub
let main proj =
let prog = Project.program proj in
let recs =
Seq.filter
(find_subs prog)
(fun sub -> Option.is_some (find_recursion prog sub)) in
printf "Recursive Functions\n";
print_subs recs
module Cmdline = struct
open Config
let () = when_ready (fun{get=(!!)} ->
Project.register_pass' (main))
let () = manpage [
`S "Description";
`P
"Checks"
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment