1 USING: accessors alien.strings assocs classes fry graphviz
2 graphviz.attributes graphviz.notation kernel sequences system
3 tools.image-analyzer.references tools.image-analyzer.vm vocabs.parser ;
4 IN: tools.image-analyzer.graphviz
5 FROM: arrays => 1array 2array ;
6 FROM: byte-arrays => >byte-array ;
7 FROM: kernel => object ;
8 FROM: math => <= - shift ;
11 ! For the two annoying structs that differ on 32 and 64 bit.
13 "tools.image-analyzer.vm.32"
14 "tools.image-analyzer.vm.64"
18 : array>string ( array -- str )
19 0 suffix >byte-array alien>native-string ;
21 CONSTANT: node-colors {
24 { byte-array "#ffff00" }
25 { code-block "#ffaaff" }
27 { quotation "#449900" }
31 : heap-node>color ( heap-node -- color )
32 object>> class-of node-colors at ;
34 : relativise-address ( image heap-node -- address )
36 [ address>> ] [ code-heap-node? ] bi
38 header>> [ code-relocation-base>> ] [ data-relocation-base>> ] bi
41 : heap-node>label ( image heap-node -- label )
42 dup object>> string? [
43 nip payload>> array>string
44 ] [ relativise-address ] if ;
46 : heap-node>node ( image heap-node -- node )
47 [ heap-node>label ] [ heap-node>color ] [ address>> ] tri
48 <node> swap =fillcolor swap =label "filled" =style ;
50 : add-nodes ( graph image -- graph )
51 dup heap>> [ heap-node>node add ] with each ;
53 : heap-node-edges ( heap heap-node -- seq )
54 [ collect-pointers ] keep address>> '[ _ swap 2array ] map ;
56 : image>edges ( image -- edges )
57 heap>> dup [ heap-node-edges ] with map concat ;
59 : add-graphviz-edges ( graph edges -- graph )
60 [ first2 add-edge ] each ;
62 : add-edges ( graph image -- graph )
63 image>edges add-graphviz-edges ;
65 : <heap-graph> ( -- graph )
67 [graph "neato" =layout ];
68 <graph-attributes> "false" >>overlap add ;
70 : image>graph ( image -- graph )
71 <heap-graph> over add-nodes swap add-edges ;