src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

initial.go (1035B)


      1 // Copyright 2024 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 package vta
      6 
      7 import (
      8 	"golang.org/x/tools/go/callgraph"
      9 	"golang.org/x/tools/go/callgraph/internal/chautil"
     10 	"golang.org/x/tools/go/ssa"
     11 )
     12 
     13 // calleesFunc abstracts call graph in one direction,
     14 // from call sites to callees.
     15 type calleesFunc func(ssa.CallInstruction) []*ssa.Function
     16 
     17 // makeCalleesFunc returns an initial call graph for vta as a
     18 // calleesFunc. If c is not nil, returns callees as given by c.
     19 // Otherwise, it returns chautil.LazyCallees over fs.
     20 func makeCalleesFunc(fs map[*ssa.Function]bool, c *callgraph.Graph) calleesFunc {
     21 	if c == nil {
     22 		return chautil.LazyCallees(fs)
     23 	}
     24 	return func(call ssa.CallInstruction) []*ssa.Function {
     25 		node := c.Nodes[call.Parent()]
     26 		if node == nil {
     27 			return nil
     28 		}
     29 		var cs []*ssa.Function
     30 		for _, edge := range node.Out {
     31 			if edge.Site == call {
     32 				cs = append(cs, edge.Callee.Func)
     33 			}
     34 		}
     35 		return cs
     36 	}
     37 }