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.
7 // This file defines the internal (context-sensitive) call graph.
13 "golang.org/x/tools/go/ssa"
18 obj nodeid // start of this contour's object block
19 sites []*callsite // ordered list of callsites within this function
20 callersite *callsite // where called from, if known; nil for shared contours
23 // contour returns a description of this node's contour.
24 func (n *cgnode) contour() string {
25 if n.callersite == nil {
26 return "shared contour"
28 if n.callersite.instr != nil {
29 return fmt.Sprintf("as called from %s", n.callersite.instr.Parent())
31 return fmt.Sprintf("as called from intrinsic (targets=n%d)", n.callersite.targets)
34 func (n *cgnode) String() string {
35 return fmt.Sprintf("cg%d:%s", n.obj, n.fn)
38 // A callsite represents a single call site within a cgnode;
39 // it is implicitly context-sensitive.
40 // callsites never represent calls to built-ins;
41 // they are handled as intrinsics.
43 type callsite struct {
44 targets nodeid // pts(ยท) contains objects for dynamically called functions
45 instr ssa.CallInstruction // the call instruction; nil for synthetic/intrinsic
48 func (c *callsite) String() string {
50 return c.instr.Common().Description()
52 return "synthetic function call"
55 // pos returns the source position of this callsite, or token.NoPos if implicit.
56 func (c *callsite) pos() token.Pos {