diff options
| author | Joseph Richey <joerichey94@gmail.com> | 2018-02-11 20:34:07 -0800 |
|---|---|---|
| committer | Joseph Richey <joerichey94@gmail.com> | 2018-02-11 20:34:07 -0800 |
| commit | 23b8c7b4eab0375b3d59cf4b2a1f3d7356515f95 (patch) | |
| tree | 6ec67f8d6b15420c3870d2b7c43b2b636fbb8349 /vendor/honnef.co/go/tools/callgraph/static | |
| parent | fff13ea9041a3945e36d5f002c3c0a1e0e93c825 (diff) | |
vendor: include source for tools
This change vendors the source for all our build, formatting, and
linting tools. Generated by running "dep ensure".
Diffstat (limited to 'vendor/honnef.co/go/tools/callgraph/static')
| -rw-r--r-- | vendor/honnef.co/go/tools/callgraph/static/static.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/honnef.co/go/tools/callgraph/static/static.go b/vendor/honnef.co/go/tools/callgraph/static/static.go new file mode 100644 index 0000000..5444e84 --- /dev/null +++ b/vendor/honnef.co/go/tools/callgraph/static/static.go @@ -0,0 +1,35 @@ +// Package static computes the call graph of a Go program containing +// only static call edges. +package static // import "honnef.co/go/tools/callgraph/static" + +import ( + "honnef.co/go/tools/callgraph" + "honnef.co/go/tools/ssa" + "honnef.co/go/tools/ssa/ssautil" +) + +// CallGraph computes the call graph of the specified program +// considering only static calls. +// +func CallGraph(prog *ssa.Program) *callgraph.Graph { + cg := callgraph.New(nil) // TODO(adonovan) eliminate concept of rooted callgraph + + // TODO(adonovan): opt: use only a single pass over the ssa.Program. + // TODO(adonovan): opt: this is slower than RTA (perhaps because + // the lower precision means so many edges are allocated)! + for f := range ssautil.AllFunctions(prog) { + fnode := cg.CreateNode(f) + for _, b := range f.Blocks { + for _, instr := range b.Instrs { + if site, ok := instr.(ssa.CallInstruction); ok { + if g := site.Common().StaticCallee(); g != nil { + gnode := cg.CreateNode(g) + callgraph.AddEdge(fnode, site, gnode) + } + } + } + } + } + + return cg +} |