http://digitocero.com/en/blog/exporting-and-visualizing-gccs-abstract-syntax-tree-ast
There is a source file named hello.c
.
YOUR_PATH/astviz hello
#!/usr/bin/env sh | |
SCRIPT_PATH=$(dirname $0) | |
gcc -o $1 $1.c -fdump-tree-original-raw | |
$SCRIPT_PATH/pre.awk $1.c.* | $SCRIPT_PATH/treeviz.awk > $1.dot | |
dot -Tpng $1.dot -o $1.png |
#!/usr/bin/env gawk -f | |
/^[^;]/{ | |
gsub(/^@/, "~@", $0); | |
gsub(/( *):( *)/, ":", $0); | |
print; | |
} |
#!/usr/bin/env gawk -f | |
#http://alohakun.blog7.fc2.com/?mode=m&no=355 | |
BEGIN {RS = "~@"; printf "digraph G {\n node [shape = record];";} | |
/^[0-9]/{ | |
s = sprintf("%s [label = \"{%s | {", $1, $1); | |
for(i = 2; i < NF - 1; i++) | |
s = s sprintf("%s | ", $i); | |
s = s sprintf("%s}}\"];\n", $i); | |
$0 = s; | |
while (/([a-zA-Z]+):@([0-9]+)/){ | |
format = sprintf("\\1 \\3\n %s:\\1 -> \\2;", $1); | |
$0 = gensub(/([a-zA-Z]+):@([0-9]+)(.*)$/, format, "g"); | |
}; | |
printf " %s\n", $0; | |
} | |
END {print "}"} |
http://digitocero.com/en/blog/exporting-and-visualizing-gccs-abstract-syntax-tree-ast
There is a source file named hello.c
.
YOUR_PATH/astviz hello
Strictly it is Parse Tree rather than Ast you are visualizing
Thank you for your sharing and your code is helpful.
I personally also built something similar