github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/src/cmd/compile/internal/gc/gen.go (about)

     1  // Copyright 2009 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 gc
     6  
     7  import (
     8  	"cmd/compile/internal/types"
     9  	"cmd/internal/obj"
    10  	"cmd/internal/src"
    11  	"strconv"
    12  )
    13  
    14  func sysfunc(name string) *obj.LSym {
    15  	return Runtimepkg.Lookup(name).Linksym()
    16  }
    17  
    18  // isParamStackCopy reports whether this is the on-stack copy of a
    19  // function parameter that moved to the heap.
    20  func (n *Node) isParamStackCopy() bool {
    21  	return n.Op == ONAME && (n.Class() == PPARAM || n.Class() == PPARAMOUT) && n.Name.Param.Heapaddr != nil
    22  }
    23  
    24  // isParamHeapCopy reports whether this is the on-heap copy of
    25  // a function parameter that moved to the heap.
    26  func (n *Node) isParamHeapCopy() bool {
    27  	return n.Op == ONAME && n.Class() == PAUTOHEAP && n.Name.Param.Stackcopy != nil
    28  }
    29  
    30  // autotmpname returns the name for an autotmp variable numbered n.
    31  func autotmpname(n int) string {
    32  	// Give each tmp a different name so that they can be registerized.
    33  	// Add a preceding . to avoid clashing with legal names.
    34  	const prefix = ".autotmp_"
    35  	// Start with a buffer big enough to hold a large n.
    36  	b := []byte(prefix + "      ")[:len(prefix)]
    37  	b = strconv.AppendInt(b, int64(n), 10)
    38  	return types.InternString(b)
    39  }
    40  
    41  // make a new Node off the books
    42  func tempAt(pos src.XPos, curfn *Node, t *types.Type) *Node {
    43  	if curfn == nil {
    44  		Fatalf("no curfn for tempname")
    45  	}
    46  	if curfn.Func.Closure != nil && curfn.Op == OCLOSURE {
    47  		Dump("tempname", curfn)
    48  		Fatalf("adding tempname to wrong closure function")
    49  	}
    50  	if t == nil {
    51  		Fatalf("tempname called with nil type")
    52  	}
    53  
    54  	s := &types.Sym{
    55  		Name: autotmpname(len(curfn.Func.Dcl)),
    56  		Pkg:  localpkg,
    57  	}
    58  	n := newnamel(pos, s)
    59  	s.Def = asTypesNode(n)
    60  	n.Type = t
    61  	n.SetClass(PAUTO)
    62  	n.Esc = EscNever
    63  	n.Name.Curfn = curfn
    64  	n.Name.SetUsed(true)
    65  	n.Name.SetAutoTemp(true)
    66  	curfn.Func.Dcl = append(curfn.Func.Dcl, n)
    67  
    68  	dowidth(t)
    69  
    70  	return n.Orig
    71  }
    72  
    73  func temp(t *types.Type) *Node {
    74  	return tempAt(lineno, Curfn, t)
    75  }