cmd/callgraph: add -algo=vta option

This option uses Variable Type Analysis, a refinement of CHA
suitable for partial programs.

Change-Id: I6c8b074e915d29eb9425656f345e8160417ba594
Reviewed-on: https://go-review.googlesource.com/c/tools/+/410138
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Alan Donovan 2022-06-02 16:03:40 -04:00
Родитель d68628a908
Коммит b2fbc387b5
1 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -37,6 +37,7 @@ import (
"golang.org/x/tools/go/callgraph/cha"
"golang.org/x/tools/go/callgraph/rta"
"golang.org/x/tools/go/callgraph/static"
"golang.org/x/tools/go/callgraph/vta"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/pointer"
"golang.org/x/tools/go/ssa"
@ -46,7 +47,7 @@ import (
// flags
var (
algoFlag = flag.String("algo", "rta",
`Call graph construction algorithm (static, cha, rta, pta)`)
`Call graph construction algorithm (static, cha, rta, vta, pta)`)
testFlag = flag.Bool("test", false,
"Loads test code (*_test.go) for imported packages")
@ -67,7 +68,7 @@ const Usage = `callgraph: display the call graph of a Go program.
Usage:
callgraph [-algo=static|cha|rta|pta] [-test] [-format=...] package...
callgraph [-algo=static|cha|rta|vta|pta] [-test] [-format=...] package...
Flags:
@ -76,6 +77,7 @@ Flags:
static static calls only (unsound)
cha Class Hierarchy Analysis
rta Rapid Type Analysis
vta Variable Type Analysis
pta inclusion-based Points-To Analysis
The algorithms are ordered by increasing precision in their
@ -251,6 +253,9 @@ func doCallgraph(dir, gopath, algo, format string, tests bool, args []string) er
// NB: RTA gives us Reachable and RuntimeTypes too.
case "vta":
cg = vta.CallGraph(ssautil.AllFunctions(prog), cha.CallGraph(prog))
default:
return fmt.Errorf("unknown algorithm: %s", algo)
}