github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/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 tempnamel(pos src.XPos, curfn *Node, nn *Node, t *types.Type) { 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.SetAutoTemp(true) 65 curfn.Func.Dcl = append(curfn.Func.Dcl, n) 66 67 dowidth(t) 68 *nn = *n 69 } 70 71 func temp(t *types.Type) *Node { 72 var n Node 73 tempnamel(lineno, Curfn, &n, t) 74 asNode(n.Sym.Def).Name.SetUsed(true) 75 return n.Orig 76 } 77 78 func tempAt(pos src.XPos, curfn *Node, t *types.Type) *Node { 79 var n Node 80 tempnamel(pos, curfn, &n, t) 81 asNode(n.Sym.Def).Name.SetUsed(true) 82 return n.Orig 83 }