From b2fbc387b5a1f1ed1b074b5925e9a86caaeb3aff Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 2 Jun 2022 16:03:40 -0400 Subject: [PATCH] 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 Run-TryBot: Alan Donovan Reviewed-by: Zvonimir Pavlinovic gopls-CI: kokoro --- cmd/callgraph/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/callgraph/main.go b/cmd/callgraph/main.go index b5533ac7a3..eb8c0d1163 100644 --- a/cmd/callgraph/main.go +++ b/cmd/callgraph/main.go @@ -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) }