Skip to content

Instantly share code, notes, and snippets.

@EllipticEllipsis
EllipticEllipsis / make_file_function_calls_graph.sh
Last active July 30, 2021 23:42
Finds all mentions of functions in z_sub_s in code. Can easily modify it to look at overlays or other directories, and use other files, and makes graphviz-compatible output
#!/bin/bash
# with quotes
while read line ; do grep -Fr "$line" asm/non_matchings/code ; done < <(find asm/non_matchings/code/z_sub_s/ -type f -exec basename {} .s \;) | grep -v 'glabel' | awk -F':|\\s+' '/%lo/ { next } /%hi/ { type="hilo" } /jal/ { type="jal" } { filefunc=gensub(/.*\/(.*)\/(.*)\.s/,"\\1,\\2","g",$1) ; gsub(/%hi\(|\)/,"") ; print filefunc","$NF","type } ' | awk -F, 'BEGIN { printf "digraph {\ncompound=true;\n\n" } { arr[$1] = arr[$1]" \""$2"\"" ; print "\""$2"\" -> \""$3"\"" } END { print "" ; for (file in arr) { print "subgraph cluster_"file" {" ; print arr[file]";" ; printf " style = filled;\n label = \"%s\";\n}\n\n" , file } print "}" }'
# without quotes
# while read line ; do grep -Fr "$line" asm/non_matchings/code ; done < <(find asm/non_matchings/code/z_sub_s/ -type f -exec basename {} .s \;) | grep -v 'glabel' | awk -F':|\\s+' '/%lo/ { next } /%hi/ { type="hilo" } /jal/ { type="jal" } { filefunc=gensub(/.*\/(.*)\/(.*)\.s/,"\\1,\\2","g",$1) ; gsub(/%hi\(|\)/,"") ; print filefunc","$NF