github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/compile/internal/ssa/location.go (about) 1 // Copyright 2015 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 ssa 6 7 import ( 8 "cmd/compile/internal/types" 9 "fmt" 10 ) 11 12 // A place that an ssa variable can reside. 13 type Location interface { 14 String() string // name to use in assembly templates: AX, 16(SP), ... 15 } 16 17 // A Register is a machine register, like AX. 18 // They are numbered densely from 0 (for each architecture). 19 type Register struct { 20 num int32 // dense numbering 21 objNum int16 // register number from cmd/internal/obj/$ARCH 22 name string 23 } 24 25 func (r *Register) String() string { 26 return r.name 27 } 28 29 // ObjNum returns the register number from cmd/internal/obj/$ARCH that 30 // corresponds to this register. 31 func (r *Register) ObjNum() int16 { 32 return r.objNum 33 } 34 35 // A LocalSlot is a location in the stack frame, which identifies and stores 36 // part or all of a PPARAM, PPARAMOUT, or PAUTO ONAME node. 37 // It can represent a whole variable, part of a larger stack slot, or part of a 38 // variable that has been decomposed into multiple stack slots. 39 // As an example, a string could have the following configurations: 40 // 41 // stack layout LocalSlots 42 // 43 // Optimizations are disabled. s is on the stack and represented in its entirety. 44 // [ ------- s string ---- ] { N: s, Type: string, Off: 0 } 45 // 46 // s was not decomposed, but the SSA operates on its parts individually, so 47 // there is a LocalSlot for each of its fields that points into the single stack slot. 48 // [ ------- s string ---- ] { N: s, Type: *uint8, Off: 0 }, {N: s, Type: int, Off: 8} 49 // 50 // s was decomposed. Each of its fields is in its own stack slot and has its own LocalSLot. 51 // [ ptr *uint8 ] [ len int] { N: ptr, Type: *uint8, Off: 0, SplitOf: parent, SplitOffset: 0}, 52 // { N: len, Type: int, Off: 0, SplitOf: parent, SplitOffset: 8} 53 // parent = &{N: s, Type: string} 54 type LocalSlot struct { 55 N GCNode // an ONAME *gc.Node representing a stack location. 56 Type *types.Type // type of slot 57 Off int64 // offset of slot in N 58 59 SplitOf *LocalSlot // slot is a decomposition of SplitOf 60 SplitOffset int64 // .. at this offset. 61 } 62 63 func (s LocalSlot) String() string { 64 if s.Off == 0 { 65 return fmt.Sprintf("%v[%v]", s.N, s.Type) 66 } 67 return fmt.Sprintf("%v+%d[%v]", s.N, s.Off, s.Type) 68 } 69 70 type LocPair [2]Location 71 72 func (t LocPair) String() string { 73 n0, n1 := "nil", "nil" 74 if t[0] != nil { 75 n0 = t[0].String() 76 } 77 if t[1] != nil { 78 n1 = t[1].String() 79 } 80 return fmt.Sprintf("<%s,%s>", n0, n1) 81 }