Debian Codegraph @

internal/cmd/irdump/main.go

raw
1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // irdump: a tool for displaying the IR form of Go programs.
6 package main
7
8 import (
9 "flag"
10
11 "honnef.co/go/tools/go/ir"
12 "honnef.co/go/tools/internal/passes/buildir"
13
14 "golang.org/x/tools/go/analysis/singlechecker"
15 )
16
17 // flags
18 var (
19 dot bool
20 html string
21 )
22
23 func init() {
24 flag.BoolVar(&dot, "dot", false, "Print Graphviz dot of CFG")
25 flag.StringVar(&html, "html", "", "Print HTML for 'function'")
26 }
27
28 func main() {
29 buildir.Debug.Mode = ir.PrintFunctions | ir.PrintPackages
30 flag.Func("build", ir.BuilderModeDoc, func(s string) error {
31 return buildir.Debug.Mode.Set(s)
32 })
33 singlechecker.Main(buildir.Analyzer)
34
35 // if dot {
36 // for _, p := range pkgs {
37 // for _, m := range p.Members {
38 // if fn, ok := m.(*ir.Function); ok {
39 // fmt.Println("digraph{")
40 // fmt.Printf("label = %q;\n", fn.Name())
41 // for _, b := range fn.Blocks {
42 // fmt.Printf("n%d [label=\"%d: %s\"]\n", b.Index, b.Index, b.Comment)
43 // for _, succ := range b.Succs {
44 // fmt.Printf("n%d -> n%d\n", b.Index, succ.Index)
45 // }
46 // }
47 // fmt.Println("}")
48 // }
49 // }
50 // }
51 // }
52 }