github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/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 "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 name string 19 } 20 21 func (r *Register) Name() string { 22 return r.name 23 } 24 25 // A LocalSlot is a location in the stack frame. 26 // It is (possibly a subpiece of) a PPARAM, PPARAMOUT, or PAUTO ONAME node. 27 type LocalSlot struct { 28 N GCNode // an ONAME *gc.Node representing a variable on the stack 29 Type Type // type of slot 30 Off int64 // offset of slot in N 31 } 32 33 func (s LocalSlot) Name() string { 34 if s.Off == 0 { 35 return fmt.Sprintf("%s[%s]", s.N, s.Type) 36 } 37 return fmt.Sprintf("%s+%d[%s]", s.N, s.Off, s.Type) 38 }