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 "fmt" 8 9 // A place that an ssa variable can reside. 10 type Location interface { 11 Name() string // name to use in assembly templates: %rax, 16(%rsp), ... 12 } 13 14 // A Register is a machine register, like %rax. 15 // They are numbered densely from 0 (for each architecture). 16 type Register struct { 17 num int32 18 objNum int16 // register number from cmd/internal/obj/$ARCH 19 name string 20 } 21 22 func (r *Register) Name() string { 23 return r.name 24 } 25 26 // A LocalSlot is a location in the stack frame. 27 // It is (possibly a subpiece of) a PPARAM, PPARAMOUT, or PAUTO ONAME node. 28 type LocalSlot struct { 29 N GCNode // an ONAME *gc.Node representing a variable on the stack 30 Type Type // type of slot 31 Off int64 // offset of slot in N 32 } 33 34 func (s LocalSlot) Name() string { 35 if s.Off == 0 { 36 return fmt.Sprintf("%v[%v]", s.N, s.Type) 37 } 38 return fmt.Sprintf("%v+%d[%v]", s.N, s.Off, s.Type) 39 } 40 41 type LocPair [2]Location 42 43 func (t LocPair) Name() string { 44 n0, n1 := "nil", "nil" 45 if t[0] != nil { 46 n0 = t[0].Name() 47 } 48 if t[1] != nil { 49 n1 = t[1].Name() 50 } 51 return fmt.Sprintf("<%s,%s>", n0, n1) 52 } 53