File tree Expand file tree Collapse file tree 2 files changed +8
-14
lines changed Expand file tree Collapse file tree 2 files changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -211,9 +211,13 @@ func (g *CFG) Format(fset *token.FileSet) string {
211
211
return buf .String ()
212
212
}
213
213
214
- // digraph emits AT&T GraphViz (dot) syntax for the CFG.
215
- // TODO(adonovan): publish; needs a proposal.
216
- func (g * CFG ) digraph (fset * token.FileSet ) string {
214
+ // Dot returns the control-flow graph in the [Dot graph description language].
215
+ // Use a command such as 'dot -Tsvg' to render it in a form viewable in a browser.
216
+ // This method is provided as a debugging aid; the details of the
217
+ // output are unspecified and may change.
218
+ //
219
+ // [Dot graph description language]: https://en.wikipedia.org/wiki/DOT_(graph_description_language)
220
+ func (g * CFG ) Dot (fset * token.FileSet ) string {
217
221
var buf bytes.Buffer
218
222
buf .WriteString ("digraph CFG {\n " )
219
223
buf .WriteString (" node [shape=box];\n " )
@@ -235,11 +239,6 @@ func (g *CFG) digraph(fset *token.FileSet) string {
235
239
return buf .String ()
236
240
}
237
241
238
- // exposed to main.go
239
- func digraph (g * CFG , fset * token.FileSet ) string {
240
- return g .digraph (fset )
241
- }
242
-
243
242
func formatNode (fset * token.FileSet , n ast.Node ) string {
244
243
var buf bytes.Buffer
245
244
format .Node (& buf , fset , n )
Original file line number Diff line number Diff line change @@ -19,10 +19,8 @@ import (
19
19
"flag"
20
20
"fmt"
21
21
"go/ast"
22
- "go/token"
23
22
"log"
24
23
"os"
25
- _ "unsafe" // for linkname
26
24
27
25
"golang.org/x/tools/go/cfg"
28
26
"golang.org/x/tools/go/packages"
@@ -47,7 +45,7 @@ func main() {
47
45
if decl , ok := decl .(* ast.FuncDecl ); ok {
48
46
if decl .Name .Name == funcname {
49
47
g := cfg .New (decl .Body , mayReturn )
50
- fmt .Println (digraph ( g , pkg .Fset ))
48
+ fmt .Println (g . Dot ( pkg .Fset ))
51
49
os .Exit (0 )
52
50
}
53
51
}
@@ -67,6 +65,3 @@ func mayReturn(call *ast.CallExpr) bool {
67
65
}
68
66
return true
69
67
}
70
-
71
- //go:linkname digraph golang.org/x/tools/go/cfg.digraph
72
- func digraph (g * cfg.CFG , fset * token.FileSet ) string
You can’t perform that action at this time.
0 commit comments