JuliaDebug / Cthulhu.jl

The slow descent into madness
MIT License
659 stars 41 forks source link

Display of CFGs and DomTrees #26

Open vchuravy opened 5 years ago

vchuravy commented 5 years ago

Would be fabolous to add some pretty printing for the CFG and dominator trees.

Keno apparently uses this snippet for DomTrees. We could use dot for the CFG like opt does it.

using AbstractTrees
using Core.Compiler: DomTree

AbstractTrees.treekind(d::DomTree) = AbstractTrees.IndexedTree()
AbstractTrees.childindices(d::DomTree, i::Int) = d[i].children
AbstractTrees.childindices(::DomTree, ::DomTree) = (1,)
AbstractTrees.parentlinks(::DomTree) = AbstractTrees.StoredParents()
AbstractTrees.printnode(io::IO, i::Int, d::DomTree) = print(io, i)
Base.getindex(d::DomTree, i) = d.nodes[i]
Base.show(io::IO, d::DomTree) = print_tree(io, 1; roottree = d)
tkf commented 3 years ago

FYI, I started playing with code visualizations in https://github.com/tkf/ShowCode.jl. It's integrated with Cthulhu.BOOKMARKS.

image

FWIW, I think implementing something on a lower layer (TypedCodeUtils?) than Cthulhu would be nicer.