Last active
October 3, 2015 22:03
-
-
Save cognominal/eedf4128848d4e54ab9a to your computer and use it in GitHub Desktop.
create a call graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $test = q:to<END>; | |
void a(); | |
void a( | |
) { | |
b(); | |
c(); | |
} | |
END | |
grammar G { | |
token TOP { [ .*? <fun> ]+ .* } | |
token nm { <[a..z_]>+ } | |
token fun { ^^ \w \V*? <nm> '(' <-[)]>*? ')' \s* <fun-block> }; | |
token end-fun-block { ^^ '}'} | |
token fun-block { | |
'{' [ | |
[ <!before <.end-fun-block> > . ]+? # skip, not to far | |
<called-fun=.nm> '(' | |
]* | |
.*? | |
<.end-fun-block> | |
} | |
} | |
sub infix:«->» { " $^a -> $^b\n" }; | |
class actions { | |
method TOP($/) { | |
my $s = ''; | |
for $<fun> { | |
my @called = (grep { $_ ne 'sizeof'| 'memcpy' }, .<fun-block><called-fun>).unique( :with( &[eq] )) ; | |
$s ~= [~] ~.<nm> X[->] @called; | |
} | |
make "digraph A \{\n$s\}"; | |
} | |
} | |
# say G.parse($test); | |
say G.parse(slurp("src/rrb.c"), :actions(actions)).ast ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/hyPiRion/c-rrb | |
cd c-rrb | |
perl6 dot.p6 > rrb.dot # dot.p6 must created in c-rrb | |
dot -Tpdf rrb.dot > rrb.pdf | |
open rrb.pdf # on mac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment