github.com/Rookout/GoSDK@v0.1.48/pkg/services/assembler/internal/obj/inl.go (about)

     1  // Copyright 2017 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.assembler file.
     4  
     5  package obj
     6  
     7  import "github.com/Rookout/GoSDK/pkg/services/assembler/internal/src"
     8  
     9  
    10  
    11  
    12  
    13  
    14  
    15  
    16  
    17  
    18  
    19  
    20  
    21  
    22  
    23  
    24  
    25  
    26  
    27  
    28  
    29  
    30  
    31  
    32  
    33  
    34  
    35  
    36  
    37  
    38  
    39  
    40  
    41  
    42  
    43  
    44  type InlTree struct {
    45  	nodes []InlinedCall
    46  }
    47  
    48  
    49  type InlinedCall struct {
    50  	Parent   int      
    51  	Pos      src.XPos 
    52  	Func     *LSym    
    53  	ParentPC int32    
    54  }
    55  
    56  
    57  func (tree *InlTree) Add(parent int, pos src.XPos, func_ *LSym) int {
    58  	r := len(tree.nodes)
    59  	call := InlinedCall{
    60  		Parent: parent,
    61  		Pos:    pos,
    62  		Func:   func_,
    63  	}
    64  	tree.nodes = append(tree.nodes, call)
    65  	return r
    66  }
    67  
    68  func (tree *InlTree) Parent(inlIndex int) int {
    69  	return tree.nodes[inlIndex].Parent
    70  }
    71  
    72  func (tree *InlTree) InlinedFunction(inlIndex int) *LSym {
    73  	return tree.nodes[inlIndex].Func
    74  }
    75  
    76  func (tree *InlTree) CallPos(inlIndex int) src.XPos {
    77  	return tree.nodes[inlIndex].Pos
    78  }
    79  
    80  func (tree *InlTree) setParentPC(inlIndex int, pc int32) {
    81  	tree.nodes[inlIndex].ParentPC = pc
    82  }
    83  
    84  
    85  
    86  
    87  
    88  func (ctxt *Link) OutermostPos(xpos src.XPos) src.Pos {
    89  	pos := ctxt.InnermostPos(xpos)
    90  
    91  	outerxpos := xpos
    92  	for ix := pos.Base().InliningIndex(); ix >= 0; {
    93  		call := ctxt.InlTree.nodes[ix]
    94  		ix = call.Parent
    95  		outerxpos = call.Pos
    96  	}
    97  	return ctxt.PosTable.Pos(outerxpos)
    98  }
    99  
   100  
   101  
   102  
   103  
   104  
   105  
   106  
   107  func (ctxt *Link) InnermostPos(xpos src.XPos) src.Pos {
   108  	return ctxt.PosTable.Pos(xpos)
   109  }
   110  
   111  
   112  
   113  
   114  func (ctxt *Link) AllPos(xpos src.XPos, do func(src.Pos)) {
   115  	pos := ctxt.InnermostPos(xpos)
   116  	ctxt.forAllPos(pos.Base().InliningIndex(), do)
   117  	do(ctxt.PosTable.Pos(xpos))
   118  }
   119  
   120  func (ctxt *Link) forAllPos(ix int, do func(src.Pos)) {
   121  	if ix >= 0 {
   122  		call := ctxt.InlTree.nodes[ix]
   123  		ctxt.forAllPos(call.Parent, do)
   124  		do(ctxt.PosTable.Pos(call.Pos))
   125  	}
   126  }
   127  
   128  func dumpInlTree(ctxt *Link, tree InlTree) {
   129  	for i, call := range tree.nodes {
   130  		pos := ctxt.PosTable.Pos(call.Pos)
   131  		ctxt.Logf("%0d | %0d | %s (%s) pc=%d\n", i, call.Parent, call.Func, pos, call.ParentPC)
   132  	}
   133  }